Lemon fix: don't let grammar define the same nonterminal %type more than once.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 17 Feb 2010 15:35:15 -0500
changeset 833 cd7c278acf02
parent 832 375ac4fcdc51
child 834 f651801bfbbd
Lemon fix: don't let grammar define the same nonterminal %type more than once.
misc/lemon.c
--- a/misc/lemon.c	Wed Feb 17 15:34:43 2010 -0500
+++ b/misc/lemon.c	Wed Feb 17 15:35:15 2010 -0500
@@ -2357,10 +2357,20 @@
         psp->errorcnt++;
         psp->state = RESYNC_AFTER_DECL_ERROR;
       }else{
-        struct symbol *sp = Symbol_new(x);
-        psp->declargslot = &sp->datatype;
-        psp->insertLineMacro = 0;
-        psp->state = WAITING_FOR_DECL_ARG;
+        struct symbol *sp = Symbol_find(x);
+        if((sp) && (sp->datatype)){
+          ErrorMsg(psp->filename,psp->tokenlineno,
+            "Symbol %%type \"%s\" already defined", x);
+          psp->errorcnt++;
+          psp->state = RESYNC_AFTER_DECL_ERROR;
+        }else{
+          if (!sp){
+            sp = Symbol_new(x);
+          }
+          psp->declargslot = &sp->datatype;
+          psp->insertLineMacro = 0;
+          psp->state = WAITING_FOR_DECL_ARG;
+        }
       }
       break;
     case WAITING_FOR_PRECEDENCE_SYMBOL: