[antlr-interest] Using token values in other java classes (newbie)

Peter Robinson Peter.Robinson at t-online.de
Tue Jan 18 22:49:27 PST 2005


Thanks to Nigel and Paul for the prompt and useful answers. Now it
works. To summarize the correct solution:

myrule {int tt;}: tt=status_type { myJavaObject.setStatus(tt); }
	;

status_type returns [ int x = LIVE_KW /* the default */ ]
		{
                    x = LA(1);
                }:
  ( LIVE_KW  |  SECONDARY_KW  | DISCONTINUED_KW  |  NEWENTRY_KW  )
;

-peter

On Wed, 2005-01-19 at 02:06, Nigel Sheridan-Smith wrote:
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Nigel Sheridan-Smith
> > Sent: Wednesday, 19 January 2005 9:38 AM
> > To: 'Peter Robinson'; antlr-interest at antlr.org
> > Subject: RE: [antlr-interest] Using token values in other java classes
> > (newbie)
> > 
> > > -----Original Message-----
> > > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > > bounces at antlr.org] On Behalf Of Peter Robinson
> > > Sent: Wednesday, 19 January 2005 9:11 AM
> > > To: antlr-interest at antlr.org
> > > Subject: [antlr-interest] Using token values in other java classes
> > > (newbie)
> > >
> > >
> > > 	STATUS_KW
> > > 		s:status_type {
> > > 		  myJavaObject.setStatus(Integer.parseInt(s.getText())); }
> > >
> 
> Oh yeah! One other thing, you need to declare s (for saving return values):
> 
> 	STATUS_KW
> 					{int s=0;}
> 		: s=status_type 	{myJavaObject.setStatus(s);};
> 
> Nigel
> 
> 
> 
> --
> Nigel Sheridan-Smith
> PhD research student
> 
> Faculty of Engineering
> University of Technology, Sydney
> Phone: 02 9514 7946
> Fax: 02 9514 2435
-- 
Peter N. Robinson
peter.robinson at t-online.de
peter.robinson at charite.de
http://www.charite.de/ch/medgen/robinson/



More information about the antlr-interest mailing list