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

Peter Robinson Peter.Robinson at t-online.de
Tue Jan 18 14:11:06 PST 2005


Hi,

I recently stumbled upon antlr -- it seems so much easier to use
productively than lex/yacc that I have been trying to learn it, even
though Java is not my "first" language. I hope these questions are not
to obvious, but I have been frutilessly googling for a few hours, so
please forgive...

1) The file type I am trying to parse has thousands of individual
records, each of which contain multiple specifications such as
status xx
where xx can be one of 2-30 keywords. I have a rule that contains the
following.

	STATUS_KW 
		s:status_type {
		  myJavaObject.setStatus(Integer.parseInt(s.getText())); }

;

status_type returns [ int x ]:  ( LIVE_KW { x = LIVE_KW; } |
	                         SECONDARY_KW { x = SECONDARY_KW; } |
				DISCONTINUED_KW { x = DISCONTINUED_KW; }|
				NEWENTRY_KW {  x = NEWENTRY_KW; } )
;

==>> However, I keep getting error messages when transforming the .g
file that "s" cannot be identified. What am I doing wrong?

2) The grammar file generates a java interface with int constants for
tokens. Assuming I have some java class files in subdirectories and want
them to know about these constants, how does one do that (just class foo
implements bar doesnt work).
==>> WHat is the best way to get other Java classes to use these tokens?

Thanks!,
Peter
:-}

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