Lexer and parser generators using CTFE

Philippe Sigaud philippe.sigaud at gmail.com
Mon May 28 05:26:54 PDT 2012


On Sun, May 27, 2012 at 11:13 PM, John Belmonte <john at neggie.net> wrote:
> I'm wondering if people have seen LPeg.  It's a Lua library, but the design
> is interesting in that patterns are first class objects which can be
> composed with operator overloading.
>
> http://www.inf.puc-rio.br/~roberto/lpeg/

This is exactly the approach followed by C++ Boost::Spirit, with halas
the limitations from Algol-language operators and precedence: no
postfix '*' (Kleene Star) operator. It seems that lpeg has the same
problem.

I played with this idea with my own Pegged
(https://github.com/PhilippeSigaud/Pegged), but I wasn't quite
convinced by the result, exactly for the reason above. Also, when
looking at real-world Spirit examples, I was a bit disappointed by the
resulting syntax: it's not *that* readable for complicated
expressions. In fact, that's exactly why I decided to follow the DSL
road with Pegged, so as to obtain exactly the PEG syntax, with the
real operators and their standard precedence.

Btw, if you're interested in expression templates, I uploaded
yesterday a very preliminary project in Github, to construct, and then
manipulate, expressions:

auto e = expr(); // The null expression
auto f = 2*e + 1- (e~"abc")*3; // f is an expression template that
encodes the right-hand side.

Then, it's up to the user to define what the expression represents.

https://github.com/PhilippeSigaud/Expression-Tree


More information about the Digitalmars-d mailing list