Eliminating Epsilon Production for Left Recursion Elimination

橙三吉。 提交于 2019-12-11 05:15:33

问题


Im following the algorithm for left recursion elimination from a grammar.It says remove the epsilon production if there is any

I have the following grammer

S-->Aa/b

A-->Ac/Sd/∈

I can see after removing the epsilon productions the grammer becomes

  1) S-->Aa/a/b

  2)A-->Ac/Sd/c/d

Im confused where the a/b comes in 1) and c/d comes in 2) Can someone explain this?


回答1:


lets look at the rule S->Aa, if A->∈ then S->∈a giving just S->a, so together with the previous rules we get S->Aa|a|b

now lets check the rule A->Ac and A->∈c which gives us A->c.

what about A->Sd? I dont see how you got A->d as a rule. if that is a rule, then the string "da" is accepted by this grammar (S->Aa & A->d --> "da"), but try to construct this string with the original grammar - if you start with S and the string finishes with a, it means you must use S->Aa, but then in order to have a "d" you must use A->Sd, which forces us to have another "a" or "b", meaning we cannot construct this string, and the rule A->d is not correct.



来源:https://stackoverflow.com/questions/21312669/eliminating-epsilon-production-for-left-recursion-elimination

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