[antlr-interest] Building Treenodes from Kleene Closure
Gavin Lambert
antlr at mirality.co.nz
Tue Feb 19 10:40:34 PST 2008
At 07:07 20/02/2008, Dejas Ninethousand wrote:
>I think that's moving in the right direction, except I want the
>seperators and not the expression. I tried:
>
>expression (e+=EXPRESSION_LIST_SEPARATOR expression)* -> $e+
>EXPRESSION_LIST
>
>which works fine unless there are 0 occurences of
>EXPRESSION_LIST_SEPARATOR expression in which case the parser
>throws an early exit exception. Is there a way to exclude the
>$e+ if the number of occurrences is zero?
Yeah: $e*. :)
>I tried:
>
>expression_list
> :
> expression -> EXPRESSION_LIST
> |
> expression (e+=EXPRESSION_LIST_SEPARATOR expression)+ -> $e+
> EXPRESSION_LIST
>
>but ANTLER complains about introduction of left recursion (which
>I don't see).
Can 'expression' include 'expression_list'?
But anyway, what you do have there is common left prefixes in
alts, which isn't a good idea. Try this instead:
expression_list
: expression -> EXPRESSION_LIST
( (e+=EXPRESSION_LIST_SEPARATOR expression)+ ->
^(EXPRESSION_LIST $e+) )?
;
But it's a bit strange that you're throwing away all the actual
expressions.
More information about the antlr-interest
mailing list