[antlr-interest] Tree grammar for expression subrules?
Bart Kiers
bkiers at gmail.com
Fri Mar 4 11:13:12 PST 2011
On Fri, Mar 4, 2011 at 6:53 PM, g4 at novadsp.com <g4 at novadsp.com> wrote:
> 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)
> )
> )*
> ;
>
I'd expect that to become the tree-grammar rule:
expression
: term
| ^(OR expression term)
| ^(OR expression EPSILON)
;
instead of:
>
> // 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)
> ;
>
>
Regards,
Bart.
More information about the antlr-interest
mailing list