grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] Questions about Parsers


From: Per Cederberg
Subject: Re: [Grammatica-users] Questions about Parsers
Date: Wed, 20 Apr 2005 08:53:32 +0200

On 2005-04-19 D. R. E. Moonfire  wrote:
>Related to this, how do I get the following to work?
>
>   %tokens%
>   CONSTRAINT = "CONSTRAINT"
>   IDENTIFIER = <<[a-zA-Z_\$][a-zA-Z0-9_\$]+>>
>   %production%
>   bob = CONSTRAINT IDENTIFIER
>
>where "CONSTRAINT CONSTRAINT" is given as the text. Right now, it keeps 
>telling me that it expects IDENTIFIER but it got the constraint token 
>instead.

Well, this is actually expected... :-)  Thing is, the tokenizer is completely 
context-insensitive. So it generates a flow of tokens from your input chars
all by itself without caring about the current production. And as the 
CONSTRAINT token is placed above the IDENTIFIER token in the list of
token definitions, it is chosen.

The fix here, if you really mean that a constraint can be called CONSTRAINT,
is to change the production:

bob = CONSTRAINT (IDENTIFIER | CONSTRAINT) ;

Or even nicer:

Bob = CONSTRAINT String ;

String = IDENTIFIER
       | CONSTRAINT ;

Hope this helps!

/Per








reply via email to

[Prev in Thread] Current Thread [Next in Thread]