Hi, My assignment/disclaimer process with the FSF is completed. And I updated the patch based on feedbacks.
I change "Tokens" to "Terminals" because "Terminals" corresponding to "Non terminal". Thanks. commit 7430c63861a756aec22c9b8b21668f6e6f053076 Author: Yuichiro Kaneko <[email protected]> Date: Tue Oct 22 12:18:32 2019 +0900 gram.c: 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. diff --git a/src/gram.c b/src/gram.c index 5753f70f..e0448bae 100644 --- a/src/gram.c +++ b/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, nvars, nsyms, nrules, nritems); - - fprintf (out, "Variables\n---------\n\n"); + fprintf (out, "Terminals\n---------\n\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", i, 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, "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, diff --git a/tests/sets.at b/tests/sets.at index 5dbc50dc..7d40cea2 100644 --- a/tests/sets.at +++ b/tests/sets.at @@ -329,14 +329,27 @@ Reduced Grammar ntokens = 7, nvars = 4, nsyms = 11, nrules = 6, nritems = 17 -Variables +Terminals --------- Value Sprec Sassoc Tag - 7 0 0 $accept - 8 0 0 expr - 9 0 0 term - 10 0 0 fact + 0 0 0 $end + 1 0 0 error + 2 0 0 $undefined + 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 @@ -368,3 +381,89 @@ reduced input.y defines 7 terminals, 4 nonterminals, and 6 productions. ]]) 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 + +Terminals +--------- + +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 2019年10月26日(土) 9:32 kaneko y <[email protected]>: > Hi Akim, > > > (is this the right way to (first) name you?) > > Yes! > > > Eventually, if you are willing to contribute, you'll have to sign the > FSF's disclaimers. Will you agree? > > Yes, I may agree. Could you share me detail of the FSF's disclaimers? > Is https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html the > right guide which I should understand? > > Thanks. > > > > 2019年10月25日(金) 1:11 Akim Demaille <[email protected]>: > >> Hi Kaneko, >> >> (is this the right way to (first) name you?) >> >> > Le 23 oct. 2019 à 16:08, kaneko y <[email protected]> a écrit : >> > >> > I feel it's helpful to print Tokens in grammar_dump likewise Variables >> > in grammar_dump. >> >> Which is really an output for developers. Are you toying with Bison >> currently? >> >> > How do you think about it? >> >> Instead of having two paragraphs, I'd say that a single one with all the >> symbols suffices. But if we keep two paragraphs: >> - then eliminate precedence and associativity for nonterminals, AFAICT, >> it makes no sense >> - make sure to underline "Tokens" by the correct number of dashes >> - rename "Variables" as "non terminals", since that's really the name we >> use >> - write a test where prec and assis are actually used. >> >> >> Eventually, if you are willing to contribute, you'll have to sign the >> FSF's disclaimers. Will you agree? >> >> Cheers! > >
