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