COMP2022Assignment2课业解析

COMP2022Assignment2课业解析
题意:
考察LL(1)文法的相关知识及实现基于预测分析表方法的LL(1)语法分析器
解析:
第一题分别要求列出给定文法G的终止符、非终止符、最左推导字符串及构建其语法树;第二题用泵引理证明文法是否非正则;第三题证明给定文法不是LL(1)文法,提示:存在左递归;第四题消除左递归和回溯,构造等价的LL(1)文法;第五题构造预测分析表;第六题编程实现预测分析表表驱动的LL(1)文法分析器;第七部分实现附加功能,判断出一些类型的语法错。符号串的分析流程图:涉及知识点:
LL(1)文法、预测分析表、泵引理
更多可加v讨论
v:luna619-
pdf
COMP2022: Assignment 2
Due: 23:59pm Sunday 20th October 2019 (end week 10)
1 The grammar G [10%]
Consider the following grammar G, which represents a fragment of a simple programming language:
S ! SL j "
L ! A; j E; j C;
E ! (EBE) j N j V
A ! let V =E
C ! while E do S j while E do S else S
B ! + j - j * j >
V ! x j y j z
N ! ND j N0 j D
D ! 1 j 2 j 3 j 4 j 5 j 6 j 7 j 8 j 9 (you can denote this [1-9])
In this assignment, you can ignore whitespace in the strings (i.e. spaces and newlines are not part of the
language, but should be used for the sake of readability).
i) List the variables of G
ii) List the terminals of G
iii) Give a leftmost derivation of the string let x=(y-20); while 1 do y;;
iv) Draw a parse tree for the string: let x=(y-20); while 1 do y;;
2 Prove that L(G) is not regular [5%]
Prove that the language generated by G is not a regular language, by contradicting the Pumping Lemma.
3 Prove G is not LL(1) [5%]
Prove that G is

你可能感兴趣的:(计算机)