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

Pragma ericanderton at yahoo.removeme.com
Tue Apr 10 09:59:17 PDT 2007


KlausO wrote:
> Pragma schrieb:
>> KlausO wrote:
>>
>>> 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 ?

Yep, that one bit me too; just use the CTFE trick I mentioned.  Wrapping each rule fixes this since DMD can resolve 
forward references to functions, but not with template instances.

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

Thanks.  I can always use a little more research to lean on.

-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list