2 ms·
The theory of PEGs is fundamentally different but I haven't been in either's guts recently to be a reliable explainer of them. For practical purposes, PEGs are
by giraffe_lady 3y ago
The theory of PEGs is fundamentally different but I haven't been in either's guts recently to be a reliable explainer of them.
For practical purposes, PEGs are always linear time and can easily handle prioritized choice, with the downside that declared priority is the only way to resolve ambiguity. Backtracking is cheap but they are stateless in a very specific technical sense, so can't handle some semantic constructs. The no ambiguity thing means they only succeed or fail, no incremental parsing of incomplete grammar for example like you would want in a syntax highlighter. Some PEG libraries aren't "pure" PEGs and can get around these limitations though.
In real use they tend to have a very straightforward mapping between declaration and grammar. I got used to them in Janet, which has them in the standard lib instead of regex and for that purpose they are incredible. Much easier to write and especially edit. They also work well for some languages but there are some real world language features that they simply can't parse.