Overlapping functionality: IFTI, templates, is-expressions

Russell Lewis webmaster at villagersonline.com
Thu Mar 20 10:35:29 PDT 2008


BCS wrote:
> Russell Lewis wrote:

Thanks for the example code.  I'll look it over soon, but right now I 
have to do my real job. :(

I do have one response and one more question, though...

(huge snip)

>> Ofc, if you have a parser library which is functional even if it's a 
>> little clunky, then hopefully you could use that library to scan input 
>> strings, build parse trees, and then generate parsers from that. :)
> 
> I don't follow: Are you talking about parsing at run time or compile time?

Both, actually.  My hope is to build a a parser library which is good 
for runtime parses, but which also, with CTFE and a string-to-template 
compile-time lexer, could be used to parse the actual grammar code that 
people give me as input.  That is:

	stringInput -> compile-time-lexer -> myLibrary -> CTFE
	            -> parse tree of user's grammar
	            -> code which uses my library -> generated parser

We'll see if it works...

>> Also, how good are you at handling ambiguous grammars?
> 
> It doesn't care. It work by matching the first match given so if there 
> is ambiguity, it won't know and will still produce something as output.

I should have also asked about lookahead.  I didn't, because I view 
lookahead & ambiguity as the same thing in my parser. :)

A key problem I had with Bison was that it couldn't handle C or D 
grammars in the "natural" form.  The canonical example of this is the 
token string
	IDENT '*' '*' ... '*' IDENT ...
which could be parsed as "declaration of pointer variable" (in which 
case the stars would naturally be part of "type" nonterminals, attached 
the to left side), or "multiplication where 2nd element needs lots of 
dereferencing" (in which case most of the stars would natrually be part 
of "expression" nonterminals, attached to the right side).

This the classic reduce/shift conflict problem in yacc/Bison.

Ofc, you can write grammars which don't need arbitrary recursion, but a 
high priority for me is to support natural grammar definitions and do 
the hard work in the library.

So: can you handle arbitrary lookahead?  Or do you, like Bison, make a 
one-time choice of "reduce or shift" and then you're stuck with it?



More information about the Digitalmars-d mailing list