What advantages do LL parsers have over LR parsers?

后端 未结 6 1499
感情败类
感情败类 2021-01-30 04:36

What advantages do LL parsers have over LR parsers to warrant their relative popularity in today\'s parser generator tools?

According to Wikipedia, LR parsing appears to

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 04:43

    If you have to hand code one, recursive descent (LL) is something you can do realistically; people cannot hand-build L(AL)R parsers practically by hand.

    Given that modern parser generators will handle all the parser construction for you, and that space is not much of an issue, I prefer LR parsers because you don't have to fight with the grammars as much to make them valid for your particular parser generator (no "remove all the left recursion" silliness).

    In fact, I prefer GLR parsers, which will pretty much parse anything with a context free grammar. No left-recursion worries. No shift/reduce conflict worries. No lookahead limits.

    If you want to see the range of languages that one GLR parsing engine can handle (including the famously hard-to-parse-using-LL/LALR language, C++), you can look here.

提交回复
热议问题