2 ms·
Yeah I would also like to see how those topics fit in. To me, it is curious that people move from LALR to recursive descent -- i.e. generated bottom-up to manu
by chubot 12y ago
Yeah I would also like to see how those topics fit in.
To me, it is curious that people move from LALR to recursive descent -- i.e. generated bottom-up to manual top-down. It seems like moving to PEGs or ANTLR would be less drastic -- i.e. to generated top-down.
That may be a historical thing though, because top-down parser generators seem to have come a lot later (was there anything before ANTLR's predecessors?)
I find top down parsers a lot more intuitive and this article seems to say it's not just me (despite the fact that his project is bottom-up?). I think there is some confusion about top down parsers and arithmetic expressions, e.g. left recursion. But it seems much easier to mix top down parsers with other techniques like operator precedence parsing. You can always insert arbitrary code for one of the rule/production functions.
I don't believe you can mix LALR with anything else.
PEGs are really just a formalization of recursive descent, which I think makes them a very practical choice. I implemented a PEG parsing interpreter awhile ago. What I discovered though is that it's a lot more natural to have a separate traditional lex phase, and use the PEG abstraction (ordered choice with negations) for parsing only.
It seems extremely natural because:
- it uses the same top down algorithm as hand-written parsers
- easy to reason about in terms of correctness
- easy to reason about in terms of performance
- easy to mix with other paradigms
- I think it's easier to reason about how to insert good error messages too, though I have to investigate this more.
So I think there is a missing design choice. PEGs are kind of coupling lexing and parsing, while you could use a PEG-like algorithm for a top down generated parser only. I believe that is a very practical choice for a lot of systems that use hand coded recursive descent.
PEGs are relatively new (2004) so it's not that surprising that the entire design space hasn't been explored yet.
- loup-vaillant 12y ago> (despite the fact that his project is bottom-up?) Earley parsers, including Marpa, are at the same time top-down and bottom-up. And in the end it doesn't really matter. What does is the tree construction phase, and that generally ends up being defined in a top-down manner. As a result, Earley parsing feels like top-down parsing that doesn't fail on left-recursion.