Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
PEGs: Parsing Expression Grammars (brynosaurus.com)
58 points by ahalan on Nov 16, 2011 | hide | past | favorite | 6 comments


I read this paper not long ago as it was referenced in Ward Cunningham's interesting work in Exploratory Parsing [0]. It's a quick read and definitely interesting. If you're interested there's a yacc equivalent peg/leg [1]. The only thing that wasn't clear to me (and I'd appreciate enlightenment if anyone has any) is why Cunningham's Exploratory Parsing depends so much on PEGs? Is it simply the non-ambiguous nature of the parse tree?

0. http://c2.com/~ward/sao/TechIgnite-v1/ 1. http://piumarta.com/software/peg/


I have to mention OMeta, a language based on PEGs (plus a few extensions): http://www.tinlizzie.org/ometa/

It's dead simple, and quite powerful: it helps implement all compilation phases, from parsing to code generation. And it compiles itself in about 400 lines of code.


It should be mentioned that this paper is from 2004, and that in the meantime there's even a Wikipedia article about PEG: http://en.wikipedia.org/wiki/Parsing_expression_grammar


PEG.js has an online grammar creator:

http://pegjs.majda.cz/online


There are some great PEG parsers in Ruby:

* Parslet: http://kschiess.github.com/parslet/

* Treetop: http://kschiess.github.com/parslet/


Treetop is great - I have previously written parsers using yacc and lex, and I found treetop to be around about 2 orders of magnitude more productive. That said, I don't know that I would want to use it on large files with a complex grammar :/




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: