I'd appreciate comments about this change. I'm very happy to get rid of this piece of code, with several calls to sprintf. I don't think it make the output less readable. Actually, I do think it is more readable.
commit 245143ceb03865bbcc2e9c52225198bec0913499 Author: Akim Demaille <[email protected]> Date: Sun Feb 3 14:26:37 2019 +0100 report: clean up its format The format is inconsistent. For instance most sections are indented (including "Terminals unused in grammar" for instance), but the sections "Terminals, with rules where they appear" and "Nonterminals, with rules where they appear" are not. Let's indent them. Also, these two sections try to wrap the output to avoid lines too long. Yet we don't do that in the rest of the file, for instance when listing the lookaheads of an item. For instance in the case of Bison's parse-gram.output we go from: Terminals, with rules where they appear "end of file" (0) 0 error (256) 28 88 "string" <char*> (258) 9 13 16 17 20 23 24 109 116 [...] Nonterminals, with rules where they appear $accept (58) on left: 0 input (59) on left: 1, on right: 0 prologue_declarations (60) on left: 2 3, on right: 1 3 prologue_declaration (61) on left: 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29, on right: 3 [...] to Terminals, with rules where they appear "end of file" (0) 0 error (256) 28 88 "string" <char*> (258) 9 13 16 17 20 23 24 109 116 [...] Nonterminals, with rules where they appear $accept (58) on left: 0 input (59) on left: 1 on right: 0 prologue_declarations (60) on left: 2 3 on right: 1 3 prologue_declaration (61) on left: 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 on right: 3 [...] * src/print.c (END_TEST): Remove. (print_terminal_symbols): Don't try to wrap the output. (print_nonterminal_symbols): Likewise. Make two different lines for occurrences on the left, and occurrence on the rhs of the rules. Indent by 4 and 8, not 3. * src/reduce.c (reduce_output): Indent by 4, not 3. * tests/conflicts.at, tests/existing.at, tests/reduce.at, * tests/regression.at, tests/report.at: Adjust. diff --git a/src/print.c b/src/print.c index 7e002c14..ab63a3eb 100644 --- a/src/print.c +++ b/src/print.c @@ -357,17 +357,6 @@ print_state (FILE *out, state *s) | Print information on the whole grammar. | `-----------------------------------------*/ -#define END_TEST(End) \ - do { \ - if (column + strlen (buffer) > (End)) \ - { \ - fprintf (out, "%s\n ", buffer); \ - column = 3; \ - buffer[0] = 0; \ - } \ - } while (0) - - static void print_terminal_symbols (FILE *out) { @@ -377,29 +366,20 @@ print_terminal_symbols (FILE *out) if (token_translations[i] != undeftoken->content->number) { const char *tag = symbols[token_translations[i]]->tag; - int column = strlen (tag); - char buffer[90]; - - buffer[0] = 0; - fputs (tag, out); - END_TEST (65); + fprintf (out, "%4s%s", "", tag); if (symbols[token_translations[i]]->content->type_name) - { - column += fprintf (out, " <%s>", - symbols[token_translations[i]]->content->type_name); - END_TEST (65); - } - sprintf (buffer, " (%d)", i); + fprintf (out, " <%s>", + symbols[token_translations[i]]->content->type_name); + fprintf (out, " (%d)", i); for (rule_number r = 0; r < nrules; r++) for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == token_translations[i]) { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); + fprintf (out, " %d", r); break; } - fprintf (out, "%s\n", buffer); + fputc ('\n', out); } fputs ("\n\n", out); } @@ -412,14 +392,13 @@ print_nonterminal_symbols (FILE *out) for (symbol_number i = ntokens; i < nsyms; i++) { const char *tag = symbols[i]->tag; - int column = strlen (tag); int left_count = 0, right_count = 0; for (rule_number r = 0; r < nrules; r++) { if (rules[r].lhs->number == i) left_count++; - for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; rhsp++) if (item_number_as_symbol_number (*rhsp) == i) { right_count++; @@ -427,49 +406,34 @@ print_nonterminal_symbols (FILE *out) } } - fputs (tag, out); + int column = 4 + strlen (tag); + fprintf (out, "%4s%s", "", tag); if (symbols[i]->content->type_name) column += fprintf (out, " <%s>", symbols[i]->content->type_name); - char buffer[90]; - buffer[0] = 0; - sprintf (buffer, " (%d)", i); - END_TEST (0); + fprintf (out, " (%d)\n", i); if (left_count > 0) { - END_TEST (65); - sprintf (buffer + strlen (buffer), _(" on left:")); - + fprintf (out, "%8s%s", "", _("on left:")); for (rule_number r = 0; r < nrules; r++) - { - if (rules[r].lhs->number == i) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); - } - } + if (rules[r].lhs->number == i) + fprintf (out, " %d", r); + fputc ('\n', out); } if (right_count > 0) { - if (left_count > 0) - sprintf (buffer + strlen (buffer), ","); - END_TEST (65); - sprintf (buffer + strlen (buffer), _(" on right:")); + fprintf (out, "%8s%s", "", _("on right:")); for (rule_number r = 0; r < nrules; r++) - { - item_number *rhsp; - for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) - if (item_number_as_symbol_number (*rhsp) == i) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); - break; - } - } + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; rhsp++) + if (item_number_as_symbol_number (*rhsp) == i) + { + fprintf (out, " %d", r); + break; + } + fputc ('\n', out); } - fprintf (out, "%s\n", buffer); } } diff --git a/src/reduce.c b/src/reduce.c index 4408e6a2..5ec63fde 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -320,7 +320,7 @@ reduce_output (FILE *out) { fprintf (out, "%s\n\n", _("Nonterminals useless in grammar")); for (int i = 0; i < nuseless_nonterminals; ++i) - fprintf (out, " %s\n", symbols[nsyms + i]->tag); + fprintf (out, " %s\n", symbols[nsyms + i]->tag); fputs ("\n\n", out); } @@ -332,7 +332,7 @@ reduce_output (FILE *out) if (!b) fprintf (out, "%s\n\n", _("Terminals unused in grammar")); b = true; - fprintf (out, " %s\n", symbols[i]->tag); + fprintf (out, " %s\n", symbols[i]->tag); } if (b) fputs ("\n\n", out); diff --git a/tests/conflicts.at b/tests/conflicts.at index 93f64952..edd86600 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -799,18 +799,19 @@ Grammar Terminals, with rules where they appear -$end (0) 0 -error (256) -NUM (258) 2 -OP (259) 1 + $end (0) 0 + error (256) + NUM (258) 2 + OP (259) 1 Nonterminals, with rules where they appear -$accept (5) - on left: 0 -exp (6) - on left: 1 2, on right: 0 1 + $accept (5) + on left: 0 + exp (6) + on left: 1 2 + on right: 0 1 State 0 @@ -902,18 +903,19 @@ AT_CHECK([cat input.output], [], Terminals, with rules where they appear -$end (0) 0 -error (256) -NUM (258) 2 -OP (259) 1 + $end (0) 0 + error (256) + NUM (258) 2 + OP (259) 1 Nonterminals, with rules where they appear -$accept (5) - on left: 0 -exp (6) - on left: 1 2, on right: 0 1 + $accept (5) + on left: 0 + exp (6) + on left: 1 2 + on right: 0 1 State 0 @@ -1095,21 +1097,24 @@ Grammar Terminals, with rules where they appear -$end (0) 0 -'0' (48) 3 4 -error (256) + $end (0) 0 + '0' (48) 3 4 + error (256) Nonterminals, with rules where they appear -$accept (4) - on left: 0 -exp (5) - on left: 1 2, on right: 0 -num (6) - on left: 3, on right: 1 -id (7) - on left: 4, on right: 2 + $accept (4) + on left: 0 + exp (5) + on left: 1 2 + on right: 0 + num (6) + on left: 3 + on right: 1 + id (7) + on left: 4 + on right: 2 State 0 @@ -1595,25 +1600,30 @@ Grammar Terminals, with rules where they appear -$end (0) 0 -'a' (97) 1 2 4 8 9 -error (256) + $end (0) 0 + 'a' (97) 1 2 4 8 9 + error (256) Nonterminals, with rules where they appear -$accept (4) - on left: 0 -start (5) - on left: 1, on right: 0 -resolved_conflict (6) - on left: 2 3, on right: 1 -unreachable1 (7) - on left: 4 5, on right: 2 -unreachable2 (8) - on left: 6 7, on right: 4 -reported_conflicts (9) - on left: 8 9 10, on right: 1 + $accept (4) + on left: 0 + start (5) + on left: 1 + on right: 0 + resolved_conflict (6) + on left: 2 3 + on right: 1 + unreachable1 (7) + on left: 4 5 + on right: 2 + unreachable2 (8) + on left: 6 7 + on right: 4 + reported_conflicts (9) + on left: 8 9 10 + on right: 1 State 0 diff --git a/tests/existing.at b/tests/existing.at index 16e75b0c..27bd0be3 100644 --- a/tests/existing.at +++ b/tests/existing.at @@ -475,7 +475,7 @@ dnl - 56 -> 326: reduce -> shift on '*', '/', and '%' dnl - 58 -> 327: reduce -> shift on '*', '/', and '%' dnl - 61 -> 328: reduce -> shift on '*', '/', and '%' [AT_COND_CASE([[LALR]], [], -[[@@ -712,7 +712,7 @@ +[[@@ -747,7 +747,7 @@ 156 | . '$' non_post_simp_exp NAME shift, and go to state 9 @@ -484,7 +484,7 @@ dnl - 61 -> 328: reduce -> shift on '*', '/', and '%' NAME [reduce using rule 152 (opt_variable)] '$' [reduce using rule 152 (opt_variable)] -@@ -5379,7 +5379,7 @@ +@@ -5414,7 +5414,7 @@ 156 | . '$' non_post_simp_exp NAME shift, and go to state 9 @@ -493,7 +493,7 @@ dnl - 61 -> 328: reduce -> shift on '*', '/', and '%' NAME [reduce using rule 152 (opt_variable)] '$' [reduce using rule 152 (opt_variable)] -@@ -5399,7 +5399,7 @@ +@@ -5434,7 +5434,7 @@ 156 | . '$' non_post_simp_exp NAME shift, and go to state 9 @@ -502,7 +502,7 @@ dnl - 61 -> 328: reduce -> shift on '*', '/', and '%' NAME [reduce using rule 152 (opt_variable)] '$' [reduce using rule 152 (opt_variable)] -@@ -6214,7 +6214,7 @@ +@@ -6249,7 +6249,7 @@ 156 | . '$' non_post_simp_exp NAME shift, and go to state 9 @@ -511,7 +511,7 @@ dnl - 61 -> 328: reduce -> shift on '*', '/', and '%' NAME [reduce using rule 152 (opt_variable)] '$' [reduce using rule 152 (opt_variable)] -@@ -11099,3 +11099,274 @@ +@@ -11134,3 +11134,274 @@ 45 statement: LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement . $default reduce using rule 45 (statement) @@ -2110,7 +2110,7 @@ dnl - 266 -> 424 dnl - 339 -> 426 dnl - 383 -> 427 [AT_COND_CASE([[LALR]], [], -[[@@ -1223,7 +1223,7 @@ +[[@@ -1249,7 +1249,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2119,7 +2119,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -1377,7 +1377,7 @@ +@@ -1403,7 +1403,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2128,7 +2128,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -1854,7 +1854,7 @@ +@@ -1880,7 +1880,7 @@ text go to state 162 place go to state 114 @@ -2137,7 +2137,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -2047,7 +2047,7 @@ +@@ -2073,7 +2073,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2146,7 +2146,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -2571,7 +2571,7 @@ +@@ -2597,7 +2597,7 @@ position_not_place go to state 99 expr_pair go to state 191 place go to state 101 @@ -2155,7 +2155,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -2732,7 +2732,7 @@ +@@ -2758,7 +2758,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2164,7 +2164,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -2875,7 +2875,7 @@ +@@ -2901,7 +2901,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2173,7 +2173,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -3018,7 +3018,7 @@ +@@ -3044,7 +3044,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2182,7 +2182,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -3256,7 +3256,7 @@ +@@ -3282,7 +3282,7 @@ State 102 @@ -2191,7 +2191,7 @@ dnl - 383 -> 427 147 | label . corner 153 label: label . '.' LABEL 180 corner: . DOT_N -@@ -3645,7 +3645,7 @@ +@@ -3671,7 +3671,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2200,7 +2200,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -3804,7 +3804,7 @@ +@@ -3830,7 +3830,7 @@ text_expr go to state 239 text go to state 113 place go to state 114 @@ -2209,7 +2209,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -4481,7 +4481,7 @@ +@@ -4507,7 +4507,7 @@ $default reduce using rule 89 (object_spec) place go to state 114 @@ -2218,7 +2218,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -4673,7 +4673,7 @@ +@@ -4699,7 +4699,7 @@ $default reduce using rule 91 (object_spec) place go to state 114 @@ -2227,7 +2227,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -4867,7 +4867,7 @@ +@@ -4893,7 +4893,7 @@ $default reduce using rule 95 (object_spec) place go to state 114 @@ -2236,7 +2236,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -5065,7 +5065,7 @@ +@@ -5091,7 +5091,7 @@ $default reduce using rule 93 (object_spec) place go to state 114 @@ -2245,7 +2245,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -5260,7 +5260,7 @@ +@@ -5286,7 +5286,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2254,7 +2254,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -5403,7 +5403,7 @@ +@@ -5429,7 +5429,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2263,7 +2263,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -5546,7 +5546,7 @@ +@@ -5572,7 +5572,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2272,7 +2272,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -5689,7 +5689,7 @@ +@@ -5715,7 +5715,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2281,7 +2281,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -6475,7 +6475,7 @@ +@@ -6501,7 +6501,7 @@ expr_pair go to state 280 place go to state 114 @@ -2290,7 +2290,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -6633,7 +6633,7 @@ +@@ -6659,7 +6659,7 @@ $default reduce using rule 105 (object_spec) place go to state 114 @@ -2299,7 +2299,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -6825,7 +6825,7 @@ +@@ -6851,7 +6851,7 @@ $default reduce using rule 107 (object_spec) place go to state 114 @@ -2308,7 +2308,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -7017,7 +7017,7 @@ +@@ -7043,7 +7043,7 @@ $default reduce using rule 114 (object_spec) place go to state 114 @@ -2317,7 +2317,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -7264,7 +7264,7 @@ +@@ -7290,7 +7290,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2326,7 +2326,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -7408,7 +7408,7 @@ +@@ -7434,7 +7434,7 @@ $default reduce using rule 109 (object_spec) place go to state 114 @@ -2335,7 +2335,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -7819,12 +7819,12 @@ +@@ -7845,12 +7845,12 @@ position_not_place go to state 296 expr_pair go to state 100 place go to state 297 @@ -2350,7 +2350,7 @@ dnl - 383 -> 427 State 165 -@@ -7987,7 +7987,7 @@ +@@ -8013,7 +8013,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2359,7 +2359,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8172,7 +8172,7 @@ +@@ -8198,7 +8198,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2368,7 +2368,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8333,7 +8333,7 @@ +@@ -8359,7 +8359,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2377,7 +2377,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8494,7 +8494,7 @@ +@@ -8520,7 +8520,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2386,7 +2386,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8655,7 +8655,7 @@ +@@ -8681,7 +8681,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2395,7 +2395,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8816,7 +8816,7 @@ +@@ -8842,7 +8842,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2404,7 +2404,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -8977,7 +8977,7 @@ +@@ -9003,7 +9003,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2413,7 +2413,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9138,7 +9138,7 @@ +@@ -9164,7 +9164,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2422,7 +2422,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9299,7 +9299,7 @@ +@@ -9325,7 +9325,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2431,7 +2431,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9460,7 +9460,7 @@ +@@ -9486,7 +9486,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2440,7 +2440,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9623,7 +9623,7 @@ +@@ -9649,7 +9649,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2449,7 +2449,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9784,7 +9784,7 @@ +@@ -9810,7 +9810,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2458,7 +2458,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -9921,7 +9921,7 @@ +@@ -9947,7 +9947,7 @@ $default reduce using rule 47 (any_expr) @@ -2467,7 +2467,7 @@ dnl - 383 -> 427 State 193 -@@ -10152,7 +10152,7 @@ +@@ -10178,7 +10178,7 @@ expr_pair go to state 317 place go to state 114 @@ -2476,7 +2476,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -10298,7 +10298,7 @@ +@@ -10324,7 +10324,7 @@ expr_pair go to state 318 place go to state 114 @@ -2485,7 +2485,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -10622,7 +10622,7 @@ +@@ -10648,7 +10648,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2494,7 +2494,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -10765,7 +10765,7 @@ +@@ -10791,7 +10791,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2503,7 +2503,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -10908,7 +10908,7 @@ +@@ -10934,7 +10934,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2512,7 +2512,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11051,7 +11051,7 @@ +@@ -11077,7 +11077,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2521,7 +2521,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11194,7 +11194,7 @@ +@@ -11220,7 +11220,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2530,7 +2530,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11337,7 +11337,7 @@ +@@ -11363,7 +11363,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2539,7 +2539,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11480,7 +11480,7 @@ +@@ -11506,7 +11506,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2548,7 +2548,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11637,7 +11637,7 @@ +@@ -11663,7 +11663,7 @@ position_not_place go to state 99 expr_pair go to state 100 place go to state 101 @@ -2557,7 +2557,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11780,7 +11780,7 @@ +@@ -11806,7 +11806,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2566,7 +2566,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -11923,7 +11923,7 @@ +@@ -11949,7 +11949,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2575,7 +2575,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12066,7 +12066,7 @@ +@@ -12092,7 +12092,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2584,7 +2584,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12209,7 +12209,7 @@ +@@ -12235,7 +12235,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2593,7 +2593,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12352,7 +12352,7 @@ +@@ -12378,7 +12378,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2602,7 +2602,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12495,7 +12495,7 @@ +@@ -12521,7 +12521,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2611,7 +2611,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12638,7 +12638,7 @@ +@@ -12664,7 +12664,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2620,7 +2620,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -12794,12 +12794,12 @@ +@@ -12820,12 +12820,12 @@ position_not_place go to state 99 expr_pair go to state 100 place go to state 101 @@ -2635,7 +2635,7 @@ dnl - 383 -> 427 State 238 -@@ -12937,7 +12937,7 @@ +@@ -12963,7 +12963,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2644,7 +2644,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -13160,7 +13160,7 @@ +@@ -13186,7 +13186,7 @@ text_expr go to state 342 text go to state 113 place go to state 114 @@ -2653,7 +2653,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -13319,7 +13319,7 @@ +@@ -13345,7 +13345,7 @@ text_expr go to state 344 text go to state 113 place go to state 114 @@ -2662,7 +2662,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -13502,7 +13502,7 @@ +@@ -13528,7 +13528,7 @@ text_expr go to state 348 text go to state 113 place go to state 114 @@ -2671,7 +2671,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -13661,7 +13661,7 @@ +@@ -13687,7 +13687,7 @@ text_expr go to state 350 text go to state 113 place go to state 114 @@ -2680,7 +2680,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -13804,7 +13804,7 @@ +@@ -13830,7 +13830,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2689,7 +2689,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -14747,7 +14747,7 @@ +@@ -14773,7 +14773,7 @@ position_not_place go to state 99 expr_pair go to state 191 place go to state 101 @@ -2698,7 +2698,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -15074,7 +15074,7 @@ +@@ -15100,7 +15100,7 @@ text go to state 113 expr_pair go to state 365 place go to state 114 @@ -2707,7 +2707,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -15693,12 +15693,12 @@ +@@ -15719,12 +15719,12 @@ position_not_place go to state 99 expr_pair go to state 100 place go to state 101 @@ -2722,7 +2722,7 @@ dnl - 383 -> 427 State 315 -@@ -16124,7 +16124,7 @@ +@@ -16150,7 +16150,7 @@ $default reduce using rule 239 (expr) @@ -2731,7 +2731,7 @@ dnl - 383 -> 427 Conflict between rule 239 and token OF resolved as shift ('<' < OF). Conflict between rule 239 and token BETWEEN resolved as shift ('<' < BETWEEN). -@@ -17234,7 +17234,7 @@ +@@ -17260,7 +17260,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2740,7 +2740,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -17416,7 +17416,7 @@ +@@ -17442,7 +17442,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2749,7 +2749,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -17577,7 +17577,7 @@ +@@ -17603,7 +17603,7 @@ text_expr go to state 112 text go to state 113 place go to state 114 @@ -2758,7 +2758,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -17772,12 +17772,12 @@ +@@ -17798,12 +17798,12 @@ position_not_place go to state 99 expr_pair go to state 100 place go to state 101 @@ -2773,7 +2773,7 @@ dnl - 383 -> 427 State 383 -@@ -18071,7 +18071,7 @@ +@@ -18097,7 +18097,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2782,7 +2782,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -18221,7 +18221,7 @@ +@@ -18247,7 +18247,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2791,7 +2791,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -18830,7 +18830,7 @@ +@@ -18856,7 +18856,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2800,7 +2800,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -18987,7 +18987,7 @@ +@@ -19013,7 +19013,7 @@ '!' shift, and go to state 94 place go to state 114 @@ -2809,7 +2809,7 @@ dnl - 383 -> 427 ordinal go to state 103 optional_ordinal_last go to state 104 nth_primitive go to state 105 -@@ -19089,3 +19089,440 @@ +@@ -19115,3 +19115,440 @@ 29 placeless_element: FOR VARIABLE '=' expr TO expr optional_by DO $@6 DELIMITED . $default reduce using rule 29 (placeless_element) diff --git a/tests/reduce.at b/tests/reduce.at index b9385bb3..8806c7c9 100644 --- a/tests/reduce.at +++ b/tests/reduce.at @@ -48,15 +48,15 @@ AT_BISON_CHECK([[input.y]]) AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, [[Terminals unused in grammar - useless1 - useless2 - useless3 - useless4 - useless5 - useless6 - useless7 - useless8 - useless9 + useless1 + useless2 + useless3 + useless4 + useless5 + useless6 + useless7 + useless8 + useless9 ]]) AT_CLEANUP @@ -96,9 +96,9 @@ input.y:13.1-8: warning: nonterminal useless in grammar: useless3 [-Wother] AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, [[Nonterminals useless in grammar - useless1 - useless2 - useless3 + useless1 + useless2 + useless3 Rules useless in grammar 2 useless1: %empty 3 useless2: %empty @@ -178,25 +178,25 @@ input.y:18.1-8: warning: nonterminal useless in grammar: useless9 [-Wother] AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, [[Nonterminals useless in grammar - useless1 - useless2 - useless3 - useless4 - useless5 - useless6 - useless7 - useless8 - useless9 + useless1 + useless2 + useless3 + useless4 + useless5 + useless6 + useless7 + useless8 + useless9 Terminals unused in grammar - '1' - '2' - '3' - '4' - '5' - '6' - '7' - '8' - '9' + '1' + '2' + '3' + '4' + '5' + '6' + '7' + '8' + '9' Rules useless in grammar 2 useless1: '1' 3 useless2: '2' @@ -269,7 +269,7 @@ input.y:18.1-6: warning: nonterminal useless in grammar: unused [-Wother] AT_CHECK([[sed -n '/^State 0/q;/^$/!p' input.output]], 0, [[Nonterminals useless in grammar - unused + unused Rules useless in grammar 4 unused: used2 Grammar @@ -278,17 +278,20 @@ Grammar 2 used1: used2 3 used2: %empty Terminals, with rules where they appear -$end (0) 0 -error (256) + $end (0) 0 + error (256) Nonterminals, with rules where they appear -$accept (3) - on left: 0 -start (4) - on left: 1, on right: 0 -used1 <ptr> (5) - on left: 2, on right: 1 -used2 <ptr> (6) - on left: 3, on right: 2 + $accept (3) + on left: 0 + start (4) + on left: 1 + on right: 0 + used1 <ptr> (5) + on left: 2 + on right: 1 + used2 <ptr> (6) + on left: 3 + on right: 2 ]]) # Make sure the generated parser is correct. @@ -351,10 +354,10 @@ not-reduced.y:11.6-57: warning: rule useless in grammar [-Wother] AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0, [[Nonterminals useless in grammar - not_reachable - non_productive + not_reachable + non_productive Terminals unused in grammar - useless_token + useless_token Rules useless in grammar 2 exp: non_productive 3 not_reachable: useful @@ -430,8 +433,8 @@ input.y:5.15-25: warning: rule useless in grammar [-Wother] AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, [[Nonterminals useless in grammar - underivable - indirection + underivable + indirection Rules useless in grammar 2 exp: underivable 3 underivable: indirection diff --git a/tests/regression.at b/tests/regression.at index b3173021..c897e708 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -247,23 +247,26 @@ AT_CHECK([cat input.output], [], Terminals, with rules where they appear -$end (0) 0 -'a' (97) 2 -'b' (98) 2 -'c' (99) 4 -error (256) + $end (0) 0 + 'a' (97) 2 + 'b' (98) 2 + 'c' (99) 4 + error (256) Nonterminals, with rules where they appear -$accept (6) - on left: 0 -expr (7) - on left: 2 4, on right: 0 -$@1 (8) - on left: 1, on right: 2 -$@2 (9) - on left: 3, on right: 4 + $accept (6) + on left: 0 + expr (7) + on left: 2 4 + on right: 0 + $@1 (8) + on left: 1 + on right: 2 + $@2 (9) + on left: 3 + on right: 4 State 0 @@ -554,26 +557,30 @@ AT_CHECK([cat input.output], 0, Terminals, with rules where they appear -$end (0) 0 -';' (59) 5 -'=' (61) 5 -error (256) -undef_id_tok (258) 5 -const_id_tok (259) 5 + $end (0) 0 + ';' (59) 5 + '=' (61) 5 + error (256) + undef_id_tok (258) 5 + const_id_tok (259) 5 Nonterminals, with rules where they appear -$accept (7) - on left: 0 -CONST_DEC_PART (8) - on left: 1, on right: 0 -CONST_DEC_LIST (9) - on left: 2 3, on right: 1 3 -CONST_DEC (10) - on left: 5, on right: 2 3 -$@1 (11) - on left: 4, on right: 5 + $accept (7) + on left: 0 + CONST_DEC_PART (8) + on left: 1 + on right: 0 + CONST_DEC_LIST (9) + on left: 2 3 + on right: 1 3 + CONST_DEC (10) + on left: 5 + on right: 2 3 + $@1 (11) + on left: 4 + on right: 5 State 0 diff --git a/tests/report.at b/tests/report.at index bf24bc4f..ebc80e18 100644 --- a/tests/report.at +++ b/tests/report.at @@ -88,34 +88,41 @@ AT_CHECK([cat input.output], [], Terminals, with rules where they appear -"end of file" (0) 0 -error (256) -":=" (258) 4 -"incr" (259) 8 -"identifier" <std::string> (260) 5 10 -"number" <int> (261) 11 -"(" (262) 9 -")" (263) 9 + "end of file" (0) 0 + error (256) + ":=" (258) 4 + "incr" (259) 8 + "identifier" <std::string> (260) 5 10 + "number" <int> (261) 11 + "(" (262) 9 + ")" (263) 9 Nonterminals, with rules where they appear -$accept (9) - on left: 0 -unit (10) - on left: 1, on right: 0 -assignments (11) - on left: 2 3, on right: 1 3 -assignment (12) - on left: 4, on right: 3 -id <std::string> (13) - on left: 5, on right: 4 -exp <int> (14) - on left: 8 9 10 11, on right: 1 4 8 9 -@1 <int> (15) - on left: 6, on right: 8 -@2 <int> (16) - on left: 7, on right: 8 + $accept (9) + on left: 0 + unit (10) + on left: 1 + on right: 0 + assignments (11) + on left: 2 3 + on right: 1 3 + assignment (12) + on left: 4 + on right: 3 + id <std::string> (13) + on left: 5 + on right: 4 + exp <int> (14) + on left: 8 9 10 11 + on right: 1 4 8 9 + @1 <int> (15) + on left: 6 + on right: 8 + @2 <int> (16) + on left: 7 + on right: 8 State 0 @@ -326,34 +333,41 @@ AT_CHECK([cat input.output], [], Terminals, with rules where they appear -"end of file" (0) 0 -error (256) -":=" (258) 4 -"incr" (259) 8 -"identifier" <std::string> (260) 5 10 -"number" <int> (261) 11 -"(" (262) 9 -")" (263) 9 + "end of file" (0) 0 + error (256) + ":=" (258) 4 + "incr" (259) 8 + "identifier" <std::string> (260) 5 10 + "number" <int> (261) 11 + "(" (262) 9 + ")" (263) 9 Nonterminals, with rules where they appear -$accept (9) - on left: 0 -unit (10) - on left: 1, on right: 0 -assignments (11) - on left: 2 3, on right: 1 3 -assignment (12) - on left: 4, on right: 3 -id <std::string> (13) - on left: 5, on right: 4 -exp <int> (14) - on left: 8 9 10 11, on right: 1 4 8 9 -@1 <int> (15) - on left: 6, on right: 8 -@2 <int> (16) - on left: 7, on right: 8 + $accept (9) + on left: 0 + unit (10) + on left: 1 + on right: 0 + assignments (11) + on left: 2 3 + on right: 1 3 + assignment (12) + on left: 4 + on right: 3 + id <std::string> (13) + on left: 5 + on right: 4 + exp <int> (14) + on left: 8 9 10 11 + on right: 1 4 8 9 + @1 <int> (15) + on left: 6 + on right: 8 + @2 <int> (16) + on left: 7 + on right: 8 State 0
