Finding a grammar is not LL(1) without using classical methods and transforming it to LL(1)

烈酒焚心 提交于 2019-12-02 10:22:49

Both S/A and B/C involve indirect left-recursion.

Since no left-recursive grammar (direct or indirect) is LL(k) for any k, you can prove the grammar is not LL(1) simply by showing the left-recursive cycle. (On the other hand, if you have a tool which computes FIRST and FOLLOW sets, the "classical" method is really very simple.)

Eliminating indirect left recursion involves first finding one possible topological sort of the non-terminals and then breaking the derivation cycle by substituting some uses of a non-terminal with its right-hand side. After that, the simple left recursion elimination algorithm can be applied.

You can find concrete examples of this transformation here on StackOverflow, or here, or in any good textbook on parsing theory. (Or, of course, by searching for the term "indirect left recursion" and looking for pages with some credibility.)

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