Lexer and parser generators using CTFE

bls bizprac at orange.fr
Tue Feb 28 07:11:31 PST 2012


On 02/28/2012 12:36 AM, CTFE-4-the-win wrote:
> We need to have a easy-to-use, complete, seamless, and efficient
> lexer-parser generator combo in Phobos, pronto. The lexer itself could
> use a character-level PEG or a classic automaton, and emit tokens for
> consumption by a parser generator. The two should work in perfect tandem
> (no need for glue code). At the end of the day, defining a complete
> lexer+parser combo for a language should be just a few lines longer than
> the textual representation of the grammar itself.

Are you aware of Philippe Sigaud's PEG work (may become part of his 
template book)

Quote  Philippe ..
I recently wrote a parsing expression grammar module in D, also to 
create grammars and parsers at compile-time and parse inputs at CT.

(PEG: http://en.wikipedia.org/wiki/Parsing_expression_grammar)

Usage is like this:

mixin Grammar(
       "JSON <- '{' ( Pair ( ',' Pair )* )? '}'"
     , "Pair <- String ':' Value"
     , "Value <- String / Number / JSON / Array / True / False / Null"
     , `True <- "true"`
(..., rest of JSON grammar)
);

enum result = JSON.parse(
`{ "Hello":42,
     "World!":
     {
         "a":[0,1,2,3]
     }
}`);


End Quote
No that bad :) , I think.

Well, I am still a fan of EBNF based parser generators (recursive 
decent) but that's an other story. If I recall correctly BCS has created 
something working. ( BNF , so limited)


More information about the Digitalmars-d mailing list