[antlr-interest] Methods and dynamically scoped variables

Gavin Lambert antlr at mirality.co.nz
Tue Oct 30 03:35:01 PDT 2007


At 22:55 30/10/2007, Christian Andersson wrote:
 >I tried to put @name{action} in my tree grammar file but no code
 >is generated. The only place where I can put the "name" action
 >without the generator complaining is between the rule name and
 >the contents of that rule(where the @init and @after is).

"@name" was not literal -- Ter was referring to a general pattern 
of rules in the grammar file.  ie. anything starting with an @ and 
followed by a single identifier and subsequent target-language 
block is called an "action" and is passed to the 
target-language-specific template.  Whether or not that template 
does anything with it, and where it puts the code in that block, 
is left completely up to the template file.

Thus you can make up whatever you want and ANTLR will accept it 
(provided it's syntactically sound), but unless you use one of the 
names defined by the target language template then it's not going 
to achieve anything useful.



More information about the antlr-interest mailing list