[DGD] Help with parse_string() grammar

Felix A. Croes felix at dworkin.nl
Mon Apr 10 00:38:01 CEST 2006


=?ISO-8859-1?Q?Petter_Nystr=F6m?= <md1pette at mdstud.chalmers.se> wrote:

> Okay... Here is obviously something I don't understand. I follow the 
> documentation when it says that a token rule can have several definitions 
> and then they're matched in a top-to-bottom order. But I don't understand 
> why the order of *different* token rules have an impact on things. I 
> thought they were just mathced against when a production ruled referenced 
> to it? And then it'd be matching against that specific token rule and not 
> all of them? I'm a little confused now... =)

The parser can't do that.  It has to match tokens before it knows which
production rules could possibly apply.  And it matches them in the order
of the specified rules.  Basically, token matching does not depend on
the context.

Since 'plain' matches anything that 'name' could match, and 'name'
matches anything that 'char' could match, that order is important.

As for the rest of the grammar, remove the "Output : Output" rule and
it should be okay.  But your token rules probably still need a little
more tweaking.

For example, the following string does not match the grammar:

    "&foo"

because it is '&' followed by a name, not a char.  But "&f&o&o" should
work.

Regards,
Dworkin



More information about the DGD mailing list