mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-26 20:53:04 +00:00
glr.cc: no longer require location support
* data/glr.cc: Use b4_locations_if where appropriate. * data/lalr1.cc: M4 quotation changes to highlight code duplication with glr.cc. * tests/calc.at: Check glr.cc with and without %location. While at it, fuse multiple %parse-params into one. * tests/actions.at: Simplify. * NEWS: Doc this. Some other wording changes.
This commit is contained in:
10
NEWS
10
NEWS
@@ -12,7 +12,7 @@ GNU Bison NEWS
|
||||
|
||||
** Warnings
|
||||
|
||||
*** Warning categories are now displayed in warnings
|
||||
*** Warning categories are now displayed
|
||||
|
||||
For instance:
|
||||
|
||||
@@ -82,7 +82,13 @@ GNU Bison NEWS
|
||||
Also, it is possible to add code to the parser's constructors using
|
||||
"%code init" and "%define init_throws".
|
||||
|
||||
** C++ skeleton improvements
|
||||
** C++ skeletons improvements
|
||||
|
||||
*** locations are no longer mandatory (lalr1.cc, glr.cc)
|
||||
|
||||
Both lalr1.cc and glr.cc no longer require %location.
|
||||
|
||||
*** syntax_error exception (lalr1.cc)
|
||||
|
||||
The C++ parser features a syntax_error exception, which can be
|
||||
thrown from the scanner or from user rules to raise syntax errors.
|
||||
|
||||
62
data/glr.cc
62
data/glr.cc
@@ -43,8 +43,7 @@
|
||||
# user must initialize the first positions (in particular the
|
||||
# filename member).
|
||||
|
||||
# We require a pure interface using locations.
|
||||
m4_define([b4_percent_define(locations)], [])
|
||||
# We require a pure interface.
|
||||
m4_define([b4_pure_flag], [1])
|
||||
|
||||
# The header is mandatory.
|
||||
@@ -74,12 +73,13 @@ m4_define([b4_yy_symbol_print_generate],
|
||||
|
||||
]b4_c_ansi_function_def([yy_symbol_print],
|
||||
[static void],
|
||||
[[FILE *], []],
|
||||
[[int yytype], [yytype]],
|
||||
[[FILE *], []],
|
||||
[[int yytype], [yytype]],
|
||||
[[const ]b4_namespace_ref::b4_parser_class_name[::semantic_type *yyvaluep],
|
||||
[yyvaluep]],
|
||||
[yyvaluep]][]dnl
|
||||
b4_locations_if([,
|
||||
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
|
||||
[yylocationp]],
|
||||
[yylocationp]]]),
|
||||
b4_parse_param)[
|
||||
{
|
||||
]b4_parse_param_use[]dnl
|
||||
@@ -95,9 +95,9 @@ m4_append([b4_post_prologue],
|
||||
]b4_yylloc_default_define[
|
||||
#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
|
||||
]b4_c_ansi_function_decl([yyerror],
|
||||
[static void],
|
||||
[static void],b4_locations_if([
|
||||
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
|
||||
[yylocationp]],
|
||||
[yylocationp]],])
|
||||
b4_parse_param,
|
||||
[[const char* msg], [msg]])])
|
||||
|
||||
@@ -111,14 +111,14 @@ m4_append([b4_epilogue],
|
||||
`------------------*/
|
||||
|
||||
]b4_c_ansi_function_def([yyerror],
|
||||
[static void],
|
||||
[static void],b4_locations_if([
|
||||
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
|
||||
[yylocationp]],
|
||||
[yylocationp]],])
|
||||
b4_parse_param,
|
||||
[[const char* msg], [msg]])[
|
||||
{
|
||||
]b4_parse_param_use[]dnl
|
||||
[ yyparser.error (*yylocationp, msg);
|
||||
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,10 +151,10 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
|
||||
inline void
|
||||
]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
|
||||
const semantic_type* yyvaluep,
|
||||
const location_type* yylocationp)
|
||||
{
|
||||
YYUSE (yylocationp);
|
||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||
const location_type* yylocationp]])[)
|
||||
{]b4_locations_if([[
|
||||
YYUSE (yylocationp);]])[
|
||||
YYUSE (yyvaluep);
|
||||
std::ostream& yyoutput = debug_stream ();
|
||||
std::ostream& yyo = yyoutput;
|
||||
@@ -170,13 +170,13 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
|
||||
void
|
||||
]b4_parser_class_name[::yy_symbol_print_ (int yytype,
|
||||
const semantic_type* yyvaluep,
|
||||
const location_type* yylocationp)
|
||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||
const location_type* yylocationp]])[)
|
||||
{
|
||||
*yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
|
||||
<< ' ' << yytname[yytype] << " ("
|
||||
<< *yylocationp << ": ";
|
||||
yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
|
||||
<< ' ' << yytname[yytype] << " ("]b4_locations_if([[
|
||||
<< *yylocationp << ": "]])[;
|
||||
yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[);
|
||||
*yycdebug_ << ')';
|
||||
}
|
||||
|
||||
@@ -270,27 +270,27 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
|
||||
void set_debug_level (debug_level_type l);
|
||||
|
||||
public:
|
||||
/// Report a syntax error.
|
||||
/// \param loc where the syntax error is found.
|
||||
/// Report a syntax error.]b4_locations_if([[
|
||||
/// \param loc where the syntax error is found.]])[
|
||||
/// \param msg a description of the syntax error.
|
||||
virtual void error (const location_type& loc, const std::string& msg);
|
||||
virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
|
||||
|
||||
# if ]b4_api_PREFIX[DEBUG
|
||||
public:
|
||||
/// \brief Report a symbol value on the debug stream.
|
||||
/// \param yytype The token type.
|
||||
/// \param yyvaluep Its semantic value.
|
||||
/// \param yylocationp Its location.
|
||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
||||
/// \param yylocationp Its location.]])[
|
||||
virtual void yy_symbol_value_print_ (int yytype,
|
||||
const semantic_type* yyvaluep,
|
||||
const location_type* yylocationp);
|
||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||
const location_type* yylocationp]])[);
|
||||
/// \brief Report a symbol on the debug stream.
|
||||
/// \param yytype The token type.
|
||||
/// \param yyvaluep Its semantic value.
|
||||
/// \param yylocationp Its location.
|
||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
||||
/// \param yylocationp Its location.]])[
|
||||
virtual void yy_symbol_print_ (int yytype,
|
||||
const semantic_type* yyvaluep,
|
||||
const location_type* yylocationp);
|
||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||
const location_type* yylocationp]])[);
|
||||
private:
|
||||
/* Debugging. */
|
||||
std::ostream* yycdebug_;
|
||||
|
||||
@@ -189,10 +189,10 @@ b4_namespace_close])[
|
||||
void set_debug_level (debug_level_type l);
|
||||
#endif
|
||||
|
||||
/// Report a syntax error.]b4_locations_if([
|
||||
/// \param loc where the syntax error is found.])[
|
||||
/// Report a syntax error.]b4_locations_if([[
|
||||
/// \param loc where the syntax error is found.]])[
|
||||
/// \param msg a description of the syntax error.
|
||||
virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
|
||||
virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
|
||||
|
||||
/// Report a syntax error.
|
||||
void error (const syntax_error& err);
|
||||
|
||||
@@ -1273,12 +1273,11 @@ AT_CHECK_ACTION_LOCATIONS([[%printer]])
|
||||
m4_pushdef([AT_TEST],
|
||||
[AT_SETUP([[Qualified $$ in actions: $1]])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1"])
|
||||
AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
|
||||
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%skeleton "$1"
|
||||
%defines // FIXME: Mandated by lalr1.cc in Bison 2.6.
|
||||
%locations // FIXME: Mandated by lalr1.cc in Bison 2.6.
|
||||
%debug
|
||||
%code requires
|
||||
{
|
||||
@@ -1321,17 +1320,6 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
%printer { report (yyo, $<ival>$, $$ ); } <fval>;
|
||||
%printer { report (yyo, $<ival>$, $<fval>$); } <>;
|
||||
|
||||
]AT_SKEL_CC_IF([[
|
||||
/* The lalr1.cc skeleton, for backward compatibility, defines
|
||||
a constructor for position that initializes the filename. The
|
||||
glr.cc skeleton does not (and in fact cannot: location/position
|
||||
are stored in a union, from which objects with constructors are
|
||||
excluded in C++). */
|
||||
%initial-action {
|
||||
@$.initialize ();
|
||||
}
|
||||
]])[
|
||||
|
||||
%initial-action
|
||||
{
|
||||
$<ival>$ = 42;
|
||||
@@ -1366,10 +1354,7 @@ AT_FULL_COMPILE([[input]])
|
||||
AT_PARSER_CHECK([./input], 0, [], [stderr])
|
||||
# Don't be too picky on the traces, GLR is not exactly the same. Keep
|
||||
# only the lines from the printer.
|
||||
#
|
||||
# Don't care about locations. FIXME: remove their removal when Bison
|
||||
# supports C++ without locations.
|
||||
AT_CHECK([[sed -ne 's/([-0-9.]*: /(/;/ival:/p' stderr]], 0,
|
||||
AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
|
||||
[[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
|
||||
Shifting token UNTYPED (ival: 10, fval: 0.1)
|
||||
Reading a token: Next token is token INT (ival: 20, fval: 0.2)
|
||||
|
||||
@@ -637,7 +637,7 @@ AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %defi
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
|
||||
|
||||
# ----------------------- #
|
||||
@@ -675,8 +675,8 @@ AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %defin
|
||||
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
|
||||
|
||||
# ----------------------------- #
|
||||
@@ -686,7 +686,7 @@ AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %location
|
||||
AT_BANNER([[Simple LALR(1) C++ Calculator.]])
|
||||
|
||||
# First let's try using %skeleton
|
||||
AT_CHECK_CALC([%skeleton "lalr1.cc" %defines %locations])
|
||||
AT_CHECK_CALC([%skeleton "lalr1.cc" %defines])
|
||||
|
||||
# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])
|
||||
# ---------------------------------------
|
||||
@@ -706,8 +706,10 @@ AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-pref
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
|
||||
AT_CHECK_CALC_LALR1_CC([%pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
|
||||
|
||||
|
||||
@@ -718,7 +720,7 @@ AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %deb
|
||||
AT_BANNER([[Simple GLR C++ Calculator.]])
|
||||
|
||||
# Again, we try also using %skeleton.
|
||||
AT_CHECK_CALC([%skeleton "glr.cc" %defines %locations])
|
||||
AT_CHECK_CALC([%skeleton "glr.cc" %defines])
|
||||
|
||||
# AT_CHECK_CALC_GLR_CC([BISON-OPTIONS])
|
||||
# -------------------------------------
|
||||
@@ -728,7 +730,8 @@ m4_define([AT_CHECK_CALC_GLR_CC],
|
||||
[AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)])
|
||||
|
||||
AT_CHECK_CALC_GLR_CC([])
|
||||
AT_CHECK_CALC_GLR_CC([%define location_type Span])
|
||||
AT_CHECK_CALC_GLR_CC([%locations])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %define location_type Span])
|
||||
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %name-prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %define api.prefix "calc" %verbose %yacc])
|
||||
|
||||
@@ -738,5 +741,5 @@ AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %ve
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
|
||||
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
AT_CHECK_CALC_GLR_CC([%locations %pure-parser %define parse.error verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} {int *count}])
|
||||
|
||||
Reference in New Issue
Block a user