mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Simplify implementation of unqualified %code, implement macros for uniform treatment of boolean %define flags. Document %define. * data/bison.m4 (b4_percent_define_ifdef, b4_percent_define_flag_if, b4_percent_code_ifdef): New. (b4_percent_code_get): Map unqualified %code to b4_percent_code(). * data/c++.m4: Define default value for global_tokens_and_yystype. * data/glr.cc: Likewise. * data/location.cc: Use b4_percent_define_flag_if. * doc/bison.texinfo (Directives): Document %define. * src/parse-gram.y (Unqualified %code): Change muscle name to b4_percent_code(). (content.opt): Default to empty.
128 lines
3.7 KiB
Plaintext
128 lines
3.7 KiB
Plaintext
-*- Autoconf -*-
|
|
|
|
# C++ skeleton for Bison
|
|
|
|
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
|
|
# Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
# 02110-1301 USA
|
|
|
|
m4_include(b4_pkgdatadir/[c.m4])
|
|
|
|
## ---------------- ##
|
|
## Default values. ##
|
|
## ---------------- ##
|
|
|
|
# Default parser class name.
|
|
b4_percent_define_default([[parser_class_name]], [[parser]])
|
|
b4_percent_define_default([[location_type]], [[location]])
|
|
b4_percent_define_default([[filename_type]], [[std::string]])
|
|
b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
|
|
b4_percent_define_default([[global_tokens_and_yystype]], [[0]])
|
|
b4_percent_define_default([[define_location_comparison]],
|
|
[m4_if(b4_percent_define_get([[filename_type]]),
|
|
[std::string], [[1]], [[0]])])
|
|
|
|
|
|
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
|
|
# -----------------------------------------------------
|
|
# Output the definition of the tokens as enums.
|
|
m4_define([b4_token_enums],
|
|
[/* Tokens. */
|
|
enum yytokentype {
|
|
m4_map_sep([ b4_token_enum], [,
|
|
],
|
|
[$@])
|
|
};
|
|
])
|
|
|
|
|
|
## ----------------- ##
|
|
## Semantic Values. ##
|
|
## ----------------- ##
|
|
|
|
|
|
# b4_lhs_value([TYPE])
|
|
# --------------------
|
|
# Expansion of $<TYPE>$.
|
|
m4_define([b4_lhs_value],
|
|
[(yyval[]m4_ifval([$1], [.$1]))])
|
|
|
|
|
|
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
|
# --------------------------------------
|
|
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
|
# symbols on RHS.
|
|
m4_define([b4_rhs_value],
|
|
[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
|
|
|
|
# b4_lhs_location()
|
|
# -----------------
|
|
# Expansion of @$.
|
|
m4_define([b4_lhs_location],
|
|
[(yyloc)])
|
|
|
|
|
|
# b4_rhs_location(RULE-LENGTH, NUM)
|
|
# ---------------------------------
|
|
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
|
|
# on RHS.
|
|
m4_define([b4_rhs_location],
|
|
[(yylocation_stack_@{($1) - ($2)@})])
|
|
|
|
|
|
# b4_parse_param_decl
|
|
# -------------------
|
|
# Extra formal arguments of the constructor.
|
|
# Change the parameter names from "foo" into "foo_yyarg", so that
|
|
# there is no collision bw the user chosen attribute name, and the
|
|
# argument name in the constructor.
|
|
m4_define([b4_parse_param_decl],
|
|
[m4_ifset([b4_parse_param],
|
|
[m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
|
|
|
|
m4_define([b4_parse_param_decl_1],
|
|
[$1_yyarg])
|
|
|
|
|
|
|
|
# b4_parse_param_cons
|
|
# -------------------
|
|
# Extra initialisations of the constructor.
|
|
m4_define([b4_parse_param_cons],
|
|
[m4_ifset([b4_parse_param],
|
|
[
|
|
b4_cc_constructor_calls(b4_parse_param)])])
|
|
m4_define([b4_cc_constructor_calls],
|
|
[m4_map_sep([b4_cc_constructor_call], [,
|
|
], [$@])])
|
|
m4_define([b4_cc_constructor_call],
|
|
[$2 ($2_yyarg)])
|
|
|
|
# b4_parse_param_vars
|
|
# -------------------
|
|
# Extra instance variables.
|
|
m4_define([b4_parse_param_vars],
|
|
[m4_ifset([b4_parse_param],
|
|
[
|
|
/* User arguments. */
|
|
b4_cc_var_decls(b4_parse_param)])])
|
|
m4_define([b4_cc_var_decls],
|
|
[m4_map_sep([b4_cc_var_decl], [
|
|
], [$@])])
|
|
m4_define([b4_cc_var_decl],
|
|
[ $1;])
|