Can anyone convince me of the value of parser genaration, othr than an interesting academic exercise?
Can anyone convince me of the value of parser genaration, othr than an interesting academic exercise?
I don't know of any parser generator or parser combinator library that simultaneously supports abstraction and supports efficient streaming parsing. Does anybody know one?
PEG is a superset of recursive descent. You can structure you grammar in a way that backtracking is not required at all or minimised.
> They have to keep the entire input in memory in case backtracking happens.
Not necessarily. You only need to keep something like around a current statement (or other small syntax entity), discarding everything you've already streamed.
> I've actually implemented a Pratt parser in the past but I thought it was just for parsing operators with precedence?
Exactly. And it's really easy to mix it into an otherwise PEG-based parser, eliminating the need to backtrack for the worst backtracking case (binary expressions).
For example, there is a very efficient implementation of such an approach (pure PEG+Pratt, no memoisation and no backtracking) in Nemerle.
There is also a Packrat+Pratt parser used in https://github.com/combinatorylogic/mbase
Major project will necessary end up handcrafted, because major project usually need to be fast and optimized. Most projects are not that sensitive - they need to be developed reasonably fast and then need to be easy to be maintained.
They are also useful to use while shaping or discovering a syntax. Parser generators will quickly show you where the irregularities are because they will become harder (or impossible) to implement.
We certainly don't want languages with hidden ambiguities, which are resolved in different ways in different implementations.
And why exactly do you want an overbloated parser implementation full of leaky abstractions, while you can nicely generate it out of a BNF-like dense description?
> Can anyone convince me of the value of parser genaration