[antlr-interest] Understanding error: Label 'XX' has already been defined

namidsf namidsf at yahoo.com
Mon Sep 23 13:59:39 PDT 2002

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:

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/ 

More information about the antlr-interest mailing list