[antlr-interest] Getting at the token text in a parser

mzukowski at yci.com mzukowski at yci.com
Mon Mar 1 11:37:32 PST 2004


A great way to learn about what antlr is doing is to simply inspect the
generated code.  Helps explain non-determisisms too.

Monty

-----Original Message-----
From: offline314159 [mailto:offline at shaw.ca] 
Sent: Sunday, February 29, 2004 4:51 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Getting at the token text in a parser

Here's what i have  - copied verbatim, because i'm not sure where the
error is.  I'm working w/ 2.7.2 in Eclipse (using the antlreclipse
plugin)

=== begin grammar segment ---
baseitem
:
(
	{ System.out.println("Entering address"); }
	ADR
	(
		params
	)?
	addressparts
	|
	{ System.out.println("Entering org"); }
	ORG
	(
		params
	)?
	orgparts
	|
	{ System.out.println("Entering N"); }
	N
	(
		params
	)?
	nameparts
	|
	{ System.out.println("Entering Agent"); }
	AGENT
	(
		params
	)?
	value
	|
	{ System.out.println("Entering " + $getText); }
	name
	(
		params
	)?
	value
)
ENDL
;
=== end grammar segment ===

It's the $getText above that is giving me troubles - i can't seem to
use it anywhere - i get the following runtime error if i try:

== error ==
java.lang.Error: Unresolved compilation problems: 
	text cannot be resolved
	_begin cannot be resolved
	text cannot be resolved
	_begin cannot be resolved
== end error ==

I get that error anywhere and any time i try to use $getText

I would just be using the debugging parser, but i can't get that to
work either - if i try to turn on analytic debugging in the parser
options, antlr borks on me with a fairly unhelpful silence.

I'm trying hard to get a grasp of this tool, because i can see that
it's very powerful, but i'm getting frustrated at the seeming
impossibility of doing basic things - and the lack of good
troubleshooting and/or common hitches.  The fact that the jguru forum
for it can't be searched unless you're a paying member isn't helping.

Hopefully someone here will be kind enough to walk me through what i'm
doing wrong.  I'll add in anything else that is necessary to diagnose
the problem.

Thanks again
Cheers
--
Chris



 
Yahoo! Groups Links



 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list