[antlr-interest] Understanding "element labels"

mzukowski at yci.com mzukowski at yci.com
Mon Feb 24 08:05:02 PST 2003


A rule label will be naming a tree node, not a token.  You have two options.
One is to get the text out of the node.  The other is to have
parser_rule_reference return a token (or the token text for that matter), in
which case you will be responsible for declaring name and assigning it as
name=parser_rule_reference.

Monty

-----Original Message-----
From: Jorge Scandaliaris [mailto:j_scandaliaris at yahoo.es]
Sent: Saturday, February 22, 2003 2:23 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Understanding "element labels"


I've been struggling to understand how to use element labels within the
parser. What I am trying to do is:

rule	:	"some_literal1" id:ID "some_literal2"	// ID is a token
reference
				.
				.		
				.
		(name:parser_rule_reference
{id->getText()==name->getText();}?)?
	;

parser_rule_reference 
	:	ID
	;

I wanted to validate with a semantic predicate that the text of both
labels is the same, but the second element label is not declared by
antlr in the parser's c++ code and then I get error compile errors.
I can use ID instead of parser_rule_reference and that will work. So my
question is more:
What are the limitations of using element labels? In antlr doc it
mentions both atomic elements and rule references, but it seems that the
latter is intended for AST (currently off in my parser). Am I right? Am
I missing a basic point here? What other ways I would have to this?

I appreciate any help. Thanks.
		


___________________________________________________
Yahoo! Móviles
Personaliza tu móvil con tu logo y melodía favorito 
en http://moviles.yahoo.es

 

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


 

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



More information about the antlr-interest mailing list