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

Pragma ericanderton at yahoo.removeme.com
Tue Apr 10 08:10:02 PDT 2007


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".

> 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.

-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list