[antlr-interest] Building Treenodes from Kleene Closure
Dejas Ninethousand
dejas9000 at gmail.com
Tue Feb 19 10:07:05 PST 2008
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?
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).
On Feb 19, 2008 11:37 AM, shmuel siegel <antlr at shmuelhome.mine.nu> wrote:
> Dejas Ninethousand wrote:
> > If I have the grammar:
> >
> >
> > expression_list
> > :
> > expression (EXPRESSION_LIST_SEPARATOR expression)* -> EXPRESSION_LIST
> > ;
> >
> > Is there anyway to build the AST such that /n
> > /EXPRESSION_LIST_SEPARATOR nodes actually appear the number of times
> > the separator appears in the input? If so, how would I express that
> > on the right hand side of the arrow?
> >
> >
> Am I not undertstanding your question? Will this do?
>
> expression_list
> :
> e+=expression (EXPRESSION_LIST_SEPARATOR e+=expression)* ->
> ^(EXPRESSION_LIST $e+)
> ;
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080219/013e82ed/attachment-0001.html
More information about the antlr-interest
mailing list