[antlr-interest] Variable visibility problem with ANTLR 3code
generation
Denis Washington
dwashington at gmx.net
Mon Aug 21 03:44:38 PDT 2006
Jim Idle wrote:
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>
>
>> The '$' prefix is not needed, from what I see after code generation it's
>> even wrong.
>>
>
>
> If it really is wrong, then there is a bug as the $ prefix is always needed in ANTLR3.
>
> Depending on what is being generated, it can sometimes be the case that an unadorned reference to a label happens to use the same variable name as your action code and it compiles and works. However, you do need the $. As in the example below (output=AST).
>
> querySpecs
> : (
> FILENAME EQ fname = STRING SEMI
> GLOBAL EQ global = STRING SEMI
> FILETYPE EQ ftype = NUMBER SEMI
> COMMAND EQ command = STRING SEMI
> TYPE EQ query_type SEMI
> (PROCESSOR EQ output = STRING SEMI)?
> OPTIONS EQ opts = STRING SEMI
> SORTED EQ sorted = bool SEMI
> SELECTLIST EQ sellist = bool SEMI
> )
> -> ^(QUERY_SPECS
> FILENAME $fname
> GLOBAL $global
> FILETYPE $ftype
> COMMAND $command
> TYPE query_type
> (PROCESSOR $output)?
> OPTIONS $opts
> SORTED $sorted
> SELECTLIST $sellist
> )
> ;
>
> Jim
>
>
>
>
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
Is this a bug? Or do I still understand the $ prefix wrong?
More information about the antlr-interest
mailing list