[antlr-interest] FYI Duplicate Nodes Behavior

Terence Parr parrt at cs.usfca.edu
Mon Feb 21 14:31:51 PST 2011


On Feb 17, 2011, at 3:55 AM, Bastian Asam wrote:

> Hello everybody,
> I just spend almost a day to figure out a difference on how ANTLR handles 
> the duplication of nodes and thought it might be helpful to others.
> 
> What I was trying to do is rather simple:
> 
> dup : 'test =' refs -> ^('test' refs refs) ;
> refs : id(',' id)* ;
> id : ID ;
> 
> That generates with input "test = test1,test2" this tree: ^('test' id test1 test2 ^(nil test1 test2))

Is there really an "id" in there too?

> Why is there a nil node generated?

a bug i think. adding.

http://www.antlr.org/jira/browse/ANTLR-443

Ter

> 
> My solution to this is to put the refs definition in the dup definition:
> dup : 'test =' (i+=id(',' i+=id)*) -> ^('test' $i* $i*) ;       // don't 
> forget the * !!
> id : ID ;
> 
> Is not particularly beautiful, but works :)
> 
> Output is now
> ^('test' id test1 test2 test1 test2)
> 
> Hope this helps someone...
> Bastian
> 
> 
> 
> IMPORTANT  -  CONFIDENTIALITY  NOTICE  - This e-mail is intended only for 
> the use of the individual or entity shown above as addressees. It may 
> contain information which is privileged, confidential or otherwise 
> protected from disclosure under applicable laws.  If the reader of this 
> transmission is not the intended recipient, you are hereby notified that 
> any dissemination, printing, distribution, copying, disclosure or the 
> taking of any action in reliance on the contents of this information is 
> strictly prohibited.  If you have received this transmission in error, 
> please immediately notify us by reply e-mail or using the address below 
> and delete the message and any attachments from your system. 
> 
> Amadeus Data Processing GmbH 
> Geschäftsführer: Eberhard Haag 
> Sitz der Gesellschaft: Erding 
> HR München 48 199 
> Berghamer Strasse 6 
> 85435 Erding 
> Germany
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list