]> git.saurik.com Git - bison.git/blobdiff - src/nullable.c
* src/bison.simple: Remove YYERROR_VERBOSE using.
[bison.git] / src / nullable.c
index dae7a62a561f1abfba0a83dda503f07b6986defa..c207924dc8328a9770263d2313451c8e38b66748 100644 (file)
@@ -1,5 +1,5 @@
 /* Part of the bison parser generator,
 /* Part of the bison parser generator,
-   Copyright (C) 1984, 1989, 2000 Free Software Foundation, Inc.
+   Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
    do so.  */
 
 #include "system.h"
    do so.  */
 
 #include "system.h"
+#include "getargs.h"
+#include "reader.h"
 #include "types.h"
 #include "gram.h"
 #include "types.h"
 #include "gram.h"
-#include "xalloc.h"
 #include "nullable.h"
 
 char *nullable = NULL;
 
 #include "nullable.h"
 
 char *nullable = NULL;
 
+static void
+nullable_print (FILE *out)
+{
+  int i;
+  fputs ("NULLABLE\n", out);
+  for (i = ntokens; i < nsyms; i++)
+    fprintf (out, "\t%s: %s\n", tags[i], nullable[i] ? "yes" : "no");
+  fputs ("\n\n", out);
+}
+
 void
 set_nullable (void)
 {
   short *r;
   short *s1;
   short *s2;
 void
 set_nullable (void)
 {
   short *r;
   short *s1;
   short *s2;
-  int ruleno;
-  int symbol;
   shorts *p;
 
   short *squeue;
   short *rcount;
   shorts **rsets;
   shorts *relts;
   shorts *p;
 
   short *squeue;
   short *rcount;
   shorts **rsets;
   shorts *relts;
-  char any_tokens;
-  short *r1;
 
 
-#ifdef TRACE
-  fprintf (stderr, _("Entering set_nullable"));
-#endif
+  if (trace_flag)
+    fprintf (stderr, "Entering set_nullable\n");
 
   nullable = XCALLOC (char, nvars) - ntokens;
 
 
   nullable = XCALLOC (char, nvars) - ntokens;
 
@@ -70,7 +76,7 @@ set_nullable (void)
     {
       if (*r < 0)
        {
     {
       if (*r < 0)
        {
-         symbol = rlhs[-(*r++)];
+         int symbol = rule_table[-(*r++)].lhs;
          if (symbol >= 0 && !nullable[symbol])
            {
              nullable[symbol] = 1;
          if (symbol >= 0 && !nullable[symbol])
            {
              nullable[symbol] = 1;
@@ -79,17 +85,16 @@ set_nullable (void)
        }
       else
        {
        }
       else
        {
-         r1 = r;
-         any_tokens = 0;
+         int any_tokens = 0;
+         int symbol;
+         short *r1 = r;
          for (symbol = *r++; symbol > 0; symbol = *r++)
          for (symbol = *r++; symbol > 0; symbol = *r++)
-           {
-             if (ISTOKEN (symbol))
-               any_tokens = 1;
-           }
+           if (ISTOKEN (symbol))
+             any_tokens = 1;
 
          if (!any_tokens)
            {
 
          if (!any_tokens)
            {
-             ruleno = -symbol;
+             int ruleno = -symbol;
              r = r1;
              for (symbol = *r++; symbol > 0; symbol = *r++)
                {
              r = r1;
              for (symbol = *r++; symbol > 0; symbol = *r++)
                {
@@ -108,11 +113,11 @@ set_nullable (void)
       p = rsets[*s1++];
       while (p)
        {
       p = rsets[*s1++];
       while (p)
        {
-         ruleno = p->value;
+         int ruleno = p->value;
          p = p->next;
          if (--rcount[ruleno] == 0)
            {
          p = p->next;
          if (--rcount[ruleno] == 0)
            {
-             symbol = rlhs[ruleno];
+             int symbol = rule_table[ruleno].lhs;
              if (symbol >= 0 && !nullable[symbol])
                {
                  nullable[symbol] = 1;
              if (symbol >= 0 && !nullable[symbol])
                {
                  nullable[symbol] = 1;
@@ -126,6 +131,9 @@ set_nullable (void)
   XFREE (rcount);
   XFREE (rsets + ntokens);
   XFREE (relts);
   XFREE (rcount);
   XFREE (rsets + ntokens);
   XFREE (relts);
+
+  if (trace_flag)
+    nullable_print (stderr);
 }
 
 
 }