Why can't a recursive-descent parser handle left recursion

匆匆过客 提交于 2019-11-27 19:05:56

consider:

A ::= A B

the equivalent code is

boolean A() {
    if (A()) {
        return B();
    }
    return false;
}

see the infinite recursion?

For whoever is interested

 A ::= A B | A C | D | E

can be rewritten as:

 A ::= (D | E) (B | C)*

The general form of the transformation is: any one of the non left recursive disjuncts followed by any number of the left recursive disjuncts without the first element.

Reforming the action code is a bit trickery but I thing that can be plug-n-chug as well.

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