mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 01:33:03 +00:00
gram.c: also print terminals in grammar_dump
* src/gram.c (grammar_dump): Print terminals likewise non terminals. * tests/sets.at (Reduced Grammar): Update test case to catch up the change and add a test case where prec and assoc are used.
This commit is contained in:
committed by
Akim Demaille
parent
af000bab11
commit
17d34c231b
15
src/gram.c
15
src/gram.c
@@ -259,12 +259,11 @@ grammar_dump (FILE *out, const char *title)
|
|||||||
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
|
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
|
||||||
ntokens, nvars, nsyms, nrules, nritems);
|
ntokens, nvars, nsyms, nrules, nritems);
|
||||||
|
|
||||||
|
fprintf (out, "Tokens\n------\n\n");
|
||||||
fprintf (out, "Variables\n---------\n\n");
|
|
||||||
{
|
{
|
||||||
fprintf (out, "Value Sprec Sassoc Tag\n");
|
fprintf (out, "Value Sprec Sassoc Tag\n");
|
||||||
|
|
||||||
for (symbol_number i = ntokens; i < nsyms; i++)
|
for (symbol_number i = 0; i < ntokens; i++)
|
||||||
fprintf (out, "%5d %5d %5d %s\n",
|
fprintf (out, "%5d %5d %5d %s\n",
|
||||||
i,
|
i,
|
||||||
symbols[i]->content->prec, symbols[i]->content->assoc,
|
symbols[i]->content->prec, symbols[i]->content->assoc,
|
||||||
@@ -272,6 +271,16 @@ grammar_dump (FILE *out, const char *title)
|
|||||||
fprintf (out, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf (out, "Non terminals\n-------------\n\n");
|
||||||
|
{
|
||||||
|
fprintf (out, "Value Tag\n");
|
||||||
|
|
||||||
|
for (symbol_number i = ntokens; i < nsyms; i++)
|
||||||
|
fprintf (out, "%5d %s\n",
|
||||||
|
i, symbols[i]->tag);
|
||||||
|
fprintf (out, "\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
fprintf (out, "Rules\n-----\n\n");
|
fprintf (out, "Rules\n-----\n\n");
|
||||||
{
|
{
|
||||||
fprintf (out,
|
fprintf (out,
|
||||||
|
|||||||
111
tests/sets.at
111
tests/sets.at
@@ -329,14 +329,27 @@ Reduced Grammar
|
|||||||
|
|
||||||
ntokens = 7, nvars = 4, nsyms = 11, nrules = 6, nritems = 17
|
ntokens = 7, nvars = 4, nsyms = 11, nrules = 6, nritems = 17
|
||||||
|
|
||||||
Variables
|
Tokens
|
||||||
---------
|
------
|
||||||
|
|
||||||
Value Sprec Sassoc Tag
|
Value Sprec Sassoc Tag
|
||||||
7 0 0 $accept
|
0 0 0 $end
|
||||||
8 0 0 expr
|
1 0 0 error
|
||||||
9 0 0 term
|
2 0 0 $undefined
|
||||||
10 0 0 fact
|
3 0 0 "+"
|
||||||
|
4 0 0 "*"
|
||||||
|
5 0 0 "useless"
|
||||||
|
6 0 0 "num"
|
||||||
|
|
||||||
|
|
||||||
|
Non terminals
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Value Tag
|
||||||
|
7 $accept
|
||||||
|
8 expr
|
||||||
|
9 term
|
||||||
|
10 fact
|
||||||
|
|
||||||
|
|
||||||
Rules
|
Rules
|
||||||
@@ -368,3 +381,89 @@ reduced input.y defines 7 terminals, 4 nonterminals, and 6 productions.
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
## ------------------------------------- ##
|
||||||
|
## Reduced Grammar with prec and assoc. ##
|
||||||
|
## ------------------------------------- ##
|
||||||
|
|
||||||
|
# Check information about the grammar, once reduced.
|
||||||
|
|
||||||
|
AT_SETUP([Reduced Grammar with prec and assoc])
|
||||||
|
|
||||||
|
AT_DATA([input.y],
|
||||||
|
[[%nonassoc '<' '>'
|
||||||
|
%left '+' '-'
|
||||||
|
%right '^' '='
|
||||||
|
%%
|
||||||
|
exp:
|
||||||
|
exp '<' exp
|
||||||
|
| exp '>' exp
|
||||||
|
| exp '+' exp
|
||||||
|
| exp '-' exp
|
||||||
|
| exp '^' exp
|
||||||
|
| exp '=' exp
|
||||||
|
| "exp"
|
||||||
|
;
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[--trace=grammar -o input.c input.y]], [], [],
|
||||||
|
[[Reduced Grammar
|
||||||
|
|
||||||
|
ntokens = 10, nvars = 2, nsyms = 12, nrules = 8, nritems = 29
|
||||||
|
|
||||||
|
Tokens
|
||||||
|
------
|
||||||
|
|
||||||
|
Value Sprec Sassoc Tag
|
||||||
|
0 0 0 $end
|
||||||
|
1 0 0 error
|
||||||
|
2 0 0 $undefined
|
||||||
|
3 1 3 '<'
|
||||||
|
4 1 3 '>'
|
||||||
|
5 2 2 '+'
|
||||||
|
6 2 2 '-'
|
||||||
|
7 3 1 '^'
|
||||||
|
8 3 1 '='
|
||||||
|
9 0 0 "exp"
|
||||||
|
|
||||||
|
|
||||||
|
Non terminals
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Value Tag
|
||||||
|
10 $accept
|
||||||
|
11 exp
|
||||||
|
|
||||||
|
|
||||||
|
Rules
|
||||||
|
-----
|
||||||
|
|
||||||
|
Num (Prec, Assoc, Useful, UselessChain) Lhs -> (Ritem Range) Rhs
|
||||||
|
0 ( 0, 0, t, f) 10 -> ( 0- 1) 11 0
|
||||||
|
1 ( 1, 3, t, f) 11 -> ( 3- 5) 11 3 11
|
||||||
|
2 ( 1, 3, t, f) 11 -> ( 7- 9) 11 4 11
|
||||||
|
3 ( 2, 2, t, f) 11 -> (11-13) 11 5 11
|
||||||
|
4 ( 2, 2, t, f) 11 -> (15-17) 11 6 11
|
||||||
|
5 ( 3, 1, t, f) 11 -> (19-21) 11 7 11
|
||||||
|
6 ( 3, 1, t, f) 11 -> (23-25) 11 8 11
|
||||||
|
7 ( 0, 0, t, t) 11 -> (27-27) 9
|
||||||
|
|
||||||
|
|
||||||
|
Rules interpreted
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
0 $accept: exp $end
|
||||||
|
1 exp: exp '<' exp
|
||||||
|
2 exp: exp '>' exp
|
||||||
|
3 exp: exp '+' exp
|
||||||
|
4 exp: exp '-' exp
|
||||||
|
5 exp: exp '^' exp
|
||||||
|
6 exp: exp '=' exp
|
||||||
|
7 exp: "exp"
|
||||||
|
|
||||||
|
|
||||||
|
reduced input.y defines 10 terminals, 2 nonterminals, and 8 productions.
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user