简体   繁体   English

解析上下文树免费语法

[英]Parse Tree Of Context Free Grammar

I'm trying to figure out how to do parse trees correctly to show whether a grammar is ambiguous or not. 我试图弄清楚如何正确地解析树以显示语法是否模棱两可。

my grammar is S -> xSy | 我的语法是S-> xSy | ySx | ySx | SS | SS | e Ë

any help would be great. 任何帮助都会很棒。 thanks in advance 提前致谢

below is my crack at it... 下面是我的裂缝...

     S
    / \
   /   \
  x     y
 / \   / \
x   x  y  y

As a hint, pretty much any grammar with a production of the form 提示:几乎所有带有形式的语法

S → SS S→SS

will be ambiguous, because if you want to produce three S nonterminals you can do so in two ways: 这将是模棱两可的,因为如果您想产生三个S非末端,则可以通过两种方式进行:

      S                S
     / \              / \
    S   S            S   S
       / \          / \
      S   S        S   S

Assuming those S's can actually produce strings of terminals, these two "gadgets" can be put into the parse tree to derive the same string in two different ways. 假设那些S实际上可以产生终端字符串,则可以将这两个“小工具”放入解析树中,以两种不同的方式派生相同的字符串。

Hope this helps! 希望这可以帮助!

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

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