[antlr-interest] Apparent inconsistent token handling in AST grammars.

Stevenson, Todd (GE Healthcare, consultant) ToddStevenson at ge.com
Fri Mar 27 11:04:10 PDT 2009


I have run into an apparent inconsistency in AST tree construction.  I
can't see what I am doing wrong.
 
Here is the scenario.  Using this grammar (these are just snippets, not
the full grammar):
 
tokens {
    CONSTRAINT;
    VCODE;
}
 
 
element_constraint
: CARD '(' card_expression ')' -> ^(CONSTRAINT ^(CARD card_expression))
;
 
 
constraint_code
: CODE '(' ecid ')' -> ^(CODE ^(VCODE ecid))
;
 
CODE : 'code';
CARD : 'card';
 
 
I then process this tree in in an AST grammar with the following
productions:
 
 
constraint_code 
    : ^(CODE ^(VCODE ecid))
    ;
 
element_constraint
    : ^(CONSTRAINT card_constraint)
    ;
 
card_constraint
    : ^(CARD card_expression)
    ;
 
 
When I execute input with the 'card token included, I get the following
error when trying to process the AST in the 2nd grammar:
mismatched input 'card' expecting CARD

but the grammar processes input using the 'code' token just fine.  This
seems to be inconsistent in translating the CARD and CODE tokens into
the AST grammar.  What am I doing wrong?

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090327/52eae2a2/attachment.html 


More information about the antlr-interest mailing list