]> git.saurik.com Git - bison.git/blobdiff - src/print-xml.c
parser: no longer use the "braceless" non-terminal
[bison.git] / src / print-xml.c
index 400ce69f78fc6086b14d3def7e6a394b2ae9057e..a3ef15117d773647f9305305aa6a10aef27042a1 100644 (file)
@@ -1,6 +1,6 @@
 /* Print an xml on generated parser, for Bison,
 
 /* Print an xml on generated parser, for Bison,
 
-   Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -23,7 +23,6 @@
 #include <stdarg.h>
 
 #include <bitset.h>
 #include <stdarg.h>
 
 #include <bitset.h>
-#include <quotearg.h>
 
 #include "LR0.h"
 #include "closure.h"
 
 #include "LR0.h"
 #include "closure.h"
@@ -82,36 +81,36 @@ print_core (FILE *out, int level, state *s)
       sp1 = sp = ritem + sitems[i];
 
       while (*sp >= 0)
       sp1 = sp = ritem + sitems[i];
 
       while (*sp >= 0)
-       sp++;
+        sp++;
 
       r = item_number_as_rule_number (*sp);
       sp = rules[r].rhs;
 
       /* Display the lookahead tokens?  */
       if (item_number_is_rule_number (*sp1))
 
       r = item_number_as_rule_number (*sp);
       sp = rules[r].rhs;
 
       /* Display the lookahead tokens?  */
       if (item_number_is_rule_number (*sp1))
-       {
-         reductions *reds = s->reductions;
-         int red = state_reduction_find (s, &rules[r]);
-         /* Print item with lookaheads if there are. */
-         if (reds->lookahead_tokens && red != -1)
-           {
-             xml_printf (out, level + 1,
-                         "<item rule-number=\"%d\" point=\"%d\">",
-                         rules[r].number, sp1 - sp);
-             state_rule_lookahead_tokens_print_xml (s, &rules[r],
-                                                    out, level + 2);
-             xml_puts (out, level + 1, "</item>");
-             printed = true;
-           }
-       }
+        {
+          reductions *reds = s->reductions;
+          int red = state_reduction_find (s, &rules[r]);
+          /* Print item with lookaheads if there are. */
+          if (reds->lookahead_tokens && red != -1)
+            {
+              xml_printf (out, level + 1,
+                          "<item rule-number=\"%d\" point=\"%d\">",
+                          rules[r].number, sp1 - sp);
+              state_rule_lookahead_tokens_print_xml (s, &rules[r],
+                                                     out, level + 2);
+              xml_puts (out, level + 1, "</item>");
+              printed = true;
+            }
+        }
 
       if (!printed)
 
       if (!printed)
-       {
-         xml_printf (out, level + 1,
-                     "<item rule-number=\"%d\" point=\"%d\"/>",
-                     rules[r].number,
-                     sp1 - sp);
-       }
+        {
+          xml_printf (out, level + 1,
+                      "<item rule-number=\"%d\" point=\"%d\"/>",
+                      rules[r].number,
+                      sp1 - sp);
+        }
     }
   xml_puts (out, level, "</itemset>");
 }
     }
   xml_puts (out, level, "</itemset>");
 }
@@ -132,7 +131,7 @@ print_transitions (state *s, FILE *out, int level)
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i))
       {
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i))
       {
-       n++;
+        n++;
       }
 
   /* Nothing to report. */
       }
 
   /* Nothing to report. */
@@ -146,28 +145,28 @@ print_transitions (state *s, FILE *out, int level)
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
-       && TRANSITION_IS_SHIFT (trans, i))
+        && TRANSITION_IS_SHIFT (trans, i))
       {
       {
-       symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
-       char const *tag = sym->tag;
-       state *s1 = trans->states[i];
+        symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+        char const *tag = sym->tag;
+        state *s1 = trans->states[i];
 
 
-       xml_printf (out, level + 1,
-                   "<transition type=\"shift\" symbol=\"%s\" state=\"%d\"/>",
-                   xml_escape (tag), s1->number);
+        xml_printf (out, level + 1,
+                    "<transition type=\"shift\" symbol=\"%s\" state=\"%d\"/>",
+                    xml_escape (tag), s1->number);
       }
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
       }
 
   for (i = 0; i < trans->num; i++)
     if (!TRANSITION_IS_DISABLED (trans, i)
-       && !TRANSITION_IS_SHIFT (trans, i))
+        && !TRANSITION_IS_SHIFT (trans, i))
       {
       {
-       symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
-       char const *tag = sym->tag;
-       state *s1 = trans->states[i];
+        symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+        char const *tag = sym->tag;
+        state *s1 = trans->states[i];
 
 
-       xml_printf (out, level + 1,
-                   "<transition type=\"goto\" symbol=\"%s\" state=\"%d\"/>",
-                   xml_escape (tag), s1->number);
+        xml_printf (out, level + 1,
+                    "<transition type=\"goto\" symbol=\"%s\" state=\"%d\"/>",
+                    xml_escape (tag), s1->number);
       }
 
   xml_puts (out, level, "</transitions>");
       }
 
   xml_puts (out, level, "</transitions>");
@@ -200,36 +199,36 @@ print_errs (FILE *out, int level, state *s)
   for (i = 0; i < errp->num; ++i)
     if (errp->symbols[i])
       {
   for (i = 0; i < errp->num; ++i)
     if (errp->symbols[i])
       {
-       char const *tag = errp->symbols[i]->tag;
-       xml_printf (out, level + 1,
-                   "<error symbol=\"%s\">nonassociative</error>",
-                   xml_escape (tag));
+        char const *tag = errp->symbols[i]->tag;
+        xml_printf (out, level + 1,
+                    "<error symbol=\"%s\">nonassociative</error>",
+                    xml_escape (tag));
       }
   xml_puts (out, level, "</errors>");
 }
 
 
 /*-------------------------------------------------------------------------.
       }
   xml_puts (out, level, "</errors>");
 }
 
 
 /*-------------------------------------------------------------------------.
-| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be `default').  |
+| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default').  |
 | If not ENABLED, the rule is masked by a shift or a reduce (S/R and       |
 | R/R conflicts).                                                          |
 `-------------------------------------------------------------------------*/
 
 static void
 print_reduction (FILE *out, int level, char const *lookahead_token,
 | If not ENABLED, the rule is masked by a shift or a reduce (S/R and       |
 | R/R conflicts).                                                          |
 `-------------------------------------------------------------------------*/
 
 static void
 print_reduction (FILE *out, int level, char const *lookahead_token,
-                rule *r, bool enabled)
+                 rule *r, bool enabled)
 {
   if (r->number)
     xml_printf (out, level,
 {
   if (r->number)
     xml_printf (out, level,
-               "<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
-               xml_escape (lookahead_token),
-               r->number,
-               enabled ? "true" : "false");
+                "<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
+                xml_escape (lookahead_token),
+                r->number,
+                enabled ? "true" : "false");
   else
     xml_printf (out, level,
   else
     xml_printf (out, level,
-               "<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
-               xml_escape (lookahead_token),
-               enabled ? "true" : "false");
+                "<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
+                xml_escape (lookahead_token),
+                enabled ? "true" : "false");
 }
 
 
 }
 
 
@@ -268,22 +267,22 @@ print_reductions (FILE *out, int level, state *s)
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
-       bool count = bitset_test (no_reduce_set, i);
-
-       for (j = 0; j < reds->num; ++j)
-         if (bitset_test (reds->lookahead_tokens[j], i))
-           {
-             if (! count)
-               {
-                 if (reds->rules[j] != default_reduction)
-                   report = true;
-                 count = true;
-               }
-             else
-               {
-                 report = true;
-               }
-           }
+        bool count = bitset_test (no_reduce_set, i);
+
+        for (j = 0; j < reds->num; ++j)
+          if (bitset_test (reds->lookahead_tokens[j], i))
+            {
+              if (! count)
+                {
+                  if (reds->rules[j] != default_reduction)
+                    report = true;
+                  count = true;
+                }
+              else
+                {
+                  report = true;
+                }
+            }
       }
 
   /* Nothing to report. */
       }
 
   /* Nothing to report. */
@@ -298,36 +297,36 @@ print_reductions (FILE *out, int level, state *s)
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
   if (reds->lookahead_tokens)
     for (i = 0; i < ntokens; i++)
       {
-       bool defaulted = false;
-       bool count = bitset_test (no_reduce_set, i);
-
-       for (j = 0; j < reds->num; ++j)
-         if (bitset_test (reds->lookahead_tokens[j], i))
-           {
-             if (! count)
-               {
-                 if (reds->rules[j] != default_reduction)
-                   print_reduction (out, level + 1, symbols[i]->tag,
-                                    reds->rules[j], true);
-                 else
-                   defaulted = true;
-                 count = true;
-               }
-             else
-               {
-                 if (defaulted)
-                   print_reduction (out, level + 1, symbols[i]->tag,
-                                    default_reduction, true);
-                 defaulted = false;
-                 print_reduction (out, level + 1, symbols[i]->tag,
-                                  reds->rules[j], false);
-               }
-           }
+        bool defaulted = false;
+        bool count = bitset_test (no_reduce_set, i);
+
+        for (j = 0; j < reds->num; ++j)
+          if (bitset_test (reds->lookahead_tokens[j], i))
+            {
+              if (! count)
+                {
+                  if (reds->rules[j] != default_reduction)
+                    print_reduction (out, level + 1, symbols[i]->tag,
+                                     reds->rules[j], true);
+                  else
+                    defaulted = true;
+                  count = true;
+                }
+              else
+                {
+                  if (defaulted)
+                    print_reduction (out, level + 1, symbols[i]->tag,
+                                     default_reduction, true);
+                  defaulted = false;
+                  print_reduction (out, level + 1, symbols[i]->tag,
+                                   reds->rules[j], false);
+                }
+            }
       }
 
   if (default_reduction)
     print_reduction (out, level + 1,
       }
 
   if (default_reduction)
     print_reduction (out, level + 1,
-                    "$default", default_reduction, true);
+                     "$default", default_reduction, true);
 
   xml_puts (out, level, "</reductions>");
 }
 
   xml_puts (out, level, "</reductions>");
 }
@@ -390,7 +389,7 @@ print_grammar (FILE *out, int level)
   for (i = 0; i < max_user_token_number + 1; i++)
     if (token_translations[i] != undeftoken->number)
       {
   for (i = 0; i < max_user_token_number + 1; i++)
     if (token_translations[i] != undeftoken->number)
       {
-       char const *tag = symbols[token_translations[i]]->tag;
+        char const *tag = symbols[token_translations[i]]->tag;
         int precedence = symbols[token_translations[i]]->prec;
         assoc associativity = symbols[token_translations[i]]->assoc;
         xml_indent (out, level + 2);
         int precedence = symbols[token_translations[i]]->prec;
         assoc associativity = symbols[token_translations[i]]->assoc;
         xml_indent (out, level + 2);
@@ -414,9 +413,9 @@ print_grammar (FILE *out, int level)
     {
       char const *tag = symbols[i]->tag;
       xml_printf (out, level + 2,
     {
       char const *tag = symbols[i]->tag;
       xml_printf (out, level + 2,
-                 "<nonterminal symbol-number=\"%d\" name=\"%s\""
+                  "<nonterminal symbol-number=\"%d\" name=\"%s\""
                   " usefulness=\"%s\"/>",
                   " usefulness=\"%s\"/>",
-                 i, xml_escape (tag),
+                  i, xml_escape (tag),
                   reduce_nonterminal_useless_in_grammar (i)
                     ? "useless-in-grammar" : "useful");
     }
                   reduce_nonterminal_useless_in_grammar (i)
                     ? "useless-in-grammar" : "useful");
     }
@@ -512,7 +511,7 @@ print_xml (void)
 
   fputc ('\n', out);
   xml_printf (out, level + 1, "<filename>%s</filename>",
 
   fputc ('\n', out);
   xml_printf (out, level + 1, "<filename>%s</filename>",
-             xml_escape (grammar_file));
+              xml_escape (grammar_file));
 
   /* print grammar */
   print_grammar (out, level + 1);
 
   /* print grammar */
   print_grammar (out, level + 1);