Hello,
     I have written a PEG generator in python that is currently capable 
of outputing C++ and python. Mostly I use the C++ version so that has 
been heavily worked on, the python output works but probably has some 
bugs in it. This is part of a game I am working on, you can get the 
generator here:

svn co 
https://paintown.svn.sourceforge.net/svnroot/paintown/trunk/src/mugen/parser

peg.py is the generator, the .peg files are input written in mostly EBNF.

I plan to generate more languages in the future (see the TODO at the 
top). If anyone is interested in this code don't hesitate to ask me 
about it.

Miscellaneous:
1. Generating an AST with a C++ PEG necessitates using a garbage 
collector (details upon request) so I had to litter the code with 
annoying pointer saving operations. Screwing up these little details 
causes massive bugs later on!
2. I implemented a few optimizations from the Rats! paper such as chunks.
3. Rules are parameterized over values instead of other rules, so you 
can say something like
foo = "a" "b" bar($1)
bar(x) = ... {{ x }}

And 'x' will be "a". This lets me implement tail recursion nicely so I 
don't run out of stack space. In particular I can implement infix math 
expressions that uses up stack space proportional to the depth of 
nesting (as opposed to the length of the expression).
4. The infix calculator example I referenced gets about 800kb/s on my 
laptop while an equivalent version using Rats! gets 1.7mb/s. I did as 
much optimizing as I could but I guess Java is just better than C++! 
Actually the reason the C++ version is so slow is because I do a lot of 
stack copying (again the GC in Java is a win here).

_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to