]> git.saurik.com Git - bison.git/blame - data/c++.m4
yysyntax_error: prepare for readability of next patches.
[bison.git] / data / c++.m4
CommitLineData
08af01c2 1 -*- Autoconf -*-
cf147260
AD
2
3# C++ skeleton for Bison
4
6e30ede8
PE
5# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
6# Free Software Foundation, Inc.
cf147260 7
f16b0819 8# This program is free software: you can redistribute it and/or modify
cf147260 9# it under the terms of the GNU General Public License as published by
f16b0819 10# the Free Software Foundation, either version 3 of the License, or
cf147260 11# (at your option) any later version.
f16b0819 12#
cf147260
AD
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
f16b0819 17#
cf147260 18# You should have received a copy of the GNU General Public License
f16b0819 19# along with this program. If not, see <http://www.gnu.org/licenses/>.
cf147260 20
3953ed88
AD
21m4_include(b4_pkgdatadir/[c.m4])
22
cf147260
AD
23## ---------------- ##
24## Default values. ##
25## ---------------- ##
26
27# Default parser class name.
a4e25e1d 28b4_percent_define_default([[parser_class_name]], [[parser]])
95a2de56
AD
29
30# Don't do that so that we remember whether we're using a user
31# request, or the default value.
32#
33# b4_percent_define_default([[location_type]], [[location]])
34
a4e25e1d
JD
35b4_percent_define_default([[filename_type]], [[std::string]])
36b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
c1d19e10 37b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
a4e25e1d
JD
38b4_percent_define_default([[define_location_comparison]],
39 [m4_if(b4_percent_define_get([[filename_type]]),
c1d19e10 40 [std::string], [[true]], [[false]])])
cf147260
AD
41
42
793fbca5
JD
43## ----------- ##
44## Namespace. ##
45## ----------- ##
46
47m4_define([b4_namespace_ref], [b4_percent_define_get([[namespace]])])
48
49# Don't permit an empty b4_namespace_ref. Any `::parser::foo' appended to it
50# would compile as an absolute reference with `parser' in the global namespace.
51# b4_namespace_open would open an anonymous namespace and thus establish
52# internal linkage. This would compile. However, it's cryptic, and internal
53# linkage for the parser would be specified in all translation units that
54# include the header, which is always generated. If we ever need to permit
55# internal linkage somehow, surely we can find a cleaner approach.
56m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
57[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
58 [[namespace reference is empty]])])
59
60# Instead of assuming the C++ compiler will do it, Bison should reject any
61# invalid b4_namepsace_ref that would be converted to a valid
62# b4_namespace_open. The problem is that Bison doesn't always output
63# b4_namespace_ref to uncommented code but should reserve the ability to do so
64# in future releases without risking breaking any existing user grammars.
65# Specifically, don't allow empty names as b4_namespace_open would just convert
66# those into anonymous namespaces, and that might tempt some users.
67m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
68[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
69 [[namespace reference has consecutive "::"]])])
70m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
71[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
72 [[namespace reference has a trailing "::"]])])
73
74m4_define([b4_namespace_open],
75[b4_user_code([b4_percent_define_get_syncline([[namespace]])
76[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
77 [^\(.\)[ ]*::], [\1])),
78 [::], [ { namespace ])[ {]])])
79
80m4_define([b4_namespace_close],
81[b4_user_code([b4_percent_define_get_syncline([[namespace]])
8c221795 82m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
e7bfa8b7 83 [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
793fbca5 84 [\1])),
e7bfa8b7 85 [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
793fbca5
JD
86
87
cf147260
AD
88# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
89# -----------------------------------------------------
c095d689 90# Output the definition of the tokens as enums.
cf147260 91m4_define([b4_token_enums],
cf147260
AD
92[/* Tokens. */
93 enum yytokentype {
94m4_map_sep([ b4_token_enum], [,
95],
96 [$@])
97 };
c095d689 98])
cf147260
AD
99
100
101## ----------------- ##
102## Semantic Values. ##
103## ----------------- ##
104
105
106# b4_lhs_value([TYPE])
107# --------------------
108# Expansion of $<TYPE>$.
109m4_define([b4_lhs_value],
110[(yyval[]m4_ifval([$1], [.$1]))])
111
112
113# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
114# --------------------------------------
115# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
116# symbols on RHS.
117m4_define([b4_rhs_value],
d1ff7a7c 118[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
cf147260
AD
119
120# b4_lhs_location()
121# -----------------
122# Expansion of @$.
123m4_define([b4_lhs_location],
124[(yyloc)])
125
126
127# b4_rhs_location(RULE-LENGTH, NUM)
128# ---------------------------------
129# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
130# on RHS.
131m4_define([b4_rhs_location],
d1ff7a7c 132[(yylocation_stack_@{($1) - ($2)@})])
cf147260
AD
133
134
135# b4_parse_param_decl
136# -------------------
137# Extra formal arguments of the constructor.
138# Change the parameter names from "foo" into "foo_yyarg", so that
139# there is no collision bw the user chosen attribute name, and the
140# argument name in the constructor.
141m4_define([b4_parse_param_decl],
142[m4_ifset([b4_parse_param],
143 [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
144
145m4_define([b4_parse_param_decl_1],
146[$1_yyarg])
147
148
149
150# b4_parse_param_cons
151# -------------------
152# Extra initialisations of the constructor.
153m4_define([b4_parse_param_cons],
154 [m4_ifset([b4_parse_param],
fa7b79c0 155 [
cf147260
AD
156 b4_cc_constructor_calls(b4_parse_param)])])
157m4_define([b4_cc_constructor_calls],
158 [m4_map_sep([b4_cc_constructor_call], [,
159 ], [$@])])
160m4_define([b4_cc_constructor_call],
161 [$2 ($2_yyarg)])
162
163# b4_parse_param_vars
164# -------------------
165# Extra instance variables.
166m4_define([b4_parse_param_vars],
167 [m4_ifset([b4_parse_param],
168 [
169 /* User arguments. */
170b4_cc_var_decls(b4_parse_param)])])
171m4_define([b4_cc_var_decls],
172 [m4_map_sep([b4_cc_var_decl], [
173], [$@])])
174m4_define([b4_cc_var_decl],
175 [ $1;])