bison-patches
[Top][All Lists]
Advanced

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

01-fyi-lineno.patch


From: Akim Demaille
Subject: 01-fyi-lineno.patch
Date: Fri, 23 Nov 2001 15:01:52 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        Attaching lineno to buckets is stupid, since only one copy of each
        symbol is kept, only the line of the first occurrence is kept too.
        
        * src/symtab.h, src/symtab.c (bucket): Remove the line member.
        * src/reader.c (rline_allocated): Remove, unused.
        (symbol_list): Have a `line' member.
        (symbol_list_new): New.
        (readgram): Use it.
        * src/print.c (print_grammar): Output the rule line numbers.
        * tests/regression.at (Solved SR Conflicts)
        (Unresolved SR Conflicts): Adjust.
        Reported by Hans Aberg.
        
Index: src/print.c
--- src/print.c Sun, 18 Nov 2001 13:57:47 +0100 akim
+++ src/print.c Thu, 22 Nov 2001 20:25:14 +0100 akim
@@ -213,17 +213,19 @@
 
   /* rule # : LHS -> RHS */
   fprintf (out, "\n%s\n\n", _("Grammar"));
+  fprintf (out, "  %s\n", _("Number, Line, Rule"));
   for (i = 1; i <= nrules; i++)
     /* Don't print rules disabled in reduce_grammar_tables.  */
     if (rule_table[i].lhs >= 0)
       {
-       fprintf (out, _("rule %-4d %s ->"), i, tags[rule_table[i].lhs]);
+       fprintf (out, _("  %3d %3d %s ->"),
+                i, rule_table[i].line, tags[rule_table[i].lhs]);
        rule = &ritem[rule_table[i].rhs];
        if (*rule > 0)
          while (*rule > 0)
            fprintf (out, " %s", tags[*rule++]);
        else
-         fprintf (out, "               /* %s */", _("empty"));
+         fprintf (out, " /* %s */", _("empty"));
        fputc ('\n', out);
       }
 
Index: src/reader.c
--- src/reader.c Fri, 16 Nov 2001 01:37:30 +0100 akim
+++ src/reader.c Thu, 22 Nov 2001 21:22:02 +0100 akim
@@ -34,13 +34,11 @@
 #include "reader.h"
 #include "conflicts.h"
 
-/* Number of slots allocated (but not necessarily used yet) in `rline'  */
-static int rline_allocated;
-
 typedef struct symbol_list
 {
   struct symbol_list *next;
   bucket *sym;
+  int line;
   bucket *ruleprec;
 }
 symbol_list;
@@ -64,6 +62,19 @@
 
 static bucket *errtoken;
 static bucket *undeftoken;
+
+
+symbol_list *
+symbol_list_new (bucket *sym)
+{
+  symbol_list *res = XMALLOC (symbol_list, 1);
+  res->next = NULL;
+  res->sym = sym;
+  res->line = lineno;
+  res->ruleprec = NULL;
+  return res;
+}
+
 
 
 /*===================\
@@ -121,7 +132,7 @@
 `--------------------------------------------------------------*/
 
 static char *
-get_type_name (int n, symbol_list * rule)
+get_type_name (int n, symbol_list *rule)
 {
   int i;
   symbol_list *rp;
@@ -539,7 +550,8 @@
       else
        {
          complain (_("`%s' is invalid in %s"),
-                   token_buffer, (what_is == token_sym) ? "%token" : "%nterm");
+                   token_buffer,
+                   (what_is == token_sym) ? "%token" : "%nterm");
          skip_to_char ('%');
        }
     }
@@ -1357,8 +1369,7 @@
          nrules++;
          nitems++;
 
-         p = XCALLOC (symbol_list, 1);
-         p->sym = lhs;
+         p = symbol_list_new (lhs);
 
          crule1 = p1;
          if (p1)
@@ -1420,27 +1431,25 @@
                 non-terminal.  */
              if (action_flag)
                {
-                 bucket *sdummy;
-
                  /* Since the action was written out with this rule's
                     number, we must give the new rule this number by
                     inserting the new rule before it.  */
 
                  /* Make a dummy nonterminal, a gensym.  */
-                 sdummy = gensym ();
+                 bucket *sdummy = gensym ();
 
                  /* Make a new rule, whose body is empty,
                     before the current one, so that the action
                     just read can belong to it.  */
                  nrules++;
                  nitems++;
-                 p = XCALLOC (symbol_list, 1);
+                 p = symbol_list_new (sdummy);
                  if (crule1)
                    crule1->next = p;
                  else
                    grammar = p;
-                 p->sym = sdummy;
-                 crule1 = XCALLOC (symbol_list, 1);
+                 /* End of the rule. */
+                 crule1 = symbol_list_new (NULL);
                  crule1->next = crule;
 
                  p->next = crule1;
@@ -1448,8 +1457,7 @@
                  /* Insert the dummy generated by that rule into this
                     rule.  */
                  nitems++;
-                 p = XCALLOC (symbol_list, 1);
-                 p->sym = sdummy;
+                 p = symbol_list_new (sdummy);
                  p1->next = p;
                  p1 = p;
 
@@ -1459,8 +1467,7 @@
              if (t == tok_identifier)
                {
                  nitems++;
-                 p = XCALLOC (symbol_list, 1);
-                 p->sym = symval;
+                 p = symbol_list_new (symval);
                  p1->next = p;
                  p1 = p;
                }
@@ -1474,7 +1481,7 @@
            }                   /* end of  read rhs of rule */
 
          /* Put an empty link in the list to mark the end of this rule  */
-         p = XCALLOC (symbol_list, 1);
+         p = symbol_list_new (NULL);
          p1->next = p;
          p1 = p;
 
@@ -1855,8 +1862,6 @@
   int ruleno;
   symbol_list *p;
 
-  bucket *ruleprec;
-
   ritem = XCALLOC (short, nitems + 1);
   rule_table = XCALLOC (rule_t, nrules) - 1;
 
@@ -1866,10 +1871,10 @@
   p = grammar;
   while (p)
     {
+      bucket *ruleprec = p->ruleprec;
       rule_table[ruleno].lhs = p->sym->value;
       rule_table[ruleno].rhs = itemno;
-      rule_table[ruleno].line = p->sym->line;
-      ruleprec = p->ruleprec;
+      rule_table[ruleno].line = p->line;
 
       p = p->next;
       while (p && p->sym)
Index: src/symtab.c
--- src/symtab.c Fri, 16 Nov 2001 01:37:30 +0100 akim
+++ src/symtab.c Thu, 22 Nov 2001 20:56:26 +0100 akim
@@ -49,9 +49,6 @@
 static bucket *
 bucket_new (const char *tag, int hashval)
 {
-  /* Hack, until we have a Bison parser. */
-  extern int lineno;
-
   bucket *res = XMALLOC (bucket, 1);
 
   res->link = symtab[hashval];
@@ -64,7 +61,6 @@
   res->user_token_number = SUNDEF;
   res->alias = NULL;
   res->class = unknown_sym;
-  res->line = lineno;
 
   nsyms++;
 
Index: src/symtab.h
--- src/symtab.h Fri, 16 Nov 2001 01:37:30 +0100 akim
+++ src/symtab.h Thu, 22 Nov 2001 20:56:05 +0100 akim
@@ -42,9 +42,6 @@
   struct bucket *link;
   struct bucket *next;
 
-  /* The line it was found in. */
-  short line;
-
   /* The key, name of the symbol. */
   char *tag;
   /* Its type. */
Index: tests/regression.at
--- tests/regression.at Thu, 15 Nov 2001 08:56:59 +0100 akim
+++ tests/regression.at Thu, 22 Nov 2001 21:24:09 +0100 akim
@@ -65,8 +65,9 @@ exp: exp OP exp | NUM;
 
 Grammar
 
-rule 1    exp -> exp OP exp
-rule 2    exp -> NUM
+  Number, Line, Rule
+    1   3 exp -> exp OP exp
+    2   3 exp -> NUM
 
 Terminals, with rules where they appear
 
@@ -163,8 +164,9 @@ exp: exp OP exp | NUM;
 
 Grammar
 
-rule 1    exp -> exp OP exp
-rule 2    exp -> NUM
+  Number, Line, Rule
+    1   4 exp -> exp OP exp
+    2   4 exp -> NUM
 
 Terminals, with rules where they appear
 



reply via email to

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