[antlr-interest] Variable visibility problem with ANTLR 3code generation

Denis Washington dwashington at gmx.net
Wed Aug 23 04:13:21 PDT 2006


Jim Idle wrote:
> -----Original Message-----
> From: Denis Washington [mailto:dwashington at gmx.net] 
> Sent: Tuesday, August 22, 2006 1:39 AM
> To: Jim Idle; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Variable visibility problem with ANTLR 3code generation
>
>   
>> Jim Idle wrote:
>>     
>>> -----Original Message-----
>>> For the following rule:
>>>
>>> declarationStatement returns [DeclarationStatement ds]
>>>     :   var=varOrConstDeclaration
>>>         {
>>>             $ds = new DeclarationStatement($var);
>>>             $ds.setSource($var);
>>>         }
>>>     ;
>>>
>>> I get from ANTLR (3.0b3):
>>>
>>> schlicht.g:240:9: missing attribute access on rule scope: var
>>>   
>>> Hi Jim,
>>>       
>> The rule varOrConstDeclaration is returning something, exactly one 
>> element, through it's action code. so it should work.
>>
>>     
> OK - off the top of my head then: is this parser producing a tree output?  If it is then your return value from varOrConstDeclaration will not be a single value but will include start and stop (offsets or trees) as well as your own declarations. Hence you would get the message you show.
>
> If you have:
>
> options
> {
> 	output = AST;
> }
> ...
> varOrConstDeclaration returns [ String answer]
> : ...
>
> Then you would need
>
> declarationStatement returns [DeclarationStatement ds]
>      :   var=varOrConstDeclaration
>          {
>              $ds = new DeclarationStatement($var.answer);
>              $ds.setSource($var.answer);
>          }
>      ;
>
> Try that and see.
>
> Jim
>
>   
Thanks for the hint, but the parser has no tree output.

Denis


More information about the antlr-interest mailing list