Lexer and parser generators using CTFE

Nick Sabalausky a at a.a
Wed Feb 29 09:05:47 PST 2012


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:jilkj6$1a50$2 at digitalmars.com...
> On 2/28/12 11:15 PM, Nick Sabalausky wrote:
>> In Goldie, I've taken an inverted approach, which IMHO is easier to use: 
>> The
>> types are automatically generated from the grammar, not the other way
>> around. So applying that approach to the above code, it'd be more like 
>> this:
>>
>> mixin genGrammar!("myGrammar", `
>>      Identifier = [a-zA-Z_][a-zA-Z_0-9]*
>>      Module = Declaration+
>>      Declaration = StructDeclaration
>>      StructDeclaration = 'struct' Identifier '{' Declaration* '}'
>> `);
>>
>> Which generates these classes:
>>
>> Parser!"myGrammar"
>> Symbol!("myGrammar.Identifier")
>> Symbol!("myGrammar.Module")
>> Symbol!("myGrammar.Declaration")
>> Symbol!("myGrammar.StructDeclaration")
>>
>> and/or these:
>>
>> Parser_myGrammar
>> Symbol_myGrammar!"Identifier"
>> Symbol_myGrammar!"Module"
>> Symbol_myGrammar!"Declaration"
>> Symbol_myGrammar!"StructDeclaration"
>>
>> would could then be aliased by the user however they wanted:
>>
>> alias Symbol_myGrammar MySym;
>>
>> And there can still be hooks (delegates, subclassing, whatever) to add
>> customized behavior/functionality.
>
> I think this is the right approach.
>

What? We agree? ;)




More information about the Digitalmars-d mailing list