News for hackers. Stuff that matters.
Re:PEG Parsers by chrisseaton on Monday July 22, 2019 @06:29PM (#20502893)
Bryan Ford has the most comprehensive information about PEG and how they're parsed http://bford.info/packrat/.

They've become somewhat unfashionable over the last decade - not really sure why.

Re:PEG Parsers by yellowapple on Monday July 22, 2019 @06:54PM (#20503043)
They're one of Perl 6's killer features (much like how regexes were one of pre-6 Perl's killer features); first-class support for PEGs in the language itself is a godsend for parse-heavy tasks like deserialization and DSLs.

If anything I feel like PEGs are getting more popular lately, likely because the memory usage is no longer terrible relative to the amount of memory even on "memory constrained" systems.

Re:PEG Parsers by rstuart4133 on Saturday July 27, 2019 @02:36AM (#20540708)
It's very easy to write a PEG that will recognise the a target language, but it will probably recognise a few more as well. They are hard to reason about.

LR and LL have the reverse problem. It's a challenge to get it to recognise a complex target language, but once you get the thing to work at all it's probably right. Also LL & LR are faster (very close to O(size of input)) and use less memory (almost none). PEG's have get their speed by remembering how they reduced what they've seen so far.

There are lots of trade-offs in other words. PEGS win anywhere you would use once of the current crop of NFA based regular expressions recognisers (eg, PCRE), need something better.

Re:PEG Parsers by minxomat on Monday July 22, 2019 @07:30PM (#20503250)
They're alive and well in lots of DSLs implemented with LPeg. MoonScript (which I use almost daily) parses using LPeg and the general notation inspired some dynamic type validators (e.g. tableshape).
Re:PEG Parsers by skunkpocalypse on Tuesday July 23, 2019 @04:56AM (#20505360)
> They've become somewhat unfashionable over the last decade not really sure why.

Much, much larger memory consumption than LR/LALR or even GLR. They're called packrat parsers for a reason.

Although the time complexity is asymptotically the same, LR-family parsers have such a tiny memory footprint that they usually run entirely in cache. Packrat tables never fit for nontrivial grammars+inputs. In practice this makes a big difference in performance.

Re:PEG Parsers by jdoege on Monday July 29, 2019 @05:21PM (#20559587)
Packrat parsing is not an intrinsic aspect of PEG, nor does it increase memory usage. Further, the memory issue is more academic than real. If you are having memory issues, you will add intentional pruning to your parser to purge anything that comes before a point behind which you can not backtrack. Such points tend to exist in most computer languages. Yes, this is not a strict part of PEG but being academically pure when constructing a parser of any complexity leads to a short trip to madness. Perl 6's grammar construct is not pure to the PEG definition but it is a recursive descent grammar engine with all the bells and whistle you could want including functional components such as argument pattern matching which makes generic and reusable grammar expression a cinch.

Also, PEG makes having a context sensitive lexer not simply trivial but no effort at all because lexing and parsing are all the same process. It you want to have two different token-types for an INT-looking-thing at two different places in your grammar for, "reasons", you are free to do so. Try that in a discrete lex/parse style grammar.