[antlr-interest] Tree grammar for expression subrules?

g4 at novadsp.com g4 at novadsp.com
Fri Mar 4 09:53:59 PST 2011


Is there a pattern to follow for creating tree grammars for subrules?

// parser rule. this works.
expression
     : (a=term -> $a) ( ( '|' b=term -> ^(OR $expression $b)
                        | '|'        -> ^(OR $expression EPSILON)
                        )
                      )*
     ;

// tree grammar 1, based on CMinus example in the book.Throws a 
MismatchedTreeNodeException complaining about lack of
// 'UP' at SEQUENCE_EXPR
expression
     : IF_ACTION
     | ID
     | ID ATTRIBUTES
     | STRINGLITERAL
     | EPSILON
     | ^(GROUPED_EXPR expression)
     | ^(OPTIONAL_EXPR expression)
     | ^(SEQUENCE_EXPR expression)
     ;

Any pointers welcomed. Thx++

Jerry




More information about the antlr-interest mailing list