[antlr-interest] Understanding error: Label 'XX' has already been defined
Terence Parr
parrt at jguru.com
Mon Sep 23 22:23:16 PDT 2002
On Monday, September 23, 2002, at 01:59 PM, namidsf wrote:
> Hi relatives in trade,
>
> I posted the following question on jGuru a few days ago and got
> prompt answer from Monty (thanks again). Sounds like ultimate
> solution will require work in the Code Generator.
>
> I still hope to find somebody who ran into similar behaviour
> and may have some ideas on the grammar level ...
> The following is my original message to jGuru:
The issue is that labels are used for exceptions too and hence must be
unique per method so that you can specify a catch on one of those
labels. Or am I confusing myself with PCCTS. Hmm....haven't looked at
that in a while. It's probably also an issue of where the labels are
defined.
Ter
> ---------------------------------------------------------
> There is an existing grammar file (lets say My.g) - that was
> originaly processed with Antlr 2.6.1.
> I'm working on upgrade of the grammar, but prior to appending
> grammar I would like to recompile My.g with latest Antlr 2.7.2A2
> But there are number of errors:
>
> "My.g:###:##: Label 'a' has already been defined.
> Exiting due to errors."
>
> in all rules of the following nature: (skinned)
>
> CaseNodes returns [CMyNode *pNode]
> { pNode = NULL ; }
> :
> "null" { pNode = new CMyNode(CMyNode::Null); }
> |a:CASE1 { pNode = new CMyNode(CMyNode::case1); }
> |a:CASE2 { pNode = new CMyNode(CMyNode::case2); }
> |a:CASE3 { pNode = new CMyNode(CMyNode::case3); }
> |a:DEFAULT { pNode = new CMyNode(CMyNode::dflt ); }
> . . .
> { pNode->t_ = a; }
> ;
>
> I figured if I modify this rule to be:
>
> CaseNodes returns [CMyNode *pNode]
> { pExpr = NULL ; }
> :
> "null" {pNode = new CMyNode(CMyNode::Null); }
> |a:CASE1 {pNode = new CMyNode(CMyNode::case1); pNode->t_ = a; }
> |a1:CASE2 {pNode = new CMyNode(CMyNode::case2); pNode->t_ = a1;}
> |a2:CASE3 {pNode = new CMyNode(CMyNode::case3); . . .}
> |a3:DEFAULT{pNode = new CMyNode(CMyNode::dflt ); . . .}
> . . .
> ;
> errors are gone , but this will trigger lots of changes in the
> existing grammar file, and can be are very messy.
>
> What is the reason to changes in labels-related code generation
> (in 2.7) ? Is there is another way to approach it ?
>
> Thank you,
>
> Dmitriy Neyman
>
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list