bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in alias associativities


From: Akim Demaille
Subject: Bug in alias associativities
Date: 16 Jul 2002 16:02:46 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

The system of aliases will have to be completely changed, at least to
meet the GCC team requirements.  For the time being, having it work is
a good start...

2002-07-16  Akim Demaille  <address@hidden>

        * src/assoc.c, src/asssoc.h (assoc_t, assoc_to_string): New.
        Adjust all former `associativity' dependencies.
        * src/symtab.c (symbol_new): Default associativity is `undef', not
        `right'.
        (symbol_check_alias_consistence): Adjust.

Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/bison/bison/src/Makefile.am,v
retrieving revision 1.49
diff -u -u -r1.49 Makefile.am
--- src/Makefile.am 3 Jul 2002 10:54:32 -0000 1.49
+++ src/Makefile.am 16 Jul 2002 14:00:33 -0000
@@ -37,6 +37,7 @@
 
 bison_SOURCES =                                  \
        LR0.c LR0.h                               \
+       assoc.c assoc.h                           \
        closure.c closure.h                       \
        complain.c complain.h                     \
        conflicts.c conflicts.h                   \
Index: src/assoc.c
===================================================================
RCS file: src/assoc.c
diff -N src/assoc.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/assoc.c 16 Jul 2002 14:00:33 -0000
@@ -0,0 +1,43 @@
+/* Associativity information.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+   This file is part of Bison, the GNU Compiler Compiler.
+
+   Bison is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   Bison is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bison; see the file COPYING.  If not, write to
+   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include "system.h"
+#include "assoc.h"
+
+
+const char *
+assoc_to_string (assoc_t assoc)
+{
+  switch (assoc)
+    {
+    case undef_assoc:
+      return "undefined associativity";
+
+    case right_assoc:
+      return "%right";
+
+    case left_assoc:
+      return "%left";
+
+    case non_assoc:
+      return "%nonassoc";
+    }
+  return NULL;
+}
Index: src/assoc.h
===================================================================
RCS file: src/assoc.h
diff -N src/assoc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/assoc.h 16 Jul 2002 14:00:33 -0000
@@ -0,0 +1,35 @@
+/* Associativity information.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+   This file is part of Bison, the GNU Compiler Compiler.
+
+   Bison is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   Bison is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bison; see the file COPYING.  If not, write to
+   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef ASSOC_H_
+# define ASSOC_H_
+
+/* Associativity values for tokens and rules.  */
+typedef enum
+{
+  undef_assoc,
+  right_assoc,
+  left_assoc,
+  non_assoc
+} assoc_t;
+
+const char *assoc_to_string PARAMS ((assoc_t assoc));
+
+#endif /* !ASSOC_H_ */
Index: src/parse-gram.c
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.c,v
retrieving revision 1.22
diff -u -u -r1.22 parse-gram.c
--- src/parse-gram.c 9 Jul 2002 15:54:39 -0000 1.22
+++ src/parse-gram.c 16 Jul 2002 14:00:41 -0000
@@ -105,7 +105,7 @@
 char *current_type = 0;
 symbol_t *current_lhs;
 location_t current_lhs_location;
-associativity current_assoc;
+assoc_t current_assoc;
 int current_prec = 0;
 braced_code_t current_braced_code = action_braced_code;
 
@@ -231,7 +231,7 @@
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 } yystype;
 /* Line 187 of /usr/local/share/bison/yacc.c.  */
 #line 238 "parse-gram.c"
Index: src/parse-gram.h
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.h,v
retrieving revision 1.18
diff -u -u -r1.18 parse-gram.h
--- src/parse-gram.h 9 Jul 2002 14:48:01 -0000 1.18
+++ src/parse-gram.h 16 Jul 2002 14:00:41 -0000
@@ -134,7 +134,7 @@
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 } yystype;
 /* Line 1271 of /usr/local/share/bison/yacc.c.  */
 #line 141 "y.tab.h"
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.19
diff -u -u -r1.19 parse-gram.y
--- src/parse-gram.y 9 Jul 2002 15:54:39 -0000 1.19
+++ src/parse-gram.y 16 Jul 2002 14:00:41 -0000
@@ -78,7 +78,7 @@
 char *current_type = 0;
 symbol_t *current_lhs;
 location_t current_lhs_location;
-associativity current_assoc;
+assoc_t current_assoc;
 int current_prec = 0;
 braced_code_t current_braced_code = action_braced_code;
 %}
@@ -91,7 +91,7 @@
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 };
 
 /* Define the tokens together with there human representation. */
Index: src/symtab.c
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.c,v
retrieving revision 1.44
diff -u -u -r1.44 symtab.c
--- src/symtab.c 9 Jul 2002 15:54:39 -0000 1.44
+++ src/symtab.c 16 Jul 2002 14:00:45 -0000
@@ -55,7 +55,7 @@
 
   res->number = NUMBER_UNDEFINED;
   res->prec = 0;
-  res->assoc = right_assoc;
+  res->assoc = undef_assoc;
   res->user_token_number = USER_NUMBER_UNDEFINED;
 
   res->alias = NULL;
@@ -129,7 +129,7 @@
 
 void
 symbol_precedence_set (symbol_t *symbol,
-                      int prec, associativity assoc, location_t location)
+                      int prec, assoc_t assoc, location_t location)
 {
   if (assoc != undef_assoc)
     {
@@ -288,15 +288,12 @@
 
       if (this->assoc != this->alias->assoc)
        {
-         /* FIXME: For some reason (probably the S/R => keep the S),
-            the right assoc is chosen has the ``not set''.  This is
-            not nice, fix this!  */
-         if (this->assoc != right_assoc
-             && this->alias->assoc != right_assoc)
+         if (this->assoc != undef_assoc && this->alias->assoc != undef_assoc)
            complain_at (this->alias->location,
-                        _("conflicting associativities for %s and %s"),
-                        this->tag, this->alias->tag);
-         if (this->assoc != 0)
+                        _("conflicting associativities for %s (%s) and %s 
(%s)"),
+                        this->tag, assoc_to_string (this->assoc),
+                        this->alias->tag, assoc_to_string 
(this->alias->assoc));
+         if (this->assoc != undef_assoc)
            this->alias->assoc = this->assoc;
          else
            this->assoc = this->alias->assoc;
Index: src/symtab.h
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.h,v
retrieving revision 1.42
diff -u -u -r1.42 symtab.h
--- src/symtab.h 9 Jul 2002 15:54:39 -0000 1.42
+++ src/symtab.h 16 Jul 2002 14:00:45 -0000
@@ -23,21 +23,12 @@
 # define SYMTAB_H_
 
 # include "location.h"
+# include "assoc.h"
 
 /*----------.
 | Symbols.  |
 `----------*/
 
-/* Associativity values for tokens and rules.  */
-typedef enum
-{
-  undef_assoc,
-  right_assoc,
-  left_assoc,
-  non_assoc
-} associativity;
-
-
 /* Symbol classes.  */
 typedef enum
 {
@@ -68,7 +59,7 @@
 
   symbol_number_t number;
   short prec;
-  associativity assoc;
+  assoc_t assoc;
   int user_token_number;
 
   /* Points to the other in the identifier-symbol pair for an alias.
@@ -118,7 +109,7 @@
 /* Set the PRECEDENCE associated to SYMBOL.  Ensures that SYMBOL is a
    terminal.  Does nothing if invoked with UNDEF_ASSOC as ASSOC.  */
 void symbol_precedence_set PARAMS ((symbol_t *symbol,
-                                   int prec, associativity assoc,
+                                   int prec, assoc_t assoc,
                                    location_t location));
 
 /* Set the CLASS associated to SYMBOL.  */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]