[antlr-interest] Understanding "element labels"
j_scandaliaris at yahoo.es
j_scandaliaris at yahoo.es
Tue Feb 25 06:35:07 PST 2003
Thanks for the clarification. I'll see what's the easiest to implement in my
grammar.
Jorge
> -----Mensaje original-----
> De: mzukowski at yci.com [mailto:mzukowski at yci.com]
> Enviado el: lunes, 24 de febrero de 2003 17:05
> Para: antlr-interest at yahoogroups.com
> Asunto: RE: [antlr-interest] Understanding "element labels"
>
> 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.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list