[英]How to show grammar is not LL(1) and convert grammar to LL(1)
I'm trying to find the ambiguity in this grammar so I can remove it and convert it to LL(1), however for the life of me I can't find the ambiguity. 我试图在此语法中找到歧义,以便可以将其删除并将其转换为LL(1),但是对于我一生来说,我找不到歧义。 Any help will be much appreciated.
任何帮助都感激不尽。
D -> if (C) {S} | if (C) {S} else {S}
S -> D | SA | A
A -> V = T;
V -> x | y
T -> 1 | 2
C -> true | false
The grammar is not ambiguous. 语法不是模棱两可的。 Nonetheless, it is not LL(1) because when the lookahead token is
if
, it is not possible to know which of the two productions for D
will be used. 但是,它不是LL(1),因为当先行标记为
if
,不可能知道将使用D
的两个产生式中的哪一个。
To make it LL(1), you will need to left-factor D
. 为了使其为LL(1),您将需要左因子
D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.