简体   繁体   English

如何检查此语法中的歧义:

[英]How do i check the ambiguity in this grammar:-

E->EE+/E(E)/id E-> EE + / E(E)/ ID

Check if the given grammar is ambiguous. 检查给定的语法是否模棱两可。 Also, it would be of a great help if you could tell me the process to remove the ambiguity. 另外,如果您能告诉我消除歧义的过程,那将对您有很大的帮助。

I tried making the parse tree for it but could not figure out how to actually make it to find an ambiguous case 我尝试为其创建解析树,但无法弄清楚如何实际使用它来查找模棱两可的案例

Bison generates an LALR(1) parser for that grammar without any parser conflicts. Bison会为该语法生成​​一个LALR(1)解析器,而没有任何解析器冲突。 An LALR(1) grammar without parsing conflicts cannot be ambiguous, so it seems unlikely that you will be able to find an ambiguity. 没有解析冲突的LALR(1)语法不能是模棱两可的,因此您似乎不太可能发现歧义。

For reference, the bison input I used was: 作为参考,我使用的野牛输入为:

%%
E: E E '+'
 | E '(' E ')'
 | 'i'

If you process that with the -v flag, bison will produce a report file which contains the complete state machine. 如果使用-v标志进行处理,则bison将生成一个报告文件,其中包含完整的状态机。 (There are eight states plus the initial state.) (有八个状态加上初始状态。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM