[antlr-interest] rule return value not declared
David-Sarah Hopwood
david-sarah at jacaranda.org
Wed Jul 29 15:03:54 PDT 2009
Kendall Shaw wrote:
> Gavin Lambert <antlr at mirality.co.nz> writes:
>> At 09:37 29/07/2009, Kendall Shaw wrote:
>>> The result is that the return attribute "list" is not
>>> declared in the resulting parser:
>> [...]
>>> @init { list = new ArrayList<String>(); }
>>> : (t=thingy { list.add($t.name); })+
>> You should be using $list here.
>
> Thanks. It's odd that it works in all of my other rules without the '$'.
ANTLR (at least the Java target) declares a variable corresponding to each
named child of a rule, with the same name. This is probably a bad idea
since the semantics of referring to that variable are undocumented and
usually not what you want, but it does not cause an error.
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
More information about the antlr-interest
mailing list