mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 04:43:03 +00:00
When reducing initial empty rules, Bison parser read an initial
location that is not defined. This results in garbage, and that affects Bison's own parser. Therefore we need (i) to extend Bison to support a means to initialize this location, and (ii) to use this CVS Bison to fix CVS Bison's parser. * src/reader.h, reader.c (epilogue_augment): Remove, replace with... * src/muscle_tab.h, src/muscle_tab.c (muscle_code_grow): this. * src/parse-gram.y: Adjust. (%initial-action): New. (%error-verbose): Since we require CVS Bison, there is no reason not to use it. * src/scan-gram.l: Adjust. * src/Makefile.am (YACC): New, to make sure we use our own parser. * data/yacc.c (yyparse): Use b4_initial_action.
This commit is contained in:
@@ -28,6 +28,10 @@ INCLUDES = -I$(top_builddir) \
|
||||
|
||||
LDADD = ../lib/libbison.a $(LIBINTL)
|
||||
|
||||
# Use our own Bison to build the parser. Of course, you ought to
|
||||
# keep a sane version of Bison nearby...
|
||||
YACC = ../tests/bison -y
|
||||
|
||||
bin_PROGRAMS = bison
|
||||
bin_SCRIPTS = $(YACC_SCRIPT)
|
||||
EXTRA_SCRIPTS = yacc
|
||||
|
||||
@@ -154,6 +154,26 @@ muscle_grow (const char *key, const char *val, const char *separator)
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
| Append VALUE to the current value of KEY, using muscle_grow. But |
|
||||
| in addition, issue a synchronization line for the location LOC. |
|
||||
`------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
muscle_code_grow (const char *key, const char *val, location loc)
|
||||
{
|
||||
char *extension = NULL;
|
||||
obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", loc.start.line);
|
||||
MUSCLE_OBSTACK_SGROW (&muscle_obstack,
|
||||
quotearg_style (c_quoting_style, loc.start.file));
|
||||
obstack_sgrow (&muscle_obstack, "]])[\n");
|
||||
obstack_sgrow (&muscle_obstack, val);
|
||||
obstack_1grow (&muscle_obstack, 0);
|
||||
extension = obstack_finish (&muscle_obstack);
|
||||
muscle_grow (key, extension, "");
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| MUSCLE is an M4 list of pairs. Create or extend it with the pair |
|
||||
| (A1, A2). Note that because the muscle values are output *double* |
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef MUSCLE_TAB_H_
|
||||
# define MUSCLE_TAB_H_
|
||||
|
||||
# include "location.h"
|
||||
|
||||
void muscle_init (void);
|
||||
void muscle_insert (const char *key, char *value);
|
||||
char *muscle_find (const char *key);
|
||||
@@ -86,6 +88,13 @@ extern struct obstack muscle_obstack;
|
||||
|
||||
void muscle_grow (const char *key, const char *value, const char *separator);
|
||||
|
||||
|
||||
/* Append VALUE to the current value of KEY, using muscle_grow. But
|
||||
in addition, issue a synchronization line for the location LOC. */
|
||||
|
||||
void muscle_code_grow (const char *key, const char *value, location loc);
|
||||
|
||||
|
||||
/* MUSCLE is an M4 list of pairs. Create or extend it with the pair
|
||||
(A1, A2). Note that because the muscle values are output *double*
|
||||
quoted, one needs to strip the first level of quotes to reach the
|
||||
|
||||
664
src/parse-gram.c
664
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
102
src/parse-gram.h
102
src/parse-gram.h
@@ -1,4 +1,4 @@
|
||||
/* A Bison parser, made by GNU Bison 1.875b. */
|
||||
/* A Bison parser, made by GNU Bison 1.875c. */
|
||||
|
||||
/* Skeleton parser for Yacc-like parsing with Bison,
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
@@ -51,29 +51,30 @@
|
||||
PERCENT_EXPECT = 276,
|
||||
PERCENT_FILE_PREFIX = 277,
|
||||
PERCENT_GLR_PARSER = 278,
|
||||
PERCENT_LEX_PARAM = 279,
|
||||
PERCENT_LOCATIONS = 280,
|
||||
PERCENT_NAME_PREFIX = 281,
|
||||
PERCENT_NO_LINES = 282,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 283,
|
||||
PERCENT_OUTPUT = 284,
|
||||
PERCENT_PARSE_PARAM = 285,
|
||||
PERCENT_PURE_PARSER = 286,
|
||||
PERCENT_SKELETON = 287,
|
||||
PERCENT_START = 288,
|
||||
PERCENT_TOKEN_TABLE = 289,
|
||||
PERCENT_VERBOSE = 290,
|
||||
PERCENT_YACC = 291,
|
||||
TYPE = 292,
|
||||
EQUAL = 293,
|
||||
SEMICOLON = 294,
|
||||
PIPE = 295,
|
||||
ID = 296,
|
||||
ID_COLON = 297,
|
||||
PERCENT_PERCENT = 298,
|
||||
PROLOGUE = 299,
|
||||
EPILOGUE = 300,
|
||||
BRACED_CODE = 301
|
||||
PERCENT_INITIAL_ACTION = 279,
|
||||
PERCENT_LEX_PARAM = 280,
|
||||
PERCENT_LOCATIONS = 281,
|
||||
PERCENT_NAME_PREFIX = 282,
|
||||
PERCENT_NO_LINES = 283,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 284,
|
||||
PERCENT_OUTPUT = 285,
|
||||
PERCENT_PARSE_PARAM = 286,
|
||||
PERCENT_PURE_PARSER = 287,
|
||||
PERCENT_SKELETON = 288,
|
||||
PERCENT_START = 289,
|
||||
PERCENT_TOKEN_TABLE = 290,
|
||||
PERCENT_VERBOSE = 291,
|
||||
PERCENT_YACC = 292,
|
||||
TYPE = 293,
|
||||
EQUAL = 294,
|
||||
SEMICOLON = 295,
|
||||
PIPE = 296,
|
||||
ID = 297,
|
||||
ID_COLON = 298,
|
||||
PERCENT_PERCENT = 299,
|
||||
PROLOGUE = 300,
|
||||
EPILOGUE = 301,
|
||||
BRACED_CODE = 302
|
||||
};
|
||||
#endif
|
||||
#define GRAM_EOF 0
|
||||
@@ -98,35 +99,36 @@
|
||||
#define PERCENT_EXPECT 276
|
||||
#define PERCENT_FILE_PREFIX 277
|
||||
#define PERCENT_GLR_PARSER 278
|
||||
#define PERCENT_LEX_PARAM 279
|
||||
#define PERCENT_LOCATIONS 280
|
||||
#define PERCENT_NAME_PREFIX 281
|
||||
#define PERCENT_NO_LINES 282
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 283
|
||||
#define PERCENT_OUTPUT 284
|
||||
#define PERCENT_PARSE_PARAM 285
|
||||
#define PERCENT_PURE_PARSER 286
|
||||
#define PERCENT_SKELETON 287
|
||||
#define PERCENT_START 288
|
||||
#define PERCENT_TOKEN_TABLE 289
|
||||
#define PERCENT_VERBOSE 290
|
||||
#define PERCENT_YACC 291
|
||||
#define TYPE 292
|
||||
#define EQUAL 293
|
||||
#define SEMICOLON 294
|
||||
#define PIPE 295
|
||||
#define ID 296
|
||||
#define ID_COLON 297
|
||||
#define PERCENT_PERCENT 298
|
||||
#define PROLOGUE 299
|
||||
#define EPILOGUE 300
|
||||
#define BRACED_CODE 301
|
||||
#define PERCENT_INITIAL_ACTION 279
|
||||
#define PERCENT_LEX_PARAM 280
|
||||
#define PERCENT_LOCATIONS 281
|
||||
#define PERCENT_NAME_PREFIX 282
|
||||
#define PERCENT_NO_LINES 283
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 284
|
||||
#define PERCENT_OUTPUT 285
|
||||
#define PERCENT_PARSE_PARAM 286
|
||||
#define PERCENT_PURE_PARSER 287
|
||||
#define PERCENT_SKELETON 288
|
||||
#define PERCENT_START 289
|
||||
#define PERCENT_TOKEN_TABLE 290
|
||||
#define PERCENT_VERBOSE 291
|
||||
#define PERCENT_YACC 292
|
||||
#define TYPE 293
|
||||
#define EQUAL 294
|
||||
#define SEMICOLON 295
|
||||
#define PIPE 296
|
||||
#define ID 297
|
||||
#define ID_COLON 298
|
||||
#define PERCENT_PERCENT 299
|
||||
#define PROLOGUE 300
|
||||
#define EPILOGUE 301
|
||||
#define BRACED_CODE 302
|
||||
|
||||
|
||||
|
||||
|
||||
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
|
||||
#line 75 "parse-gram.y"
|
||||
#line 80 "parse-gram.y"
|
||||
typedef union YYSTYPE {
|
||||
symbol *symbol;
|
||||
symbol_list *list;
|
||||
@@ -135,8 +137,8 @@ typedef union YYSTYPE {
|
||||
assoc assoc;
|
||||
uniqstr uniqstr;
|
||||
} YYSTYPE;
|
||||
/* Line 1268 of yacc.c. */
|
||||
#line 140 "y.tab.h"
|
||||
/* Line 1285 of yacc.c. */
|
||||
#line 142 "y.tab.h"
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
%defines
|
||||
%locations
|
||||
%pure-parser
|
||||
// %error-verbose
|
||||
%error-verbose
|
||||
%defines
|
||||
%name-prefix="gram_"
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#include "reader.h"
|
||||
#include "symlist.h"
|
||||
|
||||
/* Produce verbose syntax errors. */
|
||||
#define YYERROR_VERBOSE 1
|
||||
|
||||
#define YYLLOC_DEFAULT(Current, Rhs, N) (Current) = lloc_default (Rhs, N)
|
||||
static YYLTYPE lloc_default (YYLTYPE const *, int);
|
||||
|
||||
@@ -69,6 +66,14 @@ assoc current_assoc;
|
||||
int current_prec = 0;
|
||||
%}
|
||||
|
||||
%initial-action
|
||||
{
|
||||
/* Bison's grammar can initial empty locations, hence a default
|
||||
location is needed. */
|
||||
@$.start.file = @$.end.file = current_file;
|
||||
@$.start.line = @$.end.line = 1;
|
||||
@$.start.column = @$.end.column = 0;
|
||||
}
|
||||
|
||||
/* Only NUMBERS have a value. */
|
||||
%union
|
||||
@@ -109,26 +114,28 @@ int current_prec = 0;
|
||||
`----------------------*/
|
||||
|
||||
%token
|
||||
PERCENT_DEBUG "%debug"
|
||||
PERCENT_DEFINE "%define"
|
||||
PERCENT_DEFINES "%defines"
|
||||
PERCENT_ERROR_VERBOSE "%error-verbose"
|
||||
PERCENT_EXPECT "%expect"
|
||||
PERCENT_FILE_PREFIX "%file-prefix"
|
||||
PERCENT_GLR_PARSER "%glr-parser"
|
||||
PERCENT_LEX_PARAM "%lex-param {...}"
|
||||
PERCENT_LOCATIONS "%locations"
|
||||
PERCENT_NAME_PREFIX "%name-prefix"
|
||||
PERCENT_NO_LINES "%no-lines"
|
||||
PERCENT_NONDETERMINISTIC_PARSER "%nondeterministic-parser"
|
||||
PERCENT_OUTPUT "%output"
|
||||
PERCENT_PARSE_PARAM "%parse-param {...}"
|
||||
PERCENT_PURE_PARSER "%pure-parser"
|
||||
PERCENT_SKELETON "%skeleton"
|
||||
PERCENT_START "%start"
|
||||
PERCENT_TOKEN_TABLE "%token-table"
|
||||
PERCENT_VERBOSE "%verbose"
|
||||
PERCENT_YACC "%yacc"
|
||||
PERCENT_DEBUG "%debug"
|
||||
PERCENT_DEFINE "%define"
|
||||
PERCENT_DEFINES "%defines"
|
||||
PERCENT_ERROR_VERBOSE "%error-verbose"
|
||||
PERCENT_EXPECT "%expect"
|
||||
PERCENT_FILE_PREFIX "%file-prefix"
|
||||
PERCENT_GLR_PARSER "%glr-parser"
|
||||
PERCENT_INITIAL_ACTION "%initial-action {...}"
|
||||
PERCENT_LEX_PARAM "%lex-param {...}"
|
||||
PERCENT_LOCATIONS "%locations"
|
||||
PERCENT_NAME_PREFIX "%name-prefix"
|
||||
PERCENT_NO_LINES "%no-lines"
|
||||
PERCENT_NONDETERMINISTIC_PARSER
|
||||
"%nondeterministic-parser"
|
||||
PERCENT_OUTPUT "%output"
|
||||
PERCENT_PARSE_PARAM "%parse-param {...}"
|
||||
PERCENT_PURE_PARSER "%pure-parser"
|
||||
PERCENT_SKELETON "%skeleton"
|
||||
PERCENT_START "%start"
|
||||
PERCENT_TOKEN_TABLE "%token-table"
|
||||
PERCENT_VERBOSE "%verbose"
|
||||
PERCENT_YACC "%yacc"
|
||||
;
|
||||
|
||||
%token TYPE "type"
|
||||
@@ -145,6 +152,7 @@ int current_prec = 0;
|
||||
|
||||
%type <chars> STRING string_content
|
||||
"%destructor {...}"
|
||||
"%initial-action {...}"
|
||||
"%lex-param {...}"
|
||||
"%parse-param {...}"
|
||||
"%printer {...}"
|
||||
@@ -181,21 +189,28 @@ declaration:
|
||||
| "%error-verbose" { error_verbose = true; }
|
||||
| "%expect" INT { expected_conflicts = $2; }
|
||||
| "%file-prefix" "=" string_content { spec_file_prefix = $3; }
|
||||
| "%glr-parser" { nondeterministic_parser = true;
|
||||
glr_parser = true; }
|
||||
| "%glr-parser"
|
||||
{
|
||||
nondeterministic_parser = true;
|
||||
glr_parser = true;
|
||||
}
|
||||
| "%initial-action {...}"
|
||||
{
|
||||
muscle_code_grow ("initial_action", $1, @1);
|
||||
}
|
||||
| "%lex-param {...}" { add_param ("lex_param", $1, @1); }
|
||||
| "%locations" { locations_flag = true; }
|
||||
| "%name-prefix" "=" string_content { spec_name_prefix = $3; }
|
||||
| "%no-lines" { no_lines_flag = true; }
|
||||
| "%nondeterministic-parser" { nondeterministic_parser = true; }
|
||||
| "%output" "=" string_content { spec_outfile = $3; }
|
||||
| "%parse-param {...}" { add_param ("parse_param", $1, @1); }
|
||||
| "%parse-param {...}" { add_param ("parse_param", $1, @1); }
|
||||
| "%pure-parser" { pure_parser = true; }
|
||||
| "%skeleton" string_content { skeleton = $2; }
|
||||
| "%token-table" { token_table_flag = true; }
|
||||
| "%verbose" { report_flag = report_states; }
|
||||
| "%yacc" { yacc_flag = true; }
|
||||
| ";"
|
||||
| /*FIXME: Err? What is this horror doing here? */ ";"
|
||||
;
|
||||
|
||||
grammar_declaration:
|
||||
@@ -400,7 +415,7 @@ epilogue.opt:
|
||||
/* Nothing. */
|
||||
| "%%" EPILOGUE
|
||||
{
|
||||
epilogue_augment ($2, @2);
|
||||
muscle_code_grow ("epilogue", $2, @2);
|
||||
scanner_last_string_free ();
|
||||
}
|
||||
;
|
||||
|
||||
23
src/reader.c
23
src/reader.c
@@ -78,29 +78,6 @@ prologue_augment (const char *prologue, location loc)
|
||||
obstack_sgrow (oout, prologue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------.
|
||||
| Handle the epilogue. |
|
||||
`----------------------*/
|
||||
|
||||
void
|
||||
epilogue_augment (const char *epilogue, location loc)
|
||||
{
|
||||
char *extension = NULL;
|
||||
obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", loc.start.line);
|
||||
MUSCLE_OBSTACK_SGROW (&muscle_obstack,
|
||||
quotearg_style (c_quoting_style, loc.start.file));
|
||||
obstack_sgrow (&muscle_obstack, "]])[\n");
|
||||
obstack_sgrow (&muscle_obstack, epilogue);
|
||||
obstack_1grow (&muscle_obstack, 0);
|
||||
extension = obstack_finish (&muscle_obstack);
|
||||
muscle_grow ("epilogue", extension, "");
|
||||
obstack_free (&muscle_obstack, extension);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
|
||||
@@ -56,7 +56,6 @@ char const *token_name (int);
|
||||
/* From reader.c. */
|
||||
void grammar_start_symbol_set (symbol *sym, location loc);
|
||||
void prologue_augment (const char *prologue, location loc);
|
||||
void epilogue_augment (const char *epilogue, location loc);
|
||||
void grammar_symbol_append (symbol *sym, location loc);
|
||||
void grammar_rule_begin (symbol *lhs, location loc);
|
||||
void grammar_rule_end (location loc);
|
||||
|
||||
@@ -190,6 +190,7 @@ splice (\\[ \f\t\v]*\n)*
|
||||
"%expect" return PERCENT_EXPECT;
|
||||
"%file-prefix" return PERCENT_FILE_PREFIX;
|
||||
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
|
||||
"%initial-action" token_type = PERCENT_INITIAL_ACTION; BEGIN SC_PRE_CODE;
|
||||
"%glr-parser" return PERCENT_GLR_PARSER;
|
||||
"%left" return PERCENT_LEFT;
|
||||
"%lex-param" token_type = PERCENT_LEX_PARAM; BEGIN SC_PRE_CODE;
|
||||
@@ -649,8 +650,8 @@ splice (\\[ \f\t\v]*\n)*
|
||||
|
||||
%%
|
||||
|
||||
/* Keeps track of the maximum number of semantic values to the left of
|
||||
a handle (those referenced by $0, $-1, etc.) are required by the
|
||||
/* Keeps track of the maximum number of semantic values to the left of
|
||||
a handle (those referenced by $0, $-1, etc.) are required by the
|
||||
semantic actions of this grammar. */
|
||||
int max_left_semantic_context = 0;
|
||||
|
||||
@@ -807,10 +808,10 @@ handle_action_dollar (char *text, location loc)
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------.
|
||||
| Dispatch onto handle_action_dollar, or handle_destructor_dollar, |
|
||||
| depending upon TOKEN_TYPE. |
|
||||
`-----------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------.
|
||||
| Map `$?' onto the proper M4 symbol, depending on its TOKEN_TYPE |
|
||||
| (are we in an action?). |
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
handle_dollar (int token_type, char *text, location loc)
|
||||
@@ -823,6 +824,7 @@ handle_dollar (int token_type, char *text, location loc)
|
||||
break;
|
||||
|
||||
case PERCENT_DESTRUCTOR:
|
||||
case PERCENT_INITIAL_ACTION:
|
||||
case PERCENT_PRINTER:
|
||||
if (text[1] == '$')
|
||||
{
|
||||
@@ -875,10 +877,10 @@ handle_action_at (char *text, location loc)
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Dispatch onto handle_action_at, or handle_destructor_at, depending |
|
||||
| upon CODE_KIND. |
|
||||
`-------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------.
|
||||
| Map `@?' onto the proper M4 symbol, depending on its TOKEN_TYPE |
|
||||
| (are we in an action?). |
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
handle_at (int token_type, char *text, location loc)
|
||||
@@ -889,6 +891,7 @@ handle_at (int token_type, char *text, location loc)
|
||||
handle_action_at (text, loc);
|
||||
return;
|
||||
|
||||
case PERCENT_INITIAL_ACTION:
|
||||
case PERCENT_DESTRUCTOR:
|
||||
case PERCENT_PRINTER:
|
||||
if (text[1] == '$')
|
||||
|
||||
Reference in New Issue
Block a user