[antlr-interest] Problem using += operator in actions
Miguel Ping
miguel.ping at gmail.com
Tue Apr 17 06:41:35 PDT 2007
I guess antlr is a little obscure on the syntax. I had some trouble
with trees and with actions order. For instance, I tried to do this:
rule: partA pb=partB? partC -> ^(partA ^($pb? ) partC )
but it seems that the ^ should contain only the ref:
(...) -> ^(partA ^($pb)? partC .
I also got some trouble with synpreds => and parenthesis, with members
order (the lexer at member:: and parser at member stuff), and with tree
rewrite rules. I guess all of us eventually figure a way to solve
things, and it ends up in our common sense, instead of maybe being in
the wiki ;)
Maybe we can gather this common mistakes, and make a "check this
before going nuts" page or so...
On 4/17/07, Martin Fowler <fowler at acm.org> wrote:
> This is another one of those problems I ended up solving myself but I
> post here to help others.
>
> I wanted to collect together some words using the += operator. I used a
> grammar line like this:
>
> item : 'item' w += WORD+ ';'
> {System.out.println("name is: " + $w);}
> ;
>
> The problem was that $w ended up being null.
>
> My mistake was that the phrase w+=WORD needed to be contained in
> parentheses before applying the +, like so:
>
> item : 'item' (w += WORD)+ ';'
> {System.out.println("name is: " + $w);}
> ;
>
>
> --
> Martin Fowler
> http://martinfowler.com
>
More information about the antlr-interest
mailing list