BLADE 0.2Alpha: Vector operations with mixins, expression templates, and asm

KlausO oberhofer at users.sf.net
Tue Apr 10 09:32:31 PDT 2007


Pragma schrieb:
> KlausO wrote:
>>
>> Hey pragma,
>>
>> really cool, I've come up with a similar structure while experimenting
>> with a PEG parser in D (see attachment)
>> after I've read this article series on
>> Codeproject:
>>
>> http://www.codeproject.com/cpp/crafting_interpreter_p1.asp
>> http://www.codeproject.com/cpp/crafting_interpreter_p2.asp
>> http://www.codeproject.com/cpp/crafting_interpreter_p3.asp
>>
>> The template system of D does an awesome job in keeping
>> templated PEG grammars readable.
> 
> Yes it does!  Thanks for posting this - I didn't even know that article 
> was there.
> 
>> BTW: If you turn Enki into a PEG style parser I definitely throw
>> my attempts into the dustbin :-)
>> Greets
> 
> Wow, that's one heck of an endorsement.  Thanks, but don't throw 
> anything out yet.  This rendition of Enki is still a ways off though.  
> FYI I plan on keeping Enki's internals as human-readable as possible by 
> keeping it self-hosting.  So there'll be two ways to utilize the 
> toolkit: EBNF coding and "by hand".

Nice to hear that I hit your taste :-)

> 
>> alias   Action!(
>>           And!(
>>             PlusRepeat!(EmailChar),
>>             Char!('@'),             PlusRepeat!(
>>               And!(
>>                 Or!(
>>                   In!(
>>                     Range!('a', 'z'),
>>                     Range!('A', 'Z'),
>>                     Range!('0', '9'),
>>                     Char!('_'),
>>                     Char!('%'),
>>                     Char!('-')
>>                   ),
>>                   Char!('.')
>>                 ),
>>                 Not!(EmailSuffix)
>>               )
>>             ),
>>             Char!('.'),
>>             EmailSuffix
>>           ),
>>           delegate void(char[] email) { writefln("<email:", email, 
>> ">"); }
>>         )
>>         Email;
> 
> I had an earlier cut that looked a lot like this. :)  But there's a very 
> subtle problem lurking in there.  By making your entire grammar one 
> monster-sized template instance, you'll run into DMD's identifier-length 
> limit *fast*.  As a result it failed when I tried to transcribe Enki's 
> ENBF definition.  That's why I wrap each rule as a CTFE-style function 
> as it side-steps that issue rather nicely, without generating too many 
> warts.
> 

Another issue I ran into is circular template dependencies. You could 
get nasty error messages like

dpeg.d(282): Error: forward reference to 
'And!(Alternative,OptRepeat!(And!(WS,Char!('/'),WS,Alternative)),WS)'

Any idea how they could be resolved ?


FYI:

Other good PEG references:
http://pdos.csail.mit.edu/~baford/packrat/

Cat is a open source interpreter which utilizes a rule based parser in C#
http://www.codeproject.com/csharp/cat.asp
very interesting had been
http://code.google.com/p/cat-language/wiki/HowTheInterpreterWorks

C++ templated parsers
http://www.codeproject.com/cpp/yard-xml-parser.asp
http://www.codeproject.com/cpp/biscuit.asp



More information about the Digitalmars-d mailing list