The CoCo grammar expression spec is shown below [2].  My problem is with 
constructions such as these:

CS = { ExternAliasDirective }
         { UsingDirective }
         EOF .

CS results in an AST with a OR_EXPR node although no '|' character 
actually appears. I'm sure this is due to my simplistic definition of 
expression but I cannot see any other way to write the rules.

I did experiment with [1] to resolve the ambiguity. It does work but the 
hack seems only to reinforce the fact that the basic construction is wrong.

Any tips much appreciated.

Jerry.

[1] expression
@init { bool ored = false; }
     : term {ored = (input.LT(1).Type == OR); } (OR term)*
         ->  {ored}? ^(OR_EXPR term term*)
         ->            ^(LIST term term*)


[2] rule '=' expression '.' ;

expression
     : term ('|' term)*
         -> ^( OR_EXPR term term* )
     ;
term
     : (factor (factor)*)? ;

factor
     : symbol
     | '(' expression ')'
         -> ^( GROUPED_EXPR expression )
     | '[' expression']'
         -> ^( OPTIONAL_EXPR expression)
     | '{' expression '}'
         -> ^( SEQUENCE_EXPR expression)
     ;

symbol
     : IF_ACTION
     | ID (ATTRIBUTES)?
     | STRINGLITERAL
     ;




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to