Writing a Parser

bearophile bearophileHUGS at lycos.com
Thu Jan 10 12:49:38 PST 2008


Christoph Singewald:
> I use lemonde as parsergenerator and re2c as lexer. Using re2c in most
> cases you have only to replace 'unsigned int' with 'uint' in the resulting code.

I have seen re2c and it looks nice. I think its source code can be modified with not that much efforts to make it produce D code instead of C.

I think C isn't the right language to write such tool: its sources are about 200 KB of C code (plus some code generated by itself), they can probably be replaced by a 50 (or less) KB Python module (that generates the C/D code).

Something like a tiny but really fast C compiler like TinyCC (http://fabrice.bellard.free.fr/tcc/) can be used to compile the C code on the fly in memory and execute it. This may become the starting point to give run-time compiled Regular Expressions to D :-) Probably there are other smarter ways to do similar things.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list