From: Joel E. Denny Date: Wed, 30 Dec 2009 08:20:11 +0000 (-0500) Subject: POSIX: warn if %prec's token was not defined. X-Git-Tag: v2.7.90~729 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/8bb3a2e7dfd705ff7cb78fb12028557a92b4feaf?ds=sidebyside POSIX: warn if %prec's token was not defined. Reported by Florian Krohm at . * NEWS (2.4.2): Document. * src/reader.c (grammar_rule_check): Implement. (grammar_current_rule_prec_set): Add comments explaining that we here assume a %prec identifier is a token, but we still manage to support POSIX. * tests/input.at (%prec's token must be defined): New test group. (cherry picked from commit f1ceed07743630aa2aef7c77d8bde23c3794ee1b) --- diff --git a/ChangeLog b/ChangeLog index 773e8b51..699ede37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-12-30 Joel E. Denny + + POSIX: warn if %prec's token was not defined. + Reported by Florian Krohm at + . + * NEWS (2.4.2): Document. + * src/reader.c (grammar_rule_check): Implement. + (grammar_current_rule_prec_set): Add comments explaining that we + here assume a %prec identifier is a token, but we still manage + to support POSIX. + * tests/input.at (%prec's token must be defined): New test + group. + 2009-12-31 Joel E. Denny * HACKING (Release Procedure): Recommend a secure automake. diff --git a/NEWS b/NEWS index 09610cbf..57997905 100644 --- a/NEWS +++ b/NEWS @@ -232,6 +232,16 @@ Bison News * Changes in version 2.4.2 (????-??-??): +** `%prec IDENTIFIER' requires IDENTIFIER to be defined separately. + + POSIX specifies that an error be reported for any identifier that does + not appear on the LHS of a grammar rule and that is not defined by + %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this + error report for the case when an identifier appears only after a + %prec directive. It is now restored. However, for backward + compatibility with recent Bison releases, it is only a warning for + now. In Bison 2.5 and later, it will return to being an error. + ** Detection of GNU M4 1.4.6 or newer during configure is improved. ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS, diff --git a/src/reader.c b/src/reader.c index 8a292b8a..250e4f8b 100644 --- a/src/reader.c +++ b/src/reader.c @@ -320,6 +320,15 @@ grammar_rule_check (const symbol_list *r) warn_at (r->location, _("unset value: $$")); } } + + /* See comments in grammar_current_rule_prec_set for how POSIX + mandates this complaint. It's only for identifiers, so skip + it for char literals and strings, which are always tokens. */ + if (r->ruleprec + && r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"' + && !r->ruleprec->declared && !r->ruleprec->prec) + warn_at (r->location, _("token for %%prec is not defined: %s"), + r->ruleprec->tag); } @@ -396,6 +405,16 @@ grammar_midrule_action (void) void grammar_current_rule_prec_set (symbol *precsym, location loc) { + /* POSIX says that any identifier is a nonterminal if it does not + appear on the LHS of a grammar rule and is not defined by %token + or by one of the directives that assigns precedence to a token. We + ignore this here because the only kind of identifier that POSIX + allows to follow a %prec is a token and because assuming it's a + token now can produce more logical error messages. Nevertheless, + grammar_rule_check does obey what we believe is the real intent of + POSIX here: that an error be reported for any identifier that + appears after %prec but that is not defined separately as a + token. */ symbol_class_set (precsym, token_sym, loc, false); if (current_rule->ruleprec) complain_at (loc, _("only one %s allowed per rule"), "%prec"); diff --git a/tests/input.at b/tests/input.at index ab01cbe8..6f0d70c3 100644 --- a/tests/input.at +++ b/tests/input.at @@ -794,6 +794,26 @@ AT_BISON_CHECK([input.y], [1], [], AT_CLEANUP +## ------------------------------- ## +## %prec's token must be defined. ## +## ------------------------------- ## + +AT_SETUP([[%prec's token must be defined]]) + +# According to POSIX, a %prec token must be defined separately. + +AT_DATA([[input.y]], +[[%% +start: %prec PREC ; +]]) + +AT_BISON_CHECK([[input.y]], [[0]], [], +[[input.y:2.8-17: warning: token for %prec is not defined: PREC +]]) + +AT_CLEANUP + + ## -------------------------------- ## ## Reject unused %code qualifiers. ## ## -------------------------------- ##