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

Jim Idle jimi at intersystems.com
Tue Aug 22 09:34:31 PDT 2006



-----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

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.4/424 - Release Date: 8/21/2006
 


More information about the antlr-interest mailing list