[antlr-interest] Token Attributes in Arraylist

Alexander Gängel alexander at gaengel.de
Fri Mar 14 04:06:13 PDT 2008


Thank you this work very well,

I was just wondering if there is some way in Antlr already cause this 
way I don't use the id+= operator and Coding in Antlrworks is with out 
knowing all methods the CommenTree in the ArrayList from id+= is a bit 
difficult so I would think it would be handy to use the attributes Antlr 
gives on the Tokens also on the ArrayList.

Alexander

Richard Clark schrieb:
> On Wed, Mar 12, 2008 at 9:08 AM, Alexander Gängel <alexander at gaengel.de> wrote:
>   
>> Is use id+=Identifier+ in a rule in my treegrammar and was wondering if
>>  there is some "easy" way to get an arrayList of just the text of the
>>  token like $if.text
>>     
>
> Usually you just embed an action to append to a list as you go.
>
> myRule
> @init { List values = new ArrayList(); }
>      : (id+=Identifier { values.add($Identifier.text);})+
>      // and do something with the list after
>      ;
>
> ...Richard
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080314/d8b427a0/attachment.html 


More information about the antlr-interest mailing list