bison-patches
[Top][All Lists]
Advanced

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

02-reader-reads-2.patch


From: Akim Demaille
Subject: 02-reader-reads-2.patch
Date: Sun, 09 Jun 2002 19:15:37 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/symtab.c, src/symtab.c (symbol_type_set)
        (symbol_precedence_set): New.
        * src/reader.c (parse_type_decl, parse_assoc_decl): Use them.
        (value_components_used): Remove, unused.

Index: TODO
--- TODO Thu, 06 Jun 2002 20:45:16 +0200 akim
+++ TODO Sun, 09 Jun 2002 15:51:28 +0200 akim
@@ -3,6 +3,11 @@
 * URGENT: Documenting C++ output
 Write a first documentation for C++ output.

+* value_components_used
+Was defined but not used: where was it coming from?  It can't be to
+check if %union is used, since the user is free to $<foo>n on her
+union, doesn't she?
+
 * yyerror, yyprint interface
 It should be improved, in particular when using Bison features such as
 locations, and YYPARSE_PARAMS.  For the time being, it is recommended
Index: src/reader.c
--- src/reader.c Sun, 09 Jun 2002 15:43:20 +0200 akim
+++ src/reader.c Sun, 09 Jun 2002 15:59:21 +0200 akim
@@ -52,10 +52,6 @@
 static symbol_list *grammar = NULL;
 static int start_flag = 0;

-/* Nonzero if components of semantic values are used, implying
-   they must be unions.  */
-static int value_components_used;
-
 /* Nonzero if %union has been seen.  */
 static int typed = 0;

@@ -378,7 +374,6 @@
     {
       read_type_name (fin);
       type_name = token_buffer;
-      value_components_used = 1;
       c = getc (fin);
     }

@@ -525,7 +520,6 @@
       if (token == tok_typename)
        {
          typename = xstrdup (token_buffer);
-         value_components_used = 1;
          symbol = NULL;
        }
       else if (token == tok_identifier && *symval->tag == '\"' && symbol)
@@ -630,17 +624,12 @@

       switch (t)
        {
-
        case tok_comma:
        case tok_semicolon:
          break;

        case tok_identifier:
-         if (symval->type_name == NULL)
-           symval->type_name = name;
-         else if (strcmp (name, symval->type_name) != 0)
-           complain (_("type redeclaration for %s"), symval->tag);
-
+         symbol_type_set (symval, name);
          break;

        default:
@@ -689,10 +678,6 @@
          break;

        case tok_identifier:
-         if (symval->prec != 0)
-           complain (_("redefining precedence of %s"), symval->tag);
-         symval->prec = lastprec;
-         symval->assoc = assoc;
          if (symval->class == nterm_sym)
            complain (_("symbol %s redefined"), symval->tag);
          if (symval->number == NUMBER_UNDEFINED)
@@ -700,13 +685,9 @@
              symval->number = ntokens++;
              symval->class = token_sym;
            }
+         symbol_precedence_set (symval, lastprec, assoc);
          if (name)
-           {                   /* record the type, if one is specified */
-             if (symval->type_name == NULL)
-               symval->type_name = name;
-             else if (strcmp (name, symval->type_name) != 0)
-               complain (_("type redeclaration for %s"), symval->tag);
-           }
+           symbol_type_set (symval, name);
          break;

        case tok_number:
@@ -851,7 +832,6 @@
   if (token == tok_typename)
     {
       typename = xstrdup (token_buffer);
-      value_components_used = 1;
       token = lex ();          /* fetch first token */
     }

Index: src/symtab.c
--- src/symtab.c Sun, 09 Jun 2002 15:43:20 +0200 akim
+++ src/symtab.c Sun, 09 Jun 2002 16:00:10 +0200 akim
@@ -58,6 +58,34 @@
 }


+/*-----------------------------------------.
+| Set the TYPE_NAME associated to SYMBOL.  |
+`-----------------------------------------*/
+
+void
+symbol_type_set (symbol_t *symbol, char *type_name)
+{
+  if (symbol->type_name)
+    complain (_("type redeclaration for %s"), symbol->tag);
+  symbol->type_name = type_name;
+}
+
+
+/*------------------------------------------.
+| Set the PRECEDENCE associated to SYMBOL.  |
+`------------------------------------------*/
+
+void
+symbol_precedence_set (symbol_t *symbol,
+                      int prec, associativity assoc)
+{
+  if (symbol->prec != 0)
+    complain (_("redefining precedence of %s"), symbol->tag);
+  symbol->prec = prec;
+  symbol->assoc = assoc;
+}
+
+
 /*------------.
 | Free THIS.  |
 `------------*/
Index: src/symtab.h
--- src/symtab.h Sun, 09 Jun 2002 15:43:20 +0200 akim
+++ src/symtab.h Sun, 09 Jun 2002 15:57:44 +0200 akim
@@ -84,6 +84,13 @@
 /* Fetch (or create) the symbol associated to KEY.  */
 symbol_t *getsym PARAMS ((const char *key));

+/* Set the TYPE_NAME associated to SYMBOL. */
+void symbol_type_set PARAMS ((symbol_t *symbol, char *type_name));
+
+/* Set the PRECEDENCE associated to SYMBOL.  */
+void symbol_precedence_set PARAMS ((symbol_t *symbol,
+                                   int prec, associativity assoc));
+
 /* Distinguished symbols.  AXIOM is the real start symbol, that used
    by the automaton.  STARTSYMBOL is the one specified by the user.
    */



reply via email to

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