Removing Left Recursion in a Context Free Grammar

流过昼夜 提交于 2019-12-12 15:02:03

问题


Trying to figure out removing left recursion in context free grammars. I'm used to certain forms, but this one has me a bit boggled.

S --> S {S} S | (A) | a
A --> {S} A | epsilon

I also have to design a decent parser, which I can do. However, figuring out this left recursion (especially on the first one) has me confused.


回答1:


There is an interesting Wikipedia article on left-recursion. It also has a section about removing left-recursion for non-context grammars.

http://en.wikipedia.org/wiki/Left_recursion




回答2:


Try this:

S --> a [ { S } S ]
    | ( [ A ] ) [ {S} S ]


A --> { S } [ A ]


来源:https://stackoverflow.com/questions/3826852/removing-left-recursion-in-a-context-free-grammar

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