mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 04:43:03 +00:00
Don't put the pre-prologue in the header file. For the yacc.c code
file and the glr.c header and code files, move the pre-prologue before the token definitions. Add new %before-definitions and %after-definitions to declare code that will go in both the header file and code file. Discussed at <http://lists.gnu.org/archive/html/bison-patches/2005-12/msg00000.html>, <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00016.html>, and <http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00055.html>. * NEWS (2.3+): Describe these changes. * data/glr.c (b4_pre_prologue): Move from within to before... (b4_shared_declarations): ... this. Add new b4_before_definitions before b4_token_enums. Add new b4_after_definitions at the end. * data/glr.cc (b4_pre_prologue): Replace with... (b4_before_definitions): ... this in the header file. (b4_after_definitions): New near the end of the header file. * data/lalr1.cc (b4_pre_prologue): Move from the header file to the code file right before including the header file. (b4_before_definitions): New in the previous position of b4_pre_prologue in the header file. (b4_after_definitions): New near the end of the header file. * data/yacc.c: Clean up some m4 quoting especially in the header file. (b4_token_enums_defines): In the code file, move to right before YYSTYPE for consistency with the header file. (b4_before_definitions): New right before b4_token_enums_defines in both the header and code file. (b4_after_definitions): New right after YYLTYPE and yylloc in both the header and code file. * doc/bison.texinfo (Prologue): Show use of %before-definitions instead of prologues for %union dependencies. (Bison Declaration Summary): In %defines description, mention the effect of %before-definitions and %after-definitions on the header file. (Calc++ Parser): Forward declare driver in a %before-definitions rather than in the pre-prologue so that make check succeeds. (Bison Symbols): Add entries for %before-definitions and %after-definitions. * src/parse-gram.y (PERCENT_BEFORE_DEFINITIONS): New token for %before-definitions. (PERCENT_AFTER_DEFINITIONS): New token for %after-definitions. (declaration): Parse those declarations and append to b4_before_definitions and b4_after_definitions, respectively. * src/reader.c (before_definitions, after_definitions): New bools to track whether those declarations have been seen. (prologue_augment): Add to the post-prologue if %union, %before-definitions, or %after-definitions has been seen. * src/reader.h (before_definitions, after_definitions): New extern's. * src/scan-gram.l: Scan the new declarations. * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Place the second prologue block in a %before-definitions or a %after-definitions based on whether the %union is declared. * tests/regression.at (Early token definitions with --yacc, Early token definitions without --yacc): Move tests for token definitions into the post-prologue since token names are no longer defined in the pre-prologue.
This commit is contained in:
951
src/parse-gram.c
951
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
160
src/parse-gram.h
160
src/parse-gram.h
@@ -33,6 +33,7 @@
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
@@ -53,43 +54,45 @@
|
||||
PERCENT_PREC = 268,
|
||||
PERCENT_DPREC = 269,
|
||||
PERCENT_MERGE = 270,
|
||||
PERCENT_DEBUG = 271,
|
||||
PERCENT_DEFAULT_PREC = 272,
|
||||
PERCENT_DEFINE = 273,
|
||||
PERCENT_DEFINES = 274,
|
||||
PERCENT_ERROR_VERBOSE = 275,
|
||||
PERCENT_EXPECT = 276,
|
||||
PERCENT_EXPECT_RR = 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_REQUIRE = 290,
|
||||
PERCENT_SKELETON = 291,
|
||||
PERCENT_START = 292,
|
||||
PERCENT_TOKEN_TABLE = 293,
|
||||
PERCENT_VERBOSE = 294,
|
||||
PERCENT_YACC = 295,
|
||||
BRACED_CODE = 296,
|
||||
CHAR = 297,
|
||||
EPILOGUE = 298,
|
||||
EQUAL = 299,
|
||||
ID = 300,
|
||||
ID_COLON = 301,
|
||||
PERCENT_PERCENT = 302,
|
||||
PIPE = 303,
|
||||
PROLOGUE = 304,
|
||||
SEMICOLON = 305,
|
||||
TYPE = 306,
|
||||
PERCENT_UNION = 307
|
||||
PERCENT_AFTER_DEFINITIONS = 271,
|
||||
PERCENT_BEFORE_DEFINITIONS = 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
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
@@ -107,50 +110,52 @@
|
||||
#define PERCENT_PREC 268
|
||||
#define PERCENT_DPREC 269
|
||||
#define PERCENT_MERGE 270
|
||||
#define PERCENT_DEBUG 271
|
||||
#define PERCENT_DEFAULT_PREC 272
|
||||
#define PERCENT_DEFINE 273
|
||||
#define PERCENT_DEFINES 274
|
||||
#define PERCENT_ERROR_VERBOSE 275
|
||||
#define PERCENT_EXPECT 276
|
||||
#define PERCENT_EXPECT_RR 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_REQUIRE 290
|
||||
#define PERCENT_SKELETON 291
|
||||
#define PERCENT_START 292
|
||||
#define PERCENT_TOKEN_TABLE 293
|
||||
#define PERCENT_VERBOSE 294
|
||||
#define PERCENT_YACC 295
|
||||
#define BRACED_CODE 296
|
||||
#define CHAR 297
|
||||
#define EPILOGUE 298
|
||||
#define EQUAL 299
|
||||
#define ID 300
|
||||
#define ID_COLON 301
|
||||
#define PERCENT_PERCENT 302
|
||||
#define PIPE 303
|
||||
#define PROLOGUE 304
|
||||
#define SEMICOLON 305
|
||||
#define TYPE 306
|
||||
#define PERCENT_UNION 307
|
||||
#define PERCENT_AFTER_DEFINITIONS 271
|
||||
#define PERCENT_BEFORE_DEFINITIONS 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
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 97 "../../src/parse-gram.y"
|
||||
#line 97 "parse-gram.y"
|
||||
{
|
||||
symbol *symbol;
|
||||
symbol_list *list;
|
||||
@@ -160,8 +165,8 @@ typedef union YYSTYPE
|
||||
uniqstr uniqstr;
|
||||
unsigned char character;
|
||||
}
|
||||
/* Line 1529 of yacc.c. */
|
||||
#line 165 "../../src/parse-gram.h"
|
||||
/* Line 1544 of yacc.c. */
|
||||
#line 170 "parse-gram.h"
|
||||
YYSTYPE;
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
@@ -184,3 +189,4 @@ typedef struct YYLTYPE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,6 +130,10 @@ static int current_prec = 0;
|
||||
`----------------------*/
|
||||
|
||||
%token
|
||||
PERCENT_AFTER_DEFINITIONS
|
||||
"%after-definitions"
|
||||
PERCENT_BEFORE_DEFINITIONS
|
||||
"%before-definitions"
|
||||
PERCENT_DEBUG "%debug"
|
||||
PERCENT_DEFAULT_PREC "%default-prec"
|
||||
PERCENT_DEFINE "%define"
|
||||
@@ -212,6 +216,20 @@ declaration:
|
||||
grammar_declaration
|
||||
| PROLOGUE { prologue_augment (translate_code ($1, @1),
|
||||
@1); }
|
||||
| "%after-definitions" "{...}"
|
||||
{
|
||||
after_definitions = true;
|
||||
/* Remove the '{', and replace the '}' with '\n'. */
|
||||
$2[strlen ($2) - 1] = '\n';
|
||||
muscle_code_grow ("after_definitions", $2+1, @2);
|
||||
}
|
||||
| "%before-definitions" "{...}"
|
||||
{
|
||||
before_definitions = true;
|
||||
/* Remove the '{', and replace the '}' with '\n'. */
|
||||
$2[strlen ($2) - 1] = '\n';
|
||||
muscle_code_grow ("before_definitions", $2+1, @2);
|
||||
}
|
||||
| "%debug" { debug_flag = true; }
|
||||
| "%define" string_content
|
||||
{
|
||||
|
||||
15
src/reader.c
15
src/reader.c
@@ -44,8 +44,10 @@ static symbol_list *grammar = NULL;
|
||||
static bool start_flag = false;
|
||||
merger_list *merge_functions;
|
||||
|
||||
/* Was %union seen? */
|
||||
/* Was %union, %before-definitions, or %after-definitions seen? */
|
||||
bool typed = false;
|
||||
bool before_definitions = false;
|
||||
bool after_definitions = false;
|
||||
|
||||
/* Should rules have a default precedence? */
|
||||
bool default_prec = true;
|
||||
@@ -68,16 +70,17 @@ grammar_start_symbol_set (symbol *sym, location loc)
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------.
|
||||
| There are two prologues: one before %union, one after. Augment |
|
||||
| the current one. |
|
||||
`----------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------.
|
||||
| There are two prologues: one before the first %union, %before-definitions, |
|
||||
| or %after-definitions; and one after. Augment the current one. |
|
||||
`---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
prologue_augment (const char *prologue, location loc)
|
||||
{
|
||||
struct obstack *oout =
|
||||
!typed ? &pre_prologue_obstack : &post_prologue_obstack;
|
||||
!(typed || before_definitions || after_definitions)
|
||||
? &pre_prologue_obstack : &post_prologue_obstack;
|
||||
|
||||
obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
|
||||
/* FIXME: Protection of M4 characters missing here. See
|
||||
|
||||
@@ -58,8 +58,10 @@ void free_merger_functions (void);
|
||||
|
||||
extern merger_list *merge_functions;
|
||||
|
||||
/* Was %union seen? */
|
||||
/* Was %union, %before-definitions, or %after-definitions seen? */
|
||||
extern bool typed;
|
||||
extern bool before_definitions;
|
||||
extern bool after_definitions;
|
||||
|
||||
/* Should rules have a default precedence? */
|
||||
extern bool default_prec;
|
||||
|
||||
@@ -164,6 +164,8 @@ splice (\\[ \f\t\v]*\n)*
|
||||
`----------------------------*/
|
||||
<INITIAL>
|
||||
{
|
||||
"%after-definitions" return PERCENT_AFTER_DEFINITIONS;
|
||||
"%before-definitions" return PERCENT_BEFORE_DEFINITIONS;
|
||||
"%binary" return PERCENT_NONASSOC;
|
||||
"%debug" return PERCENT_DEBUG;
|
||||
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
|
||||
|
||||
Reference in New Issue
Block a user