-CS3342

CS3342 – Midterm Exam – Wednesday, Mar. 1, 3:30 - 5:30pm 3

1. (25pt) The identifiers in a programming language consist of one or more lower case letters, a, b,..., z, which must appear in non-decreasing alphabetical order. For example, correct identifiers include: accent, begin, x, zzz. Examples of incorrect identifiers are: bad, id.

(a) (10pt) Write a regular expression for these identifiers.

(b) (15pt) Draw a deterministic finite automaton that accepts precisely these identifiers.

CS3342 – Midterm Exam – Wednesday, Mar. 1, 3:30 - 5:30pm

2. (25pt) Consider the following grammar, G:

5

0. P ?! S$

1. S ?! ABC 2. A ?! aA 3. A ?! "

4. B ?! bB 5. B ?! bA 6. C ?! Cc 7. C ?! "

(a) (10pt) Compute first(X), follow(X), for nonterminals X, and predict(p), for productions p, 0  p  7.

(b) (5pt) Explain why G is not LL(1). Include all conflicts G has in your explanation.

(c) (10pt) Modify G to become LL(1). Explain why the new, equivalent, grammar is LL(1). You don’t need to rebuild the first(), follow(), and predict() tables. Include su?cient explanation as to why the conflicts have been resolved.

CS3342 – Midterm Exam – Wednesday, Mar. 1, 3:30 - 5:30pm 7

3. (25pt) Consider the same grammar, G, from question 2 above, repeated here for convenience:

0. P ?! S$

1. S ?! ABC 2. A ?! aA 3. A ?! "

4. B ?! bB 5. B ?! bA 6. C ?! Cc 7. C ?! "

(a) (15pt) Draw the LR parser in the form of the graph; the states contain the LR-items, the transitions are labelled by terminals. Reduce states are double circled. Include also (as jflap does and as shown in class) the trivial states, those containing a single LR-item with the dot at the end.

(b) (5pt) Is this grammar SLR(1)? Explain your answer.

(c) (5pt) In general, in the definition of an SLR(1) grammar, shift/reduce and reduce/reduce conflict are forbidden. What about shift/shift conflicts?

CS3342 – Midterm Exam – Wednesday, Mar. 1, 3:30 - 5:30pm 9

4. (25pt) Consider the following grammar, G, for arithmetic expressions in postfix notation:

E ?! EEO E ?! const O ?! +

O ?! -

O ?! * O ?! /

(a) (10pt) Based on G, write an S-attributed grammar that computes the infix version of the postfix expression represented by the yield of the parse tree.

(b) (10pt) The same problem except that now you have to minimize the number of parentheses.

(c) (5pt) Draw the annotated parse tree for the string 12+345-67--** and the grammar you designed at (b). Show the attribute flow (arrows and values).

Alternative (c) (3pt) If you built a grammar for (a) but not for (b), then use the grammar you designed at (a). In this case, for a correct answer, you receive 3pt instead of 5pt. (If you solve the original (c), then you don’t have to do this.)

相关推荐

  1. -CS3342

    2024-05-01 06:40:01       7 阅读
  2. AtCoder Beginner Contest 332

    2024-05-01 06:40:01       41 阅读
  3. AtCoder Beginner Contest 332

    2024-05-01 06:40:01       42 阅读
  4. P3842 [TJOI2007] 线段

    2024-05-01 06:40:01       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-01 06:40:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-01 06:40:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-01 06:40:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-01 06:40:01       18 阅读

热门阅读

  1. Spring Boot使用Logback将某些日志输出到单独的文件

    2024-05-01 06:40:01       10 阅读
  2. Kappa系数-评估分类算法的表现

    2024-05-01 06:40:01       11 阅读
  3. Spring boot 应用引入 Spring cloud alibaba nacos

    2024-05-01 06:40:01       11 阅读
  4. NLP Step by Step -- 如何微调一个模型(1)

    2024-05-01 06:40:01       10 阅读
  5. NLP中常见的tokenize方式及token类型

    2024-05-01 06:40:01       9 阅读
  6. spring源码分析之上下文构建

    2024-05-01 06:40:01       11 阅读
  7. 2024年华东杯数学建模思路+论文+代码

    2024-05-01 06:40:01       11 阅读
  8. 自然语言处理(NLP)简介

    2024-05-01 06:40:01       10 阅读
  9. np.concatenate在图像处理中的使用

    2024-05-01 06:40:01       9 阅读
  10. 图像处理:时域、空域、频率的滤波介绍

    2024-05-01 06:40:01       10 阅读
  11. 10种新兴网络安全威胁和攻击手法

    2024-05-01 06:40:01       8 阅读
  12. 【无标题】

    2024-05-01 06:40:01       10 阅读
  13. 第19天 IO流

    2024-05-01 06:40:01       7 阅读