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

Jim Idle jimi at intersystems.com
Wed Aug 23 08:49:20 PDT 2006



-----Original Message-----
From: Denis Washington [mailto:dwashington at gmx.net] 
Sent: Wednesday, August 23, 2006 4:13 AM

>>> declarationStatement returns [DeclarationStatement ds]
>>>     :   var=varOrConstDeclaration
>>>         {
>>>             $ds = new DeclarationStatement($var);
>>>             $ds.setSource($var);
>>>         }
>>>     ;
>>>

OK, I see what is happening now. ANTLR is seeing your $ds.setSource as a reference to an attribute of $ds as if you had done this:

Returns [ int setSource, int something else]


This is because you can reference attributes of a $ref such as $ref.text and $ref.tree etc. You will have to disambiguate this a bit.

Either:

declarationStatement returns [DeclarationStatement ds]
:   var=varOrConstDeclaration
    {
	   DeclarationStatement		localDS;

         localDS  = new DeclarationStatement($var);
         localDS.setSource($var);
	   $ds	= localDS;
    }
;

Or it is possible that the following might work (have not tried this though):

($ds).setSource($var);
 
If the above does not work, then perhaps it should as a way to distinguish between label attributes and object elements of the label type.

Jim

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


More information about the antlr-interest mailing list