mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* src/parse-gram.y: Define PERCENT_EXPECT_RR.
(declaration): Replace expected_conflicts with expected_sr_conflicts. Add %expect-rr rule. * src/scan-gram.l: Recognize %expect-rr. * src/conflicts.h (expected_sr_conflicts): Rename from expected_conflicts. (expected_rr_conflicts): Declare. * src/conflicts.c (expected_sr_conflicts): Rename from expected_conflicts. (expected_rr_conflicts): Define. (conflicts_print): Check r/r conflicts against expected_rr_conflicts for GLR parsers. Use expected_sr_conflicts in place of expected_conflicts. Warn if expected_rr_conflicts used in non-GLR parser. * doc/bison.texinfo: Add documentation for %expect-rr.
This commit is contained in:
22
ChangeLog
22
ChangeLog
@@ -1,3 +1,25 @@
|
||||
2004-03-25 Paul Hilfinger <hilfingr@tully.CS.Berkeley.EDU>
|
||||
|
||||
* src/parse-gram.y: Define PERCENT_EXPECT_RR.
|
||||
(declaration): Replace expected_conflicts with expected_sr_conflicts.
|
||||
Add %expect-rr rule.
|
||||
|
||||
* src/scan-gram.l: Recognize %expect-rr.
|
||||
|
||||
* src/conflicts.h (expected_sr_conflicts): Rename from
|
||||
expected_conflicts.
|
||||
(expected_rr_conflicts): Declare.
|
||||
|
||||
* src/conflicts.c (expected_sr_conflicts): Rename from
|
||||
expected_conflicts.
|
||||
(expected_rr_conflicts): Define.
|
||||
(conflicts_print): Check r/r conflicts against expected_rr_conflicts
|
||||
for GLR parsers.
|
||||
Use expected_sr_conflicts in place of expected_conflicts.
|
||||
Warn if expected_rr_conflicts used in non-GLR parser.
|
||||
|
||||
* doc/bison.texinfo: Add documentation for %expect-rr.
|
||||
|
||||
2004-03-08 Paul Eggert <eggert@gnu.org>
|
||||
|
||||
Add support for hex token numbers. Suggested by Odd Arild Olsen in
|
||||
|
||||
@@ -223,7 +223,7 @@ Bison Declarations
|
||||
* Union Decl:: Declaring the set of all semantic value types.
|
||||
* Type Decl:: Declaring the choice of type for a nonterminal symbol.
|
||||
* Destructor Decl:: Declaring how symbols are freed.
|
||||
* Expect Decl:: Suppressing warnings about shift/reduce conflicts.
|
||||
* Expect Decl:: Suppressing warnings about parsing conflicts.
|
||||
* Start Decl:: Specifying the start symbol.
|
||||
* Pure Decl:: Requesting a reentrant parser.
|
||||
* Decl Summary:: Table of all Bison declarations.
|
||||
@@ -3280,7 +3280,7 @@ Grammars}).
|
||||
* Union Decl:: Declaring the set of all semantic value types.
|
||||
* Type Decl:: Declaring the choice of type for a nonterminal symbol.
|
||||
* Destructor Decl:: Declaring how symbols are freed.
|
||||
* Expect Decl:: Suppressing warnings about shift/reduce conflicts.
|
||||
* Expect Decl:: Suppressing warnings about parsing conflicts.
|
||||
* Start Decl:: Specifying the start symbol.
|
||||
* Pure Decl:: Requesting a reentrant parser.
|
||||
* Decl Summary:: Table of all Bison declarations.
|
||||
@@ -3560,6 +3560,7 @@ typefull: string; // $$ = $1 applies, $1 is not destroyed.
|
||||
@cindex warnings, preventing
|
||||
@cindex conflicts, suppressing warnings of
|
||||
@findex %expect
|
||||
@findex %expect-rr
|
||||
|
||||
Bison normally warns if there are any conflicts in the grammar
|
||||
(@pxref{Shift/Reduce, ,Shift/Reduce Conflicts}), but most real grammars
|
||||
@@ -3580,6 +3581,18 @@ reduce/reduce conflicts. The usual warning is
|
||||
given if there are either more or fewer conflicts, or if there are any
|
||||
reduce/reduce conflicts.
|
||||
|
||||
For normal LALR(1) parsers, reduce/reduce conflicts are more serious,
|
||||
and should be eliminated entirely. Bison will always report
|
||||
reduce/reduce conflicts for these parsers. With GLR parsers, however,
|
||||
both shift/reduce and reduce/reduce are routine (otherwise, there
|
||||
would be no need to use GLR parsing). Therefore, it is also possible
|
||||
to specify an expected number of reduce/reduce conflicts in GLR
|
||||
parsers, using the declaration:
|
||||
|
||||
@example
|
||||
%expect-rr @var{n}
|
||||
@end example
|
||||
|
||||
In general, using @code{%expect} involves these steps:
|
||||
|
||||
@itemize @bullet
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
#include "symtab.h"
|
||||
|
||||
/* -1 stands for not specified. */
|
||||
int expected_conflicts = -1;
|
||||
int expected_sr_conflicts = -1;
|
||||
int expected_rr_conflicts = -1;
|
||||
static char *conflicts = NULL;
|
||||
struct obstack solved_conflicts_obstack;
|
||||
|
||||
@@ -464,6 +465,7 @@ conflicts_print (void)
|
||||
not set, and then we want 0 SR, or else it is specified, in which
|
||||
case we want equality. */
|
||||
bool src_ok = false;
|
||||
bool rrc_ok = false;
|
||||
|
||||
int src_total = 0;
|
||||
int rrc_total = 0;
|
||||
@@ -480,11 +482,20 @@ conflicts_print (void)
|
||||
}
|
||||
}
|
||||
|
||||
src_ok = src_total == (expected_conflicts == -1 ? 0 : expected_conflicts);
|
||||
if (! glr_parser && rrc_total > 0 && expected_rr_conflicts != -1)
|
||||
{
|
||||
warn (_("%expect-rr applies only to GLR parsers"));
|
||||
expected_rr_conflicts = -1;
|
||||
}
|
||||
|
||||
/* If there are no RR conflicts, and as many SR conflicts as
|
||||
src_ok =
|
||||
src_total == (expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts);
|
||||
rrc_ok =
|
||||
rrc_total == (expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts);
|
||||
|
||||
/* If there are as many RR conflicts and SR conflicts as
|
||||
expected, then there is nothing to report. */
|
||||
if (!rrc_total && src_ok)
|
||||
if (rrc_ok && src_ok)
|
||||
return;
|
||||
|
||||
/* Report the total number of conflicts on STDERR. */
|
||||
@@ -492,15 +503,18 @@ conflicts_print (void)
|
||||
fprintf (stderr, "%s: ", current_file);
|
||||
conflict_report (stderr, src_total, rrc_total);
|
||||
|
||||
if (expected_conflicts != -1)
|
||||
if (expected_sr_conflicts != -1 || expected_rr_conflicts != -1)
|
||||
{
|
||||
int sr = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts;
|
||||
int rr = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts;
|
||||
if (! src_ok)
|
||||
warn (ngettext ("expected %d shift/reduce conflict",
|
||||
"expected %d shift/reduce conflicts",
|
||||
expected_conflicts),
|
||||
expected_conflicts);
|
||||
if (rrc_total)
|
||||
warn (_("expected 0 reduce/reduce conflicts"));
|
||||
sr), sr);
|
||||
if (! rrc_ok)
|
||||
warn (ngettext ("expected %d reduce/reduce conflict",
|
||||
"expected %d reduce/reduce conflicts",
|
||||
rr), rr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,5 +29,6 @@ void conflicts_output (FILE *out);
|
||||
void conflicts_free (void);
|
||||
|
||||
/* Were there conflicts? */
|
||||
extern int expected_conflicts;
|
||||
extern int expected_sr_conflicts;
|
||||
extern int expected_rr_conflicts;
|
||||
#endif /* !CONFLICTS_H_ */
|
||||
|
||||
631
src/parse-gram.c
631
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
114
src/parse-gram.h
114
src/parse-gram.h
@@ -50,33 +50,34 @@
|
||||
PERCENT_DEFINES = 275,
|
||||
PERCENT_ERROR_VERBOSE = 276,
|
||||
PERCENT_EXPECT = 277,
|
||||
PERCENT_FILE_PREFIX = 278,
|
||||
PERCENT_GLR_PARSER = 279,
|
||||
PERCENT_INITIAL_ACTION = 280,
|
||||
PERCENT_LEX_PARAM = 281,
|
||||
PERCENT_LOCATIONS = 282,
|
||||
PERCENT_NAME_PREFIX = 283,
|
||||
PERCENT_NO_DEFAULT_PREC = 284,
|
||||
PERCENT_NO_LINES = 285,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 286,
|
||||
PERCENT_OUTPUT = 287,
|
||||
PERCENT_PARSE_PARAM = 288,
|
||||
PERCENT_PURE_PARSER = 289,
|
||||
PERCENT_SKELETON = 290,
|
||||
PERCENT_START = 291,
|
||||
PERCENT_TOKEN_TABLE = 292,
|
||||
PERCENT_VERBOSE = 293,
|
||||
PERCENT_YACC = 294,
|
||||
TYPE = 295,
|
||||
EQUAL = 296,
|
||||
SEMICOLON = 297,
|
||||
PIPE = 298,
|
||||
ID = 299,
|
||||
ID_COLON = 300,
|
||||
PERCENT_PERCENT = 301,
|
||||
PROLOGUE = 302,
|
||||
EPILOGUE = 303,
|
||||
BRACED_CODE = 304
|
||||
PERCENT_EXPECT_RR = 278,
|
||||
PERCENT_FILE_PREFIX = 279,
|
||||
PERCENT_GLR_PARSER = 280,
|
||||
PERCENT_INITIAL_ACTION = 281,
|
||||
PERCENT_LEX_PARAM = 282,
|
||||
PERCENT_LOCATIONS = 283,
|
||||
PERCENT_NAME_PREFIX = 284,
|
||||
PERCENT_NO_DEFAULT_PREC = 285,
|
||||
PERCENT_NO_LINES = 286,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 287,
|
||||
PERCENT_OUTPUT = 288,
|
||||
PERCENT_PARSE_PARAM = 289,
|
||||
PERCENT_PURE_PARSER = 290,
|
||||
PERCENT_SKELETON = 291,
|
||||
PERCENT_START = 292,
|
||||
PERCENT_TOKEN_TABLE = 293,
|
||||
PERCENT_VERBOSE = 294,
|
||||
PERCENT_YACC = 295,
|
||||
TYPE = 296,
|
||||
EQUAL = 297,
|
||||
SEMICOLON = 298,
|
||||
PIPE = 299,
|
||||
ID = 300,
|
||||
ID_COLON = 301,
|
||||
PERCENT_PERCENT = 302,
|
||||
PROLOGUE = 303,
|
||||
EPILOGUE = 304,
|
||||
BRACED_CODE = 305
|
||||
};
|
||||
#endif
|
||||
#define GRAM_EOF 0
|
||||
@@ -100,39 +101,40 @@
|
||||
#define PERCENT_DEFINES 275
|
||||
#define PERCENT_ERROR_VERBOSE 276
|
||||
#define PERCENT_EXPECT 277
|
||||
#define PERCENT_FILE_PREFIX 278
|
||||
#define PERCENT_GLR_PARSER 279
|
||||
#define PERCENT_INITIAL_ACTION 280
|
||||
#define PERCENT_LEX_PARAM 281
|
||||
#define PERCENT_LOCATIONS 282
|
||||
#define PERCENT_NAME_PREFIX 283
|
||||
#define PERCENT_NO_DEFAULT_PREC 284
|
||||
#define PERCENT_NO_LINES 285
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 286
|
||||
#define PERCENT_OUTPUT 287
|
||||
#define PERCENT_PARSE_PARAM 288
|
||||
#define PERCENT_PURE_PARSER 289
|
||||
#define PERCENT_SKELETON 290
|
||||
#define PERCENT_START 291
|
||||
#define PERCENT_TOKEN_TABLE 292
|
||||
#define PERCENT_VERBOSE 293
|
||||
#define PERCENT_YACC 294
|
||||
#define TYPE 295
|
||||
#define EQUAL 296
|
||||
#define SEMICOLON 297
|
||||
#define PIPE 298
|
||||
#define ID 299
|
||||
#define ID_COLON 300
|
||||
#define PERCENT_PERCENT 301
|
||||
#define PROLOGUE 302
|
||||
#define EPILOGUE 303
|
||||
#define BRACED_CODE 304
|
||||
#define PERCENT_EXPECT_RR 278
|
||||
#define PERCENT_FILE_PREFIX 279
|
||||
#define PERCENT_GLR_PARSER 280
|
||||
#define PERCENT_INITIAL_ACTION 281
|
||||
#define PERCENT_LEX_PARAM 282
|
||||
#define PERCENT_LOCATIONS 283
|
||||
#define PERCENT_NAME_PREFIX 284
|
||||
#define PERCENT_NO_DEFAULT_PREC 285
|
||||
#define PERCENT_NO_LINES 286
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 287
|
||||
#define PERCENT_OUTPUT 288
|
||||
#define PERCENT_PARSE_PARAM 289
|
||||
#define PERCENT_PURE_PARSER 290
|
||||
#define PERCENT_SKELETON 291
|
||||
#define PERCENT_START 292
|
||||
#define PERCENT_TOKEN_TABLE 293
|
||||
#define PERCENT_VERBOSE 294
|
||||
#define PERCENT_YACC 295
|
||||
#define TYPE 296
|
||||
#define EQUAL 297
|
||||
#define SEMICOLON 298
|
||||
#define PIPE 299
|
||||
#define ID 300
|
||||
#define ID_COLON 301
|
||||
#define PERCENT_PERCENT 302
|
||||
#define PROLOGUE 303
|
||||
#define EPILOGUE 304
|
||||
#define BRACED_CODE 305
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
|
||||
#line 80 "parse-gram.y"
|
||||
#line 80 "../../src/parse-gram.y"
|
||||
typedef union YYSTYPE {
|
||||
symbol *symbol;
|
||||
symbol_list *list;
|
||||
@@ -142,7 +144,7 @@ typedef union YYSTYPE {
|
||||
uniqstr uniqstr;
|
||||
} YYSTYPE;
|
||||
/* Line 1285 of yacc.c. */
|
||||
#line 146 "y.tab.h"
|
||||
#line 148 "y.tab.h"
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
|
||||
@@ -120,6 +120,7 @@ int current_prec = 0;
|
||||
PERCENT_DEFINES "%defines"
|
||||
PERCENT_ERROR_VERBOSE "%error-verbose"
|
||||
PERCENT_EXPECT "%expect"
|
||||
PERCENT_EXPECT_RR "%expect-rr"
|
||||
PERCENT_FILE_PREFIX "%file-prefix"
|
||||
PERCENT_GLR_PARSER "%glr-parser"
|
||||
PERCENT_INITIAL_ACTION "%initial-action {...}"
|
||||
@@ -189,7 +190,8 @@ declaration:
|
||||
| "%define" string_content string_content { muscle_insert ($2, $3); }
|
||||
| "%defines" { defines_flag = true; }
|
||||
| "%error-verbose" { error_verbose = true; }
|
||||
| "%expect" INT { expected_conflicts = $2; }
|
||||
| "%expect" INT { expected_sr_conflicts = $2; }
|
||||
| "%expect-rr" INT { expected_rr_conflicts = $2; }
|
||||
| "%file-prefix" "=" string_content { spec_file_prefix = $3; }
|
||||
| "%glr-parser"
|
||||
{
|
||||
|
||||
@@ -190,6 +190,7 @@ splice (\\[ \f\t\v]*\n)*
|
||||
"%dprec" return PERCENT_DPREC;
|
||||
"%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
|
||||
"%expect" return PERCENT_EXPECT;
|
||||
"%expect"[-_]"rr" return PERCENT_EXPECT_RR;
|
||||
"%file-prefix" return PERCENT_FILE_PREFIX;
|
||||
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
|
||||
"%initial-action" token_type = PERCENT_INITIAL_ACTION; BEGIN SC_PRE_CODE;
|
||||
|
||||
Reference in New Issue
Block a user