Rename %before-definitions to %start-header and %after-definitions to

%end-header.  Don't use these declarations to separate pre-prologue
blocks from post-prologue blocks.  Add new order-independent
declarations %before-header and %after-header as alternatives to the
traditional Yacc pre-prologue and post-prologue blocks.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00110.html>.
* NEWS (2.3+): Update for these changes.
* data/glr.c (b4_before_definitions): Update to...
(b4_start_header): ... this.
(b4_after_definitions): Update to...
(b4_end_header): ... this.
* data/glr.cc: Likewise.
* data/lalr1.cc: Likewise.
* data/yacc.c: Likewise.
* doc/bison.texinfo (The prologue): Update names, and replace remaining
prologue blocks with %*-header declarations.
(Calc++ Parser): Likewise.
(Bison Declaration Summary): Update names.
(Bison Symbols): Update description.
* src/parse-gram.y (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
(declaration): Update token names and m4 macro names.
When parsing %end-header and %start-header, invoke translate_code
before muscle_code_grow, and no longer set global booleans to remember
whether these declarations have been seen.
Parse new %after-header and %before-header.
* src/reader.c (before_definitions, after_definitions): Remove.
(prologue_augment): Accept a new bool argument to specify whether to
augment the pre-prologue or post-prologue.
* src/reader.h (before_definitions, after_definitions): Remove these
extern's.
(prologue_augment): Add new bool argument.
* src/scan-gram.l (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
* tests/actions.at (Printers and Destructors): Update names.
This commit is contained in:
Joel E. Denny
2006-06-23 20:17:28 +00:00
parent 31b2b07ef7
commit 34f98f46ee
14 changed files with 737 additions and 617 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -54,45 +54,47 @@
PERCENT_PREC = 268,
PERCENT_DPREC = 269,
PERCENT_MERGE = 270,
PERCENT_AFTER_DEFINITIONS = 271,
PERCENT_BEFORE_DEFINITIONS = 272,
PERCENT_AFTER_HEADER = 271,
PERCENT_BEFORE_HEADER = 272,
PERCENT_DEBUG = 273,
PERCENT_DEFAULT_PREC = 274,
PERCENT_DEFINE = 275,
PERCENT_DEFINES = 276,
PERCENT_ERROR_VERBOSE = 277,
PERCENT_EXPECT = 278,
PERCENT_EXPECT_RR = 279,
PERCENT_FILE_PREFIX = 280,
PERCENT_GLR_PARSER = 281,
PERCENT_INITIAL_ACTION = 282,
PERCENT_LEX_PARAM = 283,
PERCENT_LOCATIONS = 284,
PERCENT_NAME_PREFIX = 285,
PERCENT_NO_DEFAULT_PREC = 286,
PERCENT_NO_LINES = 287,
PERCENT_NONDETERMINISTIC_PARSER = 288,
PERCENT_OUTPUT = 289,
PERCENT_PARSE_PARAM = 290,
PERCENT_PURE_PARSER = 291,
PERCENT_REQUIRE = 292,
PERCENT_SKELETON = 293,
PERCENT_START = 294,
PERCENT_TOKEN_TABLE = 295,
PERCENT_VERBOSE = 296,
PERCENT_YACC = 297,
BRACED_CODE = 298,
CHAR = 299,
EPILOGUE = 300,
EQUAL = 301,
ID = 302,
ID_COLON = 303,
PERCENT_PERCENT = 304,
PIPE = 305,
PROLOGUE = 306,
SEMICOLON = 307,
TYPE = 308,
PERCENT_UNION = 309
PERCENT_END_HEADER = 277,
PERCENT_ERROR_VERBOSE = 278,
PERCENT_EXPECT = 279,
PERCENT_EXPECT_RR = 280,
PERCENT_FILE_PREFIX = 281,
PERCENT_GLR_PARSER = 282,
PERCENT_INITIAL_ACTION = 283,
PERCENT_LEX_PARAM = 284,
PERCENT_LOCATIONS = 285,
PERCENT_NAME_PREFIX = 286,
PERCENT_NO_DEFAULT_PREC = 287,
PERCENT_NO_LINES = 288,
PERCENT_NONDETERMINISTIC_PARSER = 289,
PERCENT_OUTPUT = 290,
PERCENT_PARSE_PARAM = 291,
PERCENT_PURE_PARSER = 292,
PERCENT_REQUIRE = 293,
PERCENT_SKELETON = 294,
PERCENT_START = 295,
PERCENT_START_HEADER = 296,
PERCENT_TOKEN_TABLE = 297,
PERCENT_VERBOSE = 298,
PERCENT_YACC = 299,
BRACED_CODE = 300,
CHAR = 301,
EPILOGUE = 302,
EQUAL = 303,
ID = 304,
ID_COLON = 305,
PERCENT_PERCENT = 306,
PIPE = 307,
PROLOGUE = 308,
SEMICOLON = 309,
TYPE = 310,
PERCENT_UNION = 311
};
#endif
/* Tokens. */
@@ -110,45 +112,47 @@
#define PERCENT_PREC 268
#define PERCENT_DPREC 269
#define PERCENT_MERGE 270
#define PERCENT_AFTER_DEFINITIONS 271
#define PERCENT_BEFORE_DEFINITIONS 272
#define PERCENT_AFTER_HEADER 271
#define PERCENT_BEFORE_HEADER 272
#define PERCENT_DEBUG 273
#define PERCENT_DEFAULT_PREC 274
#define PERCENT_DEFINE 275
#define PERCENT_DEFINES 276
#define PERCENT_ERROR_VERBOSE 277
#define PERCENT_EXPECT 278
#define PERCENT_EXPECT_RR 279
#define PERCENT_FILE_PREFIX 280
#define PERCENT_GLR_PARSER 281
#define PERCENT_INITIAL_ACTION 282
#define PERCENT_LEX_PARAM 283
#define PERCENT_LOCATIONS 284
#define PERCENT_NAME_PREFIX 285
#define PERCENT_NO_DEFAULT_PREC 286
#define PERCENT_NO_LINES 287
#define PERCENT_NONDETERMINISTIC_PARSER 288
#define PERCENT_OUTPUT 289
#define PERCENT_PARSE_PARAM 290
#define PERCENT_PURE_PARSER 291
#define PERCENT_REQUIRE 292
#define PERCENT_SKELETON 293
#define PERCENT_START 294
#define PERCENT_TOKEN_TABLE 295
#define PERCENT_VERBOSE 296
#define PERCENT_YACC 297
#define BRACED_CODE 298
#define CHAR 299
#define EPILOGUE 300
#define EQUAL 301
#define ID 302
#define ID_COLON 303
#define PERCENT_PERCENT 304
#define PIPE 305
#define PROLOGUE 306
#define SEMICOLON 307
#define TYPE 308
#define PERCENT_UNION 309
#define PERCENT_END_HEADER 277
#define PERCENT_ERROR_VERBOSE 278
#define PERCENT_EXPECT 279
#define PERCENT_EXPECT_RR 280
#define PERCENT_FILE_PREFIX 281
#define PERCENT_GLR_PARSER 282
#define PERCENT_INITIAL_ACTION 283
#define PERCENT_LEX_PARAM 284
#define PERCENT_LOCATIONS 285
#define PERCENT_NAME_PREFIX 286
#define PERCENT_NO_DEFAULT_PREC 287
#define PERCENT_NO_LINES 288
#define PERCENT_NONDETERMINISTIC_PARSER 289
#define PERCENT_OUTPUT 290
#define PERCENT_PARSE_PARAM 291
#define PERCENT_PURE_PARSER 292
#define PERCENT_REQUIRE 293
#define PERCENT_SKELETON 294
#define PERCENT_START 295
#define PERCENT_START_HEADER 296
#define PERCENT_TOKEN_TABLE 297
#define PERCENT_VERBOSE 298
#define PERCENT_YACC 299
#define BRACED_CODE 300
#define CHAR 301
#define EPILOGUE 302
#define EQUAL 303
#define ID 304
#define ID_COLON 305
#define PERCENT_PERCENT 306
#define PIPE 307
#define PROLOGUE 308
#define SEMICOLON 309
#define TYPE 310
#define PERCENT_UNION 311
@@ -166,7 +170,7 @@ typedef union YYSTYPE
unsigned char character;
}
/* Line 1544 of yacc.c. */
#line 170 "parse-gram.h"
#line 174 "parse-gram.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1

View File

@@ -130,14 +130,13 @@ static int current_prec = 0;
`----------------------*/
%token
PERCENT_AFTER_DEFINITIONS
"%after-definitions"
PERCENT_BEFORE_DEFINITIONS
"%before-definitions"
PERCENT_AFTER_HEADER "%after-header"
PERCENT_BEFORE_HEADER "%before-header"
PERCENT_DEBUG "%debug"
PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define"
PERCENT_DEFINES "%defines"
PERCENT_END_HEADER "%end-header"
PERCENT_ERROR_VERBOSE "%error-verbose"
PERCENT_EXPECT "%expect"
PERCENT_EXPECT_RR "%expect-rr"
@@ -157,6 +156,7 @@ static int current_prec = 0;
PERCENT_REQUIRE "%require"
PERCENT_SKELETON "%skeleton"
PERCENT_START "%start"
PERCENT_START_HEADER "%start-header"
PERCENT_TOKEN_TABLE "%token-table"
PERCENT_VERBOSE "%verbose"
PERCENT_YACC "%yacc"
@@ -214,21 +214,21 @@ declarations:
declaration:
grammar_declaration
| PROLOGUE { prologue_augment (translate_code ($1, @1),
@1); }
| "%after-definitions" "{...}"
| PROLOGUE
{
after_definitions = true;
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("after_definitions", $2+1, @2);
prologue_augment (translate_code ($1, @1), @1, typed);
}
| "%before-definitions" "{...}"
| "%after-header" "{...}"
{
before_definitions = true;
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("before_definitions", $2+1, @2);
prologue_augment (translate_code ($2+1, @2), @2, true);
}
| "%before-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
prologue_augment (translate_code ($2+1, @2), @2, false);
}
| "%debug" { debug_flag = true; }
| "%define" string_content
@@ -238,6 +238,12 @@ declaration:
}
| "%define" string_content string_content { muscle_insert ($2, $3); }
| "%defines" { defines_flag = true; }
| "%end-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("end_header", translate_code ($2+1, @2), @2);
}
| "%error-verbose" { error_verbose = true; }
| "%expect" INT { expected_sr_conflicts = $2; }
| "%expect-rr" INT { expected_rr_conflicts = $2; }
@@ -261,6 +267,12 @@ declaration:
| "%pure-parser" { pure_parser = true; }
| "%require" string_content { version_check (&@2, $2); }
| "%skeleton" string_content { skeleton = $2; }
| "%start-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("start_header", translate_code ($2+1, @2), @2);
}
| "%token-table" { token_table_flag = true; }
| "%verbose" { report_flag = report_states; }
| "%yacc" { yacc_flag = true; }

View File

@@ -44,10 +44,8 @@ static symbol_list *grammar = NULL;
static bool start_flag = false;
merger_list *merge_functions;
/* Was %union, %before-definitions, or %after-definitions seen? */
/* Was %union seen? */
bool typed = false;
bool before_definitions = false;
bool after_definitions = false;
/* Should rules have a default precedence? */
bool default_prec = true;
@@ -70,17 +68,16 @@ grammar_start_symbol_set (symbol *sym, location loc)
}
/*---------------------------------------------------------------------------.
| There are two prologues: one before the first %union, %before-definitions, |
| or %after-definitions; and one after. Augment the current one. |
`---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------.
| There are two prologues: one before the first %union and one after. |
| Augment the one specified by POST. |
`---------------------------------------------------------------------*/
void
prologue_augment (const char *prologue, location loc)
prologue_augment (const char *prologue, location loc, bool post)
{
struct obstack *oout =
!(typed || before_definitions || after_definitions)
? &pre_prologue_obstack : &post_prologue_obstack;
!post ? &pre_prologue_obstack : &post_prologue_obstack;
obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
/* FIXME: Protection of M4 characters missing here. See

View File

@@ -43,7 +43,7 @@ char const *token_name (int type);
/* From reader.c. */
void grammar_start_symbol_set (symbol *sym, location loc);
void prologue_augment (const char *prologue, location loc);
void prologue_augment (const char *prologue, location loc, bool post);
void grammar_current_rule_begin (symbol *lhs, location loc);
void grammar_current_rule_end (location loc);
void grammar_midrule_action (void);
@@ -58,10 +58,8 @@ void free_merger_functions (void);
extern merger_list *merge_functions;
/* Was %union, %before-definitions, or %after-definitions seen? */
/* Was %union seen? */
extern bool typed;
extern bool before_definitions;
extern bool after_definitions;
/* Should rules have a default precedence? */
extern bool default_prec;

View File

@@ -164,8 +164,8 @@ splice (\\[ \f\t\v]*\n)*
`----------------------------*/
<INITIAL>
{
"%after-definitions" return PERCENT_AFTER_DEFINITIONS;
"%before-definitions" return PERCENT_BEFORE_DEFINITIONS;
"%after-header" return PERCENT_AFTER_HEADER;
"%before-header" return PERCENT_BEFORE_HEADER;
"%binary" return PERCENT_NONASSOC;
"%debug" return PERCENT_DEBUG;
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
@@ -173,6 +173,7 @@ splice (\\[ \f\t\v]*\n)*
"%defines" return PERCENT_DEFINES;
"%destructor" return PERCENT_DESTRUCTOR;
"%dprec" return PERCENT_DPREC;
"%end-header" return PERCENT_END_HEADER;
"%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
"%expect" return PERCENT_EXPECT;
"%expect"[-_]"rr" return PERCENT_EXPECT_RR;
@@ -199,6 +200,7 @@ splice (\\[ \f\t\v]*\n)*
"%right" return PERCENT_RIGHT;
"%skeleton" return PERCENT_SKELETON;
"%start" return PERCENT_START;
"%start-header" return PERCENT_START_HEADER;
"%term" return PERCENT_TOKEN;
"%token" return PERCENT_TOKEN;
"%token"[-_]"table" return PERCENT_TOKEN_TABLE;