浙江理工大学编译原理双语
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
属性文法
Consider the following grammar A Bb B cB | ε Write semantic rules to compute the X attribute A.x, which is true if and only if the sentence parsed has an odd number of b's. • multiple instances of a non-terminal in a production above are subscripted to distinguish them. • • • •
• Consider the following grammar: • Write semantic rules to compute the attribute type, using the xxxx() method to the symbol table.
• Rewrite the following grammars: • (1) remove the left recursive. • (2) factor the left factor
• Consider the following grammar G[S]: • • • a. Construct First and Follow sets for the nonterminals of the resulting grammar. • b. Show that the resulting grammar is LL(1). • c. Construct the LL(1) parsing table for the resulting grammar.
Consider the following grammar xxxx a. Rewrite it in a form of LR(0) item. b. Construct the DFA of LR(0) items for the grammar. • c. Construct the SLR(1) /LR0 parsing table for the grammar. • d. Show the parsing stack and the actions of an SLR(1) /LR0 parser for the input string XXXX using the table of part c. • • • •
describe the language defined by DFA
0基础
• a source program contains the assignment statement • xxxxxxxxxxxxxx • list all tokens and their categories in this program
• Use the subset construction to create a DFA that is equivalent to the following NFA that uses the alphabet {0,1}. Show your work. • ε denotes the empty string. X states are final states. (The detail step of subset construction and state chart is required)
• Applying the minimization algorithm to the following DFA (Please write down every step)
4 文法
• Show that the following grammar is ambiguous:
Given the following grammar: Xxx->aa Xsss->aa 1) give the leftmost derivation of xyxyz and parse tree。 • 2) give the rigthmost derivation of xyxyx and parse tree。 • 3) What is the language defined by the grammar? If it is regular, describe it with a regular expression; if not, give a description in English. • • • •
• Given thபைடு நூலகம் grammar • Write down Lefttmost/Rightmost derivations, parse tree, and abstract trees for:xxxx
5 LL(1)自顶向下
• The following is a version of an expression grammar. Do the steps to make an LL(1) parse table. If there are conflicts, show all the values that can go in a spot in the table. • 1)transformed grammar without left recursion (if necessary). • 2)left-factored grammar (starting with the grammar from the first part) (if necessary) • 3)FIRST sets of all non-terminals • 4)FOLLOW sets of all non-terminals • 5)the LL(1) parser table.
1 语言
• Write descriptions for the languages generated by the following regular expressions:
• describe the language defined by DFA
2有限自动机√
• Draw a NFA that accepts abc, Use the subset construction to create a DFA that is equivalent to the following NFA
自底向上
• • • • • • • • • Consider the following grammar with productions 1) 2) 3) Construct the SLR/LR0 parsing tables for the grammar. In particular, show the following: 1) The augmented grammar 2) The DFA to recognize viable prefixes, including the set of items for each state. 3) The FIRST and FOLLOW sets for all the non-terminals 4) The action and goto tables