[antlr-interest] put instructions into constructors

Jim Idle jimi at temporal-wave.com
Mon Feb 11 16:33:00 PST 2008


The *_return are really just containers for the ‘real’ return values.
What you probably looking to do is have your rules return your own
objects, the constructors for which you can of course code to be
whatever you like.

 

If you write:

 

rulea

returns [ int x, int y ]

 

You can just as easily write:

 

rulea

returns [ myPointClass point]

 

Then your action code can: { $point = new myPointClass(whatever); }

 

And invocations of the rule:

 

 … xx= rulea …

 

Can then use (in actions):

 

   { out.println(“Point is “ + $xx.point); }

 

Hope that helps,

 

Jim

 

From: Peter Bulychev [mailto:peter.bulychev at gmail.com] 
Sent: Monday, February 11, 2008 4:21 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] put instructions into constructors

 

Hello.

How can I put instructions in the constructors of all *_return classes?

Thank you.

-- 
Best regards,
   Peter Bulychev. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080211/4d174648/attachment.html 


More information about the antlr-interest mailing list