[antlr-interest] Problem with return values in ANTLR 3

Terence Parr parrt at cs.usfca.edu
Wed Dec 21 11:31:18 PST 2005


On Dec 21, 2005, at 3:01 AM, Dr. Kocher, Hartmut wrote:

> I try to return a boolean value from a rule (instead of the usual  
> template).
>
>
>
> Here’s the simple rule:
>
>
>
> checkedState returns [boolean result]
>
>             : 'Checked' '=' ('true' {$result = true; } |'false') ';'
>
>             ;
>
>
>
> Below’s the code that’s getting generated (ANTLR 3, EA7) (stripped  
> down to some interesting parts):
>
>  My thought’s on this:
>
> 1)       The result class seems to be OK. The Boolean field is  
> added. Maybe it should be public as well…
>
> 2)       The local variable “result” either has the wrong type or  
> is not needed at all.
>
> 3)       Instead of “result = true” I would have expected that  
> “retval.result = true” would be generated.
>
> 4)       Instead of returning “result”, it should return “retval”  
> as usual.
>
>  Any ideas?

Seems like a bug...adding to list.

> BTW: How would one access the result value in another rule?  
> $checkedState.result ???

Yes, or $label.result

Ter



More information about the antlr-interest mailing list