[antlr-interest] labels for rule results?

Gavin Lambert antlr at mirality.co.nz
Sat Aug 23 23:33:22 PDT 2008


At 15:24 24/08/2008, Torsten Curdt wrote:
 >attributeDeclaration
 >     : type_specifier name=Identifier  ';'
 >	  {
 >		System.out.println("name:" + name.getText());
 >	  }
 >     ;
 >
 >The above works just fine. But what's the easiest way to access
 >the result of the rules?

Depends on what you mean by the "result".

If you just want the text, you can use $name.text.
If you want the return value of the rule (assuming you've defined 
one), you can use $name.valuename (whatever it happens to be -- 
there can even be more than one).

There's a number of other possibilities.  They're listed in the 
wiki.



More information about the antlr-interest mailing list