]> git.saurik.com Git - bison.git/blobdiff - src/output.c
* src/reader.h, src/reader.c (symbol_list, symbol_list_new)
[bison.git] / src / output.c
index a8ddf822dee5946c9405c7c870e5ff41dd5b606f..350d7ed85535edc8fe4d1270c5d1e1765970dd9a 100644 (file)
@@ -132,7 +132,6 @@ static short *check = NULL;
 static int lowzero;
 static int high;
 
-struct obstack muscle_obstack;
 static struct obstack format_obstack;
 
 int error_verbose = 0;
@@ -236,11 +235,11 @@ prepare_tokens (void)
     int j = 0;
     for (i = 0; i < nsyms; i++)
       {
-       /* Be sure not to use twice the same quotearg slot. */
+       /* Be sure not to use twice the same QUOTEARG slot:
+          SYMBOL_TAG_GET uses slot 0.  */
        const char *cp =
          quotearg_n_style (1, c_quoting_style,
-                           quotearg_style (escape_quoting_style,
-                                           symbols[i]->tag));
+                           symbol_tag_get (symbols[i]));
        /* Width of the next token, including the two quotes, the coma
           and the space.  */
        int strsize = strlen (cp) + 2;
@@ -308,7 +307,7 @@ prepare_rules (void)
       /* Separator in RHS. */
       rhs[i++] = -1;
       /* Line where rule was defined. */
-      rline[r] = rules[r].line;
+      rline[r] = rules[r].location.first_line;
     }
   assert (i == nritems);
 
@@ -381,8 +380,8 @@ action_row (state_t *state)
        for (j = 0; j < ntokens; j++)
          /* and record this rule as the rule to use if that
             token follows.  */
-         if (bitset_test (LA[state->lookaheadsp + i], j))
-           actrow[j] = -LArule[state->lookaheadsp + i]->number;
+         if (bitset_test (state->lookaheads[i], j))
+           actrow[j] = -state->lookaheads_rule[i]->number;
     }
 
   /* Now see which tokens are allowed for shifts in this state.  For
@@ -429,7 +428,7 @@ action_row (state_t *state)
          for (i = 0; i < state->nlookaheads; i++)
            {
              int count = 0;
-             int rule = -LArule[state->lookaheadsp + i]->number;
+             int rule = -state->lookaheads_rule[i]->number;
              int j;
 
              for (j = 0; j < ntokens; j++)
@@ -545,15 +544,11 @@ actions_output (FILE *out)
 
        if (!no_lines_flag)
          fprintf (out, muscle_find ("linef"),
-                  rules[rule].action_line,
+                  rules[rule].action_location.first_line,
                   quotearg_style (c_quoting_style,
                                   muscle_find ("filename")));
-       /* As a Bison extension, add the ending semicolon.  Since some
-          Yacc don't do that, help people using bison as a Yacc
-          finding their missing semicolons.  */
-       fprintf (out, "{ %s%s }\n    break;\n\n",
-                rules[rule].action,
-                yacc_flag ? ";" : "");
+       fprintf (out, "    %s\n    break;\n\n",
+                rules[rule].action);
       }
 }
 
@@ -946,6 +941,46 @@ output_actions (void)
 }
 
 \f
+/*----------------------.
+| Run our backend, M4.  |
+`----------------------*/
+
+static void
+m4_invoke (const char *definitions)
+{
+  /* Invoke m4 on the definition of the muscles, and the skeleton. */
+  const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR");
+  const char *m4 = getenv ("M4");
+  int pkg_data_len;
+  char *full_skeleton;
+
+  if (!m4)
+    m4 = M4;
+  if (!bison_pkgdatadir)
+    bison_pkgdatadir = PKGDATADIR;
+  pkg_data_len = strlen (bison_pkgdatadir);
+  full_skeleton = XMALLOC (char, pkg_data_len + strlen (skeleton) + 2);
+  if (bison_pkgdatadir[pkg_data_len-1] == '/')
+    sprintf (full_skeleton, "%s%s", bison_pkgdatadir, skeleton);
+  else
+    sprintf (full_skeleton, "%s/%s", bison_pkgdatadir, skeleton);
+  if (trace_flag)
+    fprintf (stderr,
+            "running: %s -I %s m4sugar/m4sugar.m4 %s %s\n",
+            m4, bison_pkgdatadir, definitions, full_skeleton);
+  skel_in = readpipe (m4,
+                     "-I", bison_pkgdatadir,
+                     "m4sugar/m4sugar.m4",
+                     definitions,
+                     full_skeleton,
+                     NULL);
+  XFREE (full_skeleton);
+  if (!skel_in)
+    error (EXIT_FAILURE, errno, "cannot run m4");
+  skel_lex ();
+
+}
+
 /*---------------------------.
 | Call the skeleton parser.  |
 `---------------------------*/
@@ -990,42 +1025,13 @@ output_skeleton (void)
   fputs ("m4_divert_push(0)dnl\n", out);
   xfclose (out);
 
-  /* Invoke m4 on the definition of the muscles, and the skeleton. */
-  {
-    const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR");
-    const char *m4 = getenv ("M4");
-    int pkg_data_len;
-    char *full_skeleton;
-
-    if (!m4)
-      m4 = M4;
-    if (!bison_pkgdatadir)
-      bison_pkgdatadir = PKGDATADIR;
-    pkg_data_len = strlen (bison_pkgdatadir);
-    full_skeleton = XMALLOC (char, pkg_data_len + strlen (skeleton) + 1);
-    if (bison_pkgdatadir[pkg_data_len-1] == '/')
-      sprintf (full_skeleton, "%s%s", bison_pkgdatadir, skeleton);
-    else
-      sprintf (full_skeleton, "%s/%s", bison_pkgdatadir, skeleton);
-    if (trace_flag)
-      fprintf (stderr,
-              "running: %s -I %s m4sugar/m4sugar.m4 %s %s\n",
-              m4, bison_pkgdatadir, tempfile, full_skeleton);
-    skel_in = readpipe (m4,
-                       "-I", bison_pkgdatadir,
-                       "m4sugar/m4sugar.m4",
-                       tempfile,
-                       full_skeleton,
-                       NULL);
-    XFREE (full_skeleton);
-    if (!skel_in)
-      error (EXIT_FAILURE, errno, "cannot run m4");
-    skel_lex ();
-
-    /* If `debugging', keep this file alive. */
-    if (!trace_flag)
-      unlink (tempfile);
-  }
+  m4_invoke (tempfile);
+
+  /* If `debugging', keep this file alive. */
+  if (!trace_flag)
+    unlink (tempfile);
+
+  free (tempfile);
 }
 
 static void
@@ -1091,9 +1097,7 @@ output (void)
   /* Process the selected skeleton file.  */
   output_skeleton ();
 
-  obstack_free (&muscle_obstack, NULL);
   obstack_free (&format_obstack, NULL);
-  obstack_free (&action_obstack, NULL);
   obstack_free (&pre_prologue_obstack, NULL);
   obstack_free (&post_prologue_obstack, NULL);
 }