How to Prove a Grammar is ambiguous? S -> (S)|SS|()

五迷三道 提交于 2019-12-12 05:14:07

问题


I am rather new to grammars, and was wondering if someone could help me determine using a parse tree how this grammar below is ambiguous? I know that it needs to have two different strings that can be created.

S -> (S)|SS|()

I can def convert it to chomsky normal form and greibach, but ambiguity is perplexing to me with these.


回答1:


The easiest way to prove a grammar ambiguous is to find a sentence with two different parse trees. (Or two different rightmost derivations, which is exactly the same thing. Or, if you prefer, two different leftmost derivations.)

S → S S | X is always ambiguous (for any X), because the sentence X X X has two different parse trees:

     S            S
    / \          / \
   /   S        S   \
  /   / \      / \   \
 X   X   X    X   X   X


来源:https://stackoverflow.com/questions/43403182/how-to-prove-a-grammar-is-ambiguous-s-sss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!