[antlr-interest] Tree construction
Haralambi Haralambiev
hharalambiev at gmail.com
Tue May 13 09:25:04 PDT 2008
Hello,
As far as I can understand - you do not have that '+' token on the left.
So, first, you should have an imaginary token defined in tokens{} block.
Then the following definition of the expr rule should do the work:
expr : (id expr) => id expr -> ^(PLUS id expr)
| id
;
Hope this helps.
-Hari
On 5/13/08, Ivan Yu Titov <ITitov at beeline.ru> wrote:
>
>
> Hello,
>
> I need to parse input "%a%b%c" into the tree. This tree should be
> like this (well-know example):
>
> +
> / \
> %a +
> / \
> %b %c
>
> After lexer I have three tokens (%a, %b, %c). How can I apply to it
> following construction:
>
> expr: id ('+'^ id)*; ?
>
> Below is my grammar:
>
> grammar Expr;
>
> id
> : Reference
> ;
>
> Reference
> : '%' Identifier
> ;
>
> fragment
> Identifier
> : Letter (Letter | Digit | '_')*
> ;
>
> fragment
> Letter : 'a'..'z' | 'A'..'Z'
> ;
>
> fragment
> Digit : '0'..'9'
> ;
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080513/dc1853ba/attachment.html
More information about the antlr-interest
mailing list