]>
Commit | Line | Data |
---|---|---|
a75c057f | 1 | m4_divert(-1) |
60491a94 | 2 | # C++ skeleton for Bison |
779e7ceb | 3 | # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. |
60491a94 AD |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 2 of the License, or | |
8 | # (at your option) any later version. | |
9 | ||
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | ||
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | # 02111-1307 USA | |
19 | ||
66d30cd4 AD |
20 | ## ---------------- ## |
21 | ## Default values. ## | |
22 | ## ---------------- ## | |
23 | ||
99880de5 AD |
24 | # Default parser class name. |
25 | m4_define_default([b4_parser_class_name], [parser]) | |
66d30cd4 AD |
26 | |
27 | ||
28 | ||
29 | ## ----------------- ## | |
30 | ## Semantic Values. ## | |
31 | ## ----------------- ## | |
32 | ||
33 | ||
82b6cb3f AD |
34 | # b4_lhs_value([TYPE]) |
35 | # -------------------- | |
36 | # Expansion of $<TYPE>$. | |
37 | m4_define([b4_lhs_value], | |
bc82c5a5 | 38 | [(yyval[]m4_ifval([$1], [.$1]))]) |
82b6cb3f AD |
39 | |
40 | ||
41 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
42 | # -------------------------------------- | |
43 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
44 | # symbols on RHS. | |
45 | m4_define([b4_rhs_value], | |
bc82c5a5 | 46 | [(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))]) |
82b6cb3f | 47 | |
99880de5 | 48 | m4_define_default([b4_location_type], [location]) |
9a0d8bec | 49 | m4_define_default([b4_filename_type], [std::string]) |
82b6cb3f AD |
50 | |
51 | # b4_lhs_location() | |
52 | # ----------------- | |
53 | # Expansion of @$. | |
54 | m4_define([b4_lhs_location], | |
bc82c5a5 | 55 | [(yyloc)]) |
82b6cb3f AD |
56 | |
57 | ||
58 | # b4_rhs_location(RULE-LENGTH, NUM) | |
59 | # --------------------------------- | |
60 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
61 | # on RHS. | |
62 | m4_define([b4_rhs_location], | |
bc82c5a5 | 63 | [(yylocation_stack_@{m4_eval([$1 - $2])@})]) |
82b6cb3f AD |
64 | |
65 | ||
caf37a36 ADL |
66 | # b4_parse_param_decl |
67 | # ------------------- | |
6dde1c82 AD |
68 | # Extra formal arguments of the constructor. |
69 | # Change the parameter names from "foo" into "foo_yyarg", so that | |
70 | # there is no collision bw the user chosen attribute name, and the | |
71 | # argument name in the constructor. | |
caf37a36 | 72 | m4_define([b4_parse_param_decl], |
6dde1c82 | 73 | [m4_ifset([b4_parse_param], |
a3cb6248 | 74 | [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) |
6dde1c82 AD |
75 | |
76 | m4_define([b4_parse_param_decl_1], | |
77 | [$1_yyarg]) | |
78 | ||
79 | ||
caf37a36 ADL |
80 | |
81 | # b4_parse_param_cons | |
82 | # ------------------- | |
6dde1c82 | 83 | # Extra initialisations of the constructor. |
caf37a36 ADL |
84 | m4_define([b4_parse_param_cons], |
85 | [m4_ifset([b4_parse_param], | |
86 | [, | |
87 | b4_cc_constructor_calls(b4_parse_param)])]) | |
88 | m4_define([b4_cc_constructor_calls], | |
89 | [m4_map_sep([b4_cc_constructor_call], [, | |
90 | ], [$@])]) | |
91 | m4_define([b4_cc_constructor_call], | |
6dde1c82 | 92 | [$2 ($2_yyarg)]) |
caf37a36 ADL |
93 | |
94 | # b4_parse_param_vars | |
95 | # ------------------- | |
6dde1c82 | 96 | # Extra instance variables. |
caf37a36 ADL |
97 | m4_define([b4_parse_param_vars], |
98 | [m4_ifset([b4_parse_param], | |
99 | [ | |
100 | /* User arguments. */ | |
101 | b4_cc_var_decls(b4_parse_param)])]) | |
102 | m4_define([b4_cc_var_decls], | |
103 | [m4_map_sep([b4_cc_var_decl], [ | |
104 | ], [$@])]) | |
105 | m4_define([b4_cc_var_decl], | |
106 | [ $1;]) | |
107 | ||
a5eb1ed2 | 108 | |
a5eb1ed2 | 109 | |
b526ee61 AD |
110 | # We do want M4 expansion after # for CPP macros. |
111 | m4_changecom() | |
98254360 | 112 | m4_divert(0)dnl |
b61c6978 PE |
113 | m4_if(b4_defines_flag, 0, [], |
114 | [@output @output_header_name@ | |
fb8135fa | 115 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
779e7ceb | 116 | [2002, 2003, 2004])[ |
c5e3e510 AD |
117 | /* FIXME: This is wrong, we want computed header guards. |
118 | I don't know why the macros are missing now. :( */ | |
119 | #ifndef PARSER_HEADER_H | |
120 | # define PARSER_HEADER_H | |
2b548aa6 | 121 | |
8d69a1a3 | 122 | #include <string> |
717be197 | 123 | #include <iostream> |
50997c6e | 124 | |
4162fa07 | 125 | /* Using locations. */ |
c5e3e510 | 126 | #define YYLSP_NEEDED ]b4_locations_flag[ |
4162fa07 | 127 | |
d390b02b AD |
128 | namespace yy |
129 | { | |
130 | class position; | |
131 | class location; | |
132 | } | |
133 | ||
c5e3e510 | 134 | ]b4_token_defines(b4_tokens)[ |
17acead5 | 135 | |
0dd1580a | 136 | /* Copy the first part of user declarations. */ |
c5e3e510 | 137 | ]b4_pre_prologue[ |
4162fa07 | 138 | |
996b1c7e | 139 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 140 | b4_syncline([@oline@], [@ofile@])[ |
e96c9728 | 141 | |
9a0d8bec AD |
142 | #include "stack.hh" |
143 | #include "location.hh" | |
144 | ||
69e2658b RA |
145 | /* Enabling traces. */ |
146 | #ifndef YYDEBUG | |
c5e3e510 | 147 | # define YYDEBUG ]b4_debug[ |
69e2658b RA |
148 | #endif |
149 | ||
150 | /* Enabling verbose error message. */ | |
151 | #ifndef YYERROR_VERBOSE | |
c5e3e510 | 152 | # define YYERROR_VERBOSE ]b4_error_verbose[ |
69e2658b RA |
153 | #endif |
154 | ||
be3d9d42 | 155 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
c5e3e510 | 156 | ]m4_ifdef([b4_stype], |
437c2d80 | 157 | [b4_syncline([b4_stype_line], [b4_filename]) |
be3d9d42 | 158 | union YYSTYPE b4_stype; |
996b1c7e | 159 | /* Line __line__ of lalr1.cc. */ |
6ad762a8 | 160 | b4_syncline([@oline@], [@ofile@])], |
be3d9d42 AD |
161 | [typedef int YYSTYPE;])[ |
162 | # define yystype YYSTYPE /* obsolescent; will be withdrawn */ | |
163 | # define YYSTYPE_IS_DECLARED 1 | |
164 | # define YYSTYPE_IS_TRIVIAL 1 | |
98254360 RA |
165 | #endif |
166 | ||
0dd1580a | 167 | /* Copy the second part of user declarations. */ |
c5e3e510 | 168 | ]b4_post_prologue[ |
0dd1580a | 169 | |
996b1c7e | 170 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 171 | b4_syncline([@oline@], [@ofile@])[ |
b4a20338 AD |
172 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. |
173 | If N is 0, then set CURRENT to the empty location which ends | |
174 | the previous symbol: RHS[0] (always defined). */ | |
3fc16193 | 175 | |
374f5a14 | 176 | #ifndef YYLLOC_DEFAULT |
b4a20338 AD |
177 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
178 | do { \ | |
179 | if (N) \ | |
180 | { \ | |
181 | (Current).begin = (Rhs)[1].begin; \ | |
182 | (Current).end = (Rhs)[N].end; \ | |
183 | } \ | |
184 | else \ | |
185 | { \ | |
186 | (Current).begin = (Current).end = (Rhs)[0].end; \ | |
187 | } \ | |
3fc16193 | 188 | } while (0) |
374f5a14 RA |
189 | #endif |
190 | ||
2b548aa6 RA |
191 | namespace yy |
192 | { | |
c5e3e510 | 193 | class ]b4_parser_class_name[; |
3f3eed27 | 194 | |
f85a5e6f | 195 | template <typename P> |
99880de5 | 196 | struct traits |
2b548aa6 RA |
197 | { |
198 | }; | |
199 | ||
f85a5e6f | 200 | template <> |
99880de5 | 201 | struct traits<]b4_parser_class_name[> |
2b548aa6 | 202 | { |
99880de5 AD |
203 | typedef ]b4_int_type_for([b4_translate])[ token_number_type; |
204 | typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type; | |
205 | typedef int state_type; | |
206 | typedef YYSTYPE semantic_type; | |
207 | typedef ]b4_location_type[ location_type; | |
2b548aa6 RA |
208 | }; |
209 | } | |
210 | ||
2b548aa6 RA |
211 | namespace yy |
212 | { | |
efeed023 | 213 | /// A Bison parser. |
07fed891 | 214 | class ]b4_parser_class_name[ |
2b548aa6 RA |
215 | { |
216 | public: | |
617a8f12 | 217 | /// Internal symbol numbers. |
99880de5 | 218 | typedef traits<]b4_parser_class_name[>::token_number_type token_number_type; |
617a8f12 | 219 | /// A type to store symbol numbers and -1. |
99880de5 | 220 | typedef traits<]b4_parser_class_name[>::rhs_number_type rhs_number_type; |
617a8f12 | 221 | /// State numbers. |
99880de5 | 222 | typedef traits<]b4_parser_class_name[>::state_type state_type; |
617a8f12 | 223 | /// Symbol semantic values. |
99880de5 | 224 | typedef traits<]b4_parser_class_name[>::semantic_type semantic_type; |
617a8f12 | 225 | /// Symbol locations. |
99880de5 | 226 | typedef traits<]b4_parser_class_name[>::location_type location_type; |
2b548aa6 | 227 | |
efeed023 | 228 | /// State stack type. |
99880de5 | 229 | typedef stack<state_type> state_stack; |
efeed023 | 230 | /// Semantic value stack type. |
99880de5 AD |
231 | typedef stack<semantic_type> semantic_stack; |
232 | /// location stack type. | |
233 | typedef stack<location_type> location_stack; | |
2b548aa6 | 234 | |
efeed023 | 235 | /// Build a parser object. |
a3cb6248 AD |
236 | ]b4_parser_class_name[ (]b4_parse_param_decl[) : |
237 | yydebug_ (false), | |
9a1e9989 | 238 | yycdebug_ (&std::cerr)]b4_parse_param_cons[ |
50997c6e | 239 | { |
50997c6e RA |
240 | } |
241 | ||
c5e3e510 | 242 | virtual ~]b4_parser_class_name[ () |
2b548aa6 | 243 | { |
2b548aa6 RA |
244 | } |
245 | ||
f69a4142 AD |
246 | /// Parse. |
247 | /// \returns 0 iff parsing succeeded. | |
72731bb7 | 248 | virtual bool parse (); |
2b548aa6 | 249 | |
f69a4142 | 250 | /// The current debugging stream. |
9a1e9989 AD |
251 | std::ostream& debug_stream () const; |
252 | /// Set the current debugging stream. | |
253 | void set_debug_stream (std::ostream &); | |
254 | ||
a3cb6248 AD |
255 | /// Type for debugging levels. |
256 | typedef int debug_level_type; | |
257 | /// The current debugging level. | |
258 | debug_level_type debug_level () const; | |
259 | /// Set the current debugging level. | |
260 | void set_debug_level (debug_level_type l); | |
261 | ||
2b548aa6 | 262 | private: |
3f3eed27 | 263 | |
f69a4142 | 264 | /// Call the scanner. |
2e1f5829 | 265 | virtual void yylex_ (); |
efeed023 AD |
266 | |
267 | /// Report a syntax error. | |
268 | /// \param loc where the syntax error is found. | |
269 | /// \param msg a description of the syntax error. | |
99880de5 | 270 | virtual void error (const location_type& loc, const std::string& msg); |
efeed023 AD |
271 | |
272 | /// Generate an error message, and invoke error. | |
f69a4142 | 273 | virtual void yyreport_syntax_error_ (); |
efeed023 | 274 | |
a5eb1ed2 | 275 | #if YYDEBUG |
f69a4142 AD |
276 | /// \brief Report a symbol on the debug stream. |
277 | /// \param yytype The token type. | |
278 | /// \param yyvaluep Its semantic value. | |
279 | /// \param yylocationp Its location. | |
280 | virtual void yysymprint_ (int yytype, | |
99880de5 AD |
281 | const semantic_type* yyvaluep, |
282 | const location_type* yylocationp); | |
a5eb1ed2 AD |
283 | #endif /* ! YYDEBUG */ |
284 | ||
4bb2bc3f | 285 | |
f69a4142 | 286 | /// The state stack. |
99880de5 | 287 | state_stack yystate_stack_; |
f69a4142 | 288 | /// The semantic value stack. |
99880de5 | 289 | semantic_stack yysemantic_stack_; |
f69a4142 | 290 | /// The location stack. |
99880de5 | 291 | location_stack yylocation_stack_; |
2b548aa6 RA |
292 | |
293 | /* Tables. */ | |
efeed023 | 294 | /// For a state, the index in \a yytable_ of its portion. |
617a8f12 AD |
295 | static const ]b4_int_type_for([b4_pact])[ yypact_[]; |
296 | static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; | |
efeed023 AD |
297 | |
298 | /// For a state, default rule to reduce. | |
299 | /// Unless\a yytable_ specifies something else to do. | |
300 | /// Zero means the default is an error. | |
617a8f12 | 301 | static const ]b4_int_type_for([b4_defact])[ yydefact_[]; |
efeed023 | 302 | |
617a8f12 AD |
303 | static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[]; |
304 | static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[]; | |
efeed023 AD |
305 | |
306 | /// What to do in a state. | |
307 | /// \a yytable_[yypact_[s]]: what to do in state \a s. | |
308 | /// - if positive, shift that token. | |
309 | /// - if negative, reduce the rule which number is the opposite. | |
310 | /// - if zero, do what YYDEFACT says. | |
617a8f12 AD |
311 | static const ]b4_int_type_for([b4_table])[ yytable_[]; |
312 | static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; | |
efeed023 | 313 | |
617a8f12 | 314 | static const ]b4_int_type_for([b4_check])[ yycheck_[]; |
efeed023 AD |
315 | |
316 | /// For a state, its accessing symbol. | |
617a8f12 | 317 | static const ]b4_int_type_for([b4_stos])[ yystos_[]; |
efeed023 AD |
318 | |
319 | /// For a rule, its LHS. | |
617a8f12 | 320 | static const ]b4_int_type_for([b4_r1])[ yyr1_[]; |
efeed023 | 321 | /// For a rule, its RHS length. |
617a8f12 | 322 | static const ]b4_int_type_for([b4_r2])[ yyr2_[]; |
69e2658b RA |
323 | |
324 | #if YYDEBUG || YYERROR_VERBOSE | |
efeed023 | 325 | /// For a symbol, its name in clear. |
617a8f12 | 326 | static const char* const yyname_[]; |
69e2658b | 327 | #endif |
2b548aa6 | 328 | |
69e2658b | 329 | #if YYDEBUG |
617a8f12 | 330 | /// A `-1'-separated list of the rules' RHS. |
99880de5 | 331 | static const rhs_number_type yyrhs_[]; |
617a8f12 AD |
332 | /// For each rule, the index of the first RHS symbol in \a yyrhs_. |
333 | static const ]b4_int_type_for([b4_prhs])[ yyprhs_[]; | |
334 | /// For each rule, its source line number. | |
335 | static const ]b4_int_type_for([b4_rline])[ yyrline_[]; | |
336 | /// For each scanner token number, its symbol number. | |
337 | static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; | |
efeed023 AD |
338 | /// Report on the debug stream that the rule \a r is going to be reduced. |
339 | virtual void yyreduce_print_ (int r); | |
340 | /// Print the state stack on the debug stream. | |
f69a4142 | 341 | virtual void yystack_print_ (); |
69e2658b | 342 | #endif |
2b548aa6 | 343 | |
f69a4142 | 344 | /// Convert a scanner token number to a symbol number. |
99880de5 | 345 | inline token_number_type yytranslate_ (int token); |
f69a4142 AD |
346 | |
347 | /// \brief Reclaim the memory associated to a symbol. | |
348 | /// \param yymsg Why this token is reclaimed. | |
349 | /// \param yytype The symbol type. | |
350 | /// \param yyvaluep Its semantic value. | |
351 | /// \param yylocationp Its location. | |
352 | inline void yydestruct_ (const char* yymsg, | |
353 | int yytype, | |
99880de5 AD |
354 | semantic_type* yyvaluep, |
355 | location_type* yylocationp); | |
2b548aa6 | 356 | |
52d5733f | 357 | /// Pop \a n symbols the three stacks. |
f69a4142 | 358 | inline void yypop_ (unsigned int n = 1); |
52d5733f | 359 | |
762a801e | 360 | /* Constants. */ |
617a8f12 | 361 | static const int yyeof_; |
39912f52 | 362 | /* LAST_ -- Last index in TABLE_. */ |
617a8f12 AD |
363 | static const int yylast_; |
364 | static const int yynnts_; | |
365 | static const int yyempty_; | |
366 | static const int yyfinal_; | |
367 | static const int yyterror_; | |
368 | static const int yyerrcode_; | |
369 | static const int yyntokens_; | |
370 | static const unsigned int yyuser_token_number_max_; | |
99880de5 | 371 | static const token_number_type yyundef_token_; |
2b548aa6 RA |
372 | |
373 | /* State. */ | |
617a8f12 AD |
374 | int yyn_; |
375 | int yylen_; | |
376 | int yystate_; | |
4bb2bc3f | 377 | |
a08460b0 | 378 | /* Error handling. */ |
617a8f12 AD |
379 | int yynerrs_; |
380 | int yyerrstatus_; | |
a08460b0 | 381 | |
717be197 | 382 | /* Debugging. */ |
a3cb6248 | 383 | int yydebug_; |
9a1e9989 | 384 | std::ostream* yycdebug_; |
717be197 | 385 | |
8dd162d3 | 386 | /* Look-ahead and look-ahead in internal form. */ |
617a8f12 AD |
387 | int yylooka_; |
388 | int yyilooka_; | |
4bb2bc3f | 389 | |
451364ed | 390 | /// Semantic value of the look-ahead. |
99880de5 | 391 | semantic_type yylval; |
451364ed | 392 | /// Location of the look-ahead. |
99880de5 | 393 | location_type yylloc; |
3fc16193 | 394 | /// The locations where the error started and ended. |
99880de5 | 395 | location yyerror_range_[2]; |
8d69a1a3 | 396 | |
451364ed | 397 | /// $$. |
99880de5 | 398 | semantic_type yyval; |
451364ed | 399 | /// @@$. |
99880de5 | 400 | location_type yyloc; |
caf37a36 | 401 | ]b4_parse_param_vars[ |
2b548aa6 RA |
402 | }; |
403 | } | |
404 | ||
c5e3e510 | 405 | #endif /* ! defined PARSER_HEADER_H */] |
b61c6978 | 406 | ])dnl |
6ad762a8 | 407 | @output @output_parser_name@ |
fb8135fa | 408 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
779e7ceb | 409 | [2002, 2003, 2004]) |
c5b95ccf AD |
410 | m4_if(b4_prefix[], [yy], [], |
411 | [ | |
412 | // Take the name prefix into account. | |
413 | #define yylex b4_prefix[]lex]) | |
414 | m4_if(b4_defines_flag, 0, [], | |
415 | [ | |
416 | #include @output_header_name@])[ | |
50997c6e | 417 | |
a3cb6248 | 418 | /* A pseudo ostream that takes yydebug_ into account. */ |
9a1e9989 | 419 | # define YYCDEBUG \ |
a3cb6248 | 420 | for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ |
9a1e9989 AD |
421 | (*yycdebug_) |
422 | ||
2b548aa6 | 423 | /* Enable debugging if requested. */ |
50997c6e | 424 | #if YYDEBUG |
284acc8b | 425 | |
284acc8b AD |
426 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
427 | do { \ | |
a3cb6248 | 428 | if (yydebug_) \ |
284acc8b | 429 | { \ |
9a1e9989 | 430 | *yycdebug_ << (Title) << ' '; \ |
f69a4142 | 431 | yysymprint_ ((Type), (Value), (Location)); \ |
9a1e9989 | 432 | *yycdebug_ << std::endl; \ |
284acc8b AD |
433 | } \ |
434 | } while (0) | |
435 | ||
5348bfbe AD |
436 | # define YY_REDUCE_PRINT(Rule) \ |
437 | do { \ | |
a3cb6248 | 438 | if (yydebug_) \ |
f69a4142 | 439 | yyreduce_print_ (Rule); \ |
5348bfbe | 440 | } while (0) |
284acc8b | 441 | |
25f66e1a AD |
442 | # define YY_STACK_PRINT() \ |
443 | do { \ | |
a3cb6248 | 444 | if (yydebug_) \ |
f69a4142 | 445 | yystack_print_ (); \ |
25f66e1a | 446 | } while (0) |
284acc8b | 447 | |
2b548aa6 | 448 | #else /* !YYDEBUG */ |
284acc8b | 449 | |
284acc8b | 450 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) |
5348bfbe | 451 | # define YY_REDUCE_PRINT(Rule) |
25f66e1a | 452 | # define YY_STACK_PRINT() |
284acc8b | 453 | |
2b548aa6 RA |
454 | #endif /* !YYDEBUG */ |
455 | ||
60a777aa AD |
456 | #define YYACCEPT goto yyacceptlab |
457 | #define YYABORT goto yyabortlab | |
47301314 | 458 | #define YYERROR goto yyerrorlab |
60a777aa | 459 | |
a5eb1ed2 | 460 | #if YYDEBUG |
a0e68930 AD |
461 | /*--------------------------------. |
462 | | Print this symbol on YYOUTPUT. | | |
463 | `--------------------------------*/ | |
464 | ||
465 | void | |
f69a4142 | 466 | yy::]b4_parser_class_name[::yysymprint_ (int yytype, |
99880de5 | 467 | const semantic_type* yyvaluep, const location_type* yylocationp) |
a0e68930 AD |
468 | { |
469 | /* Pacify ``unused variable'' warnings. */ | |
470 | (void) yyvaluep; | |
471 | (void) yylocationp; | |
9a1e9989 AD |
472 | /* Backward compatibility, but should be removed eventually. */ |
473 | std::ostream& cdebug_ = *yycdebug_; | |
c1f8f16a | 474 | (void) cdebug_; |
a0e68930 | 475 | |
617a8f12 AD |
476 | *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") |
477 | << ' ' << yyname_[yytype] << " (" | |
9a1e9989 | 478 | << *yylocationp << ": "; |
a0e68930 AD |
479 | switch (yytype) |
480 | { | |
481 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl | |
482 | [ default: | |
483 | break; | |
484 | } | |
9a1e9989 | 485 | *yycdebug_ << ')'; |
a0e68930 | 486 | } |
a5eb1ed2 | 487 | #endif /* ! YYDEBUG */ |
a0e68930 AD |
488 | |
489 | void | |
f69a4142 | 490 | yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg, |
99880de5 | 491 | int yytype, semantic_type* yyvaluep, location_type* yylocationp) |
a0e68930 AD |
492 | { |
493 | /* Pacify ``unused variable'' warnings. */ | |
494 | (void) yyvaluep; | |
495 | (void) yylocationp; | |
496 | ||
a0e68930 AD |
497 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); |
498 | ||
499 | switch (yytype) | |
500 | { | |
501 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
502 | default: | |
503 | break; | |
504 | } | |
505 | } | |
60a777aa | 506 | |
52d5733f | 507 | void |
f69a4142 | 508 | yy::]b4_parser_class_name[::yypop_ (unsigned int n) |
52d5733f | 509 | { |
617a8f12 AD |
510 | yystate_stack_.pop (n); |
511 | yysemantic_stack_.pop (n); | |
512 | yylocation_stack_.pop (n); | |
52d5733f AD |
513 | } |
514 | ||
9a1e9989 AD |
515 | std::ostream& |
516 | yy::]b4_parser_class_name[::debug_stream () const | |
517 | { | |
518 | return *yycdebug_; | |
519 | } | |
520 | ||
521 | void | |
522 | yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o) | |
523 | { | |
524 | yycdebug_ = &o; | |
525 | } | |
526 | ||
527 | ||
a3cb6248 AD |
528 | yy::]b4_parser_class_name[::debug_level_type |
529 | yy::]b4_parser_class_name[::debug_level () const | |
530 | { | |
531 | return yydebug_; | |
532 | } | |
533 | ||
534 | void | |
535 | yy::]b4_parser_class_name[::set_debug_level (debug_level_type l) | |
536 | { | |
537 | yydebug_ = l; | |
538 | } | |
539 | ||
540 | ||
72731bb7 | 541 | bool |
c5e3e510 | 542 | yy::]b4_parser_class_name[::parse () |
2b548aa6 | 543 | { |
451364ed AD |
544 | YYCDEBUG << "Starting parse" << std::endl; |
545 | ||
617a8f12 AD |
546 | yynerrs_ = 0; |
547 | yyerrstatus_ = 0; | |
4bb2bc3f | 548 | |
451364ed | 549 | /* Start. */ |
617a8f12 AD |
550 | yystate_ = 0; |
551 | yylooka_ = yyempty_; | |
451364ed AD |
552 | |
553 | ]m4_ifdef([b4_initial_action], [ | |
99880de5 AD |
554 | m4_pushdef([b4_at_dollar], [yylloc])dnl |
555 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
451364ed AD |
556 | /* User initialization code. */ |
557 | b4_initial_action | |
558 | m4_popdef([b4_dollar_dollar])dnl | |
559 | m4_popdef([b4_at_dollar])dnl | |
560 | /* Line __line__ of yacc.c. */ | |
561 | b4_syncline([@oline@], [@ofile@])])dnl | |
562 | ||
563 | [ /* Initialize the stacks. The initial state will be pushed in | |
3ae831b4 AD |
564 | yynewstate, since the latter expects the semantical and the |
565 | location values to have been already stored, initialize these | |
566 | stacks with a primary value. */ | |
99880de5 AD |
567 | yystate_stack_ = state_stack (0); |
568 | yysemantic_stack_ = semantic_stack (0); | |
569 | yylocation_stack_ = location_stack (0); | |
570 | yysemantic_stack_.push (yylval); | |
571 | yylocation_stack_.push (yylloc); | |
2b548aa6 RA |
572 | |
573 | /* New state. */ | |
52d5733f | 574 | yynewstate: |
617a8f12 AD |
575 | yystate_stack_.push (yystate_); |
576 | YYCDEBUG << "Entering state " << yystate_ << std::endl; | |
50997c6e | 577 | goto yybackup; |
2b548aa6 RA |
578 | |
579 | /* Backup. */ | |
52d5733f | 580 | yybackup: |
2b548aa6 | 581 | |
8dd162d3 | 582 | /* Try to take a decision without look-ahead. */ |
617a8f12 AD |
583 | yyn_ = yypact_[yystate_]; |
584 | if (yyn_ == yypact_ninf_) | |
2b548aa6 RA |
585 | goto yydefault; |
586 | ||
8dd162d3 | 587 | /* Read a look-ahead token. */ |
617a8f12 | 588 | if (yylooka_ == yyempty_) |
2e1f5829 | 589 | yylex_ (); |
2b548aa6 RA |
590 | |
591 | /* Convert token to internal form. */ | |
617a8f12 | 592 | if (yylooka_ <= yyeof_) |
2b548aa6 | 593 | { |
617a8f12 | 594 | yylooka_ = yyilooka_ = yyeof_; |
717be197 | 595 | YYCDEBUG << "Now at end of input." << std::endl; |
2b548aa6 RA |
596 | } |
597 | else | |
598 | { | |
617a8f12 | 599 | yyilooka_ = yytranslate_ (yylooka_); |
99880de5 | 600 | YY_SYMBOL_PRINT ("Next token is", yyilooka_, &yylval, &yylloc); |
2b548aa6 RA |
601 | } |
602 | ||
a5eb1ed2 | 603 | /* If the proper action on seeing token ILOOKA_ is to reduce or to |
47301314 | 604 | detect an error, take that action. */ |
617a8f12 AD |
605 | yyn_ += yyilooka_; |
606 | if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yyilooka_) | |
2b548aa6 RA |
607 | goto yydefault; |
608 | ||
609 | /* Reduce or error. */ | |
617a8f12 AD |
610 | yyn_ = yytable_[yyn_]; |
611 | if (yyn_ < 0) | |
2b548aa6 | 612 | { |
617a8f12 | 613 | if (yyn_ == yytable_ninf_) |
2b548aa6 RA |
614 | goto yyerrlab; |
615 | else | |
616 | { | |
617a8f12 | 617 | yyn_ = -yyn_; |
2b548aa6 RA |
618 | goto yyreduce; |
619 | } | |
620 | } | |
617a8f12 | 621 | else if (yyn_ == 0) |
2b548aa6 | 622 | goto yyerrlab; |
a75c057f | 623 | |
2b548aa6 | 624 | /* Accept? */ |
617a8f12 | 625 | if (yyn_ == yyfinal_) |
2b548aa6 RA |
626 | goto yyacceptlab; |
627 | ||
8dd162d3 | 628 | /* Shift the look-ahead token. */ |
99880de5 | 629 | YY_SYMBOL_PRINT ("Shifting", yyilooka_, &yylval, &yylloc); |
2b548aa6 RA |
630 | |
631 | /* Discard the token being shifted unless it is eof. */ | |
617a8f12 AD |
632 | if (yylooka_ != yyeof_) |
633 | yylooka_ = yyempty_; | |
2b548aa6 | 634 | |
99880de5 AD |
635 | yysemantic_stack_.push (yylval); |
636 | yylocation_stack_.push (yylloc); | |
8d69a1a3 RA |
637 | |
638 | /* Count tokens shifted since error; after three, turn off error | |
639 | status. */ | |
617a8f12 AD |
640 | if (yyerrstatus_) |
641 | --yyerrstatus_; | |
8d69a1a3 | 642 | |
617a8f12 | 643 | yystate_ = yyn_; |
2b548aa6 RA |
644 | goto yynewstate; |
645 | ||
47301314 AD |
646 | /*-----------------------------------------------------------. |
647 | | yydefault -- do the default action for the current state. | | |
648 | `-----------------------------------------------------------*/ | |
52d5733f | 649 | yydefault: |
617a8f12 AD |
650 | yyn_ = yydefact_[yystate_]; |
651 | if (yyn_ == 0) | |
2b548aa6 | 652 | goto yyerrlab; |
50997c6e | 653 | goto yyreduce; |
2b548aa6 | 654 | |
47301314 AD |
655 | /*-----------------------------. |
656 | | yyreduce -- Do a reduction. | | |
657 | `-----------------------------*/ | |
52d5733f | 658 | yyreduce: |
617a8f12 | 659 | yylen_ = yyr2_[yyn_]; |
47301314 AD |
660 | /* If LEN_ is nonzero, implement the default value of the action: |
661 | `$$ = $1'. Otherwise, use the top of the stack. | |
662 | ||
663 | Otherwise, the following line sets YYVAL to garbage. | |
664 | This behavior is undocumented and Bison | |
665 | users should not rely upon it. */ | |
617a8f12 AD |
666 | if (yylen_) |
667 | yyval = yysemantic_stack_[yylen_ - 1]; | |
50997c6e | 668 | else |
617a8f12 | 669 | yyval = yysemantic_stack_[0]; |
2b548aa6 | 670 | |
b4a20338 | 671 | { |
99880de5 | 672 | slice<location_type, location_stack> slice (yylocation_stack_, yylen_); |
617a8f12 | 673 | YYLLOC_DEFAULT (yyloc, slice, yylen_); |
b4a20338 | 674 | } |
617a8f12 AD |
675 | YY_REDUCE_PRINT (yyn_); |
676 | switch (yyn_) | |
45119f04 | 677 | { |
c5e3e510 | 678 | ]b4_actions[ |
45119f04 | 679 | } |
a75c057f | 680 | |
996b1c7e | 681 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 682 | b4_syncline([@oline@], [@ofile@])[ |
06446ccf | 683 | |
617a8f12 | 684 | yypop_ (yylen_); |
2b548aa6 | 685 | |
25f66e1a | 686 | YY_STACK_PRINT (); |
a75c057f | 687 | |
617a8f12 AD |
688 | yysemantic_stack_.push (yyval); |
689 | yylocation_stack_.push (yyloc); | |
2b548aa6 RA |
690 | |
691 | /* Shift the result of the reduction. */ | |
617a8f12 AD |
692 | yyn_ = yyr1_[yyn_]; |
693 | yystate_ = yypgoto_[yyn_ - yyntokens_] + yystate_stack_[0]; | |
694 | if (0 <= yystate_ && yystate_ <= yylast_ | |
695 | && yycheck_[yystate_] == yystate_stack_[0]) | |
696 | yystate_ = yytable_[yystate_]; | |
2b548aa6 | 697 | else |
617a8f12 | 698 | yystate_ = yydefgoto_[yyn_ - yyntokens_]; |
2b548aa6 RA |
699 | goto yynewstate; |
700 | ||
47301314 AD |
701 | /*------------------------------------. |
702 | | yyerrlab -- here on detecting error | | |
703 | `------------------------------------*/ | |
284acc8b | 704 | yyerrlab: |
4bb2bc3f | 705 | /* If not already recovering from an error, report this error. */ |
f69a4142 | 706 | yyreport_syntax_error_ (); |
a75c057f | 707 | |
99880de5 | 708 | yyerror_range_[0] = yylloc; |
617a8f12 | 709 | if (yyerrstatus_ == 3) |
762a801e | 710 | { |
8dd162d3 | 711 | /* If just tried and failed to reuse look-ahead token after an |
762a801e RA |
712 | error, discard it. */ |
713 | ||
714 | /* Return failure if at end of input. */ | |
617a8f12 | 715 | if (yylooka_ <= yyeof_) |
47301314 AD |
716 | { |
717 | /* If at end of input, pop the error token, | |
718 | then the rest of the stack, then return failure. */ | |
617a8f12 | 719 | if (yylooka_ == yyeof_) |
47301314 AD |
720 | for (;;) |
721 | { | |
617a8f12 | 722 | yyerror_range_[0] = yylocation_stack_[0]; |
f69a4142 | 723 | yypop_ (); |
617a8f12 | 724 | if (yystate_stack_.height () == 1) |
47301314 | 725 | YYABORT; |
f69a4142 | 726 | yydestruct_ ("Error: popping", |
617a8f12 AD |
727 | yystos_[yystate_stack_[0]], |
728 | &yysemantic_stack_[0], | |
729 | &yylocation_stack_[0]); | |
47301314 AD |
730 | } |
731 | } | |
732 | else | |
733 | { | |
99880de5 | 734 | yydestruct_ ("Error: discarding", yyilooka_, &yylval, &yylloc); |
617a8f12 | 735 | yylooka_ = yyempty_; |
47301314 | 736 | } |
762a801e RA |
737 | } |
738 | ||
8dd162d3 | 739 | /* Else will try to reuse look-ahead token after shifting the error |
762a801e | 740 | token. */ |
47301314 AD |
741 | goto yyerrlab1; |
742 | ||
743 | ||
744 | /*---------------------------------------------------. | |
745 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
746 | `---------------------------------------------------*/ | |
747 | yyerrorlab: | |
748 | ||
62b6aef9 AD |
749 | #ifdef __GNUC__ |
750 | /* Pacify GCC when the user code never invokes YYERROR and the label | |
751 | yyerrorlab therefore never appears in user code. */ | |
752 | if (0) | |
753 | goto yyerrorlab; | |
754 | #endif | |
755 | ||
617a8f12 AD |
756 | yyerror_range_[0] = yylocation_stack_[yylen_ - 1]; |
757 | yypop_ (yylen_); | |
758 | yystate_ = yystate_stack_[0]; | |
47301314 | 759 | goto yyerrlab1; |
762a801e | 760 | |
47301314 AD |
761 | /*-------------------------------------------------------------. |
762 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
763 | `-------------------------------------------------------------*/ | |
764 | yyerrlab1: | |
617a8f12 | 765 | yyerrstatus_ = 3; /* Each real token shifted decrements this. */ |
762a801e | 766 | |
769b430f AD |
767 | for (;;) |
768 | { | |
617a8f12 AD |
769 | yyn_ = yypact_[yystate_]; |
770 | if (yyn_ != yypact_ninf_) | |
769b430f | 771 | { |
617a8f12 AD |
772 | yyn_ += yyterror_; |
773 | if (0 <= yyn_ && yyn_ <= yylast_ && yycheck_[yyn_] == yyterror_) | |
769b430f | 774 | { |
617a8f12 AD |
775 | yyn_ = yytable_[yyn_]; |
776 | if (0 < yyn_) | |
769b430f AD |
777 | break; |
778 | } | |
779 | } | |
780 | ||
781 | /* Pop the current state because it cannot handle the error token. */ | |
617a8f12 | 782 | if (yystate_stack_.height () == 1) |
47301314 | 783 | YYABORT; |
762a801e | 784 | |
617a8f12 | 785 | yyerror_range_[0] = yylocation_stack_[0]; |
f69a4142 | 786 | yydestruct_ ("Error: popping", |
617a8f12 AD |
787 | yystos_[yystate_], |
788 | &yysemantic_stack_[0], &yylocation_stack_[0]); | |
f69a4142 | 789 | yypop_ (); |
617a8f12 | 790 | yystate_ = yystate_stack_[0]; |
25f66e1a | 791 | YY_STACK_PRINT (); |
762a801e | 792 | } |
762a801e | 793 | |
617a8f12 | 794 | if (yyn_ == yyfinal_) |
762a801e RA |
795 | goto yyacceptlab; |
796 | ||
99880de5 AD |
797 | yyerror_range_[1] = yylloc; |
798 | // Using YYLLOC is tempting, but would change the location of | |
3fc16193 | 799 | // the look-ahead. YYLOC is available though. |
617a8f12 | 800 | YYLLOC_DEFAULT (yyloc, yyerror_range_ - 1, 2); |
99880de5 | 801 | yysemantic_stack_.push (yylval); |
617a8f12 | 802 | yylocation_stack_.push (yyloc); |
762a801e | 803 | |
1576d44d | 804 | /* Shift the error token. */ |
617a8f12 AD |
805 | YY_SYMBOL_PRINT ("Shifting", yystos_[yyn_], |
806 | &yysemantic_stack_[0], &yylocation_stack_[0]); | |
1576d44d | 807 | |
617a8f12 | 808 | yystate_ = yyn_; |
762a801e RA |
809 | goto yynewstate; |
810 | ||
2b548aa6 | 811 | /* Accept. */ |
284acc8b | 812 | yyacceptlab: |
2b548aa6 | 813 | return 0; |
762a801e RA |
814 | |
815 | /* Abort. */ | |
284acc8b | 816 | yyabortlab: |
e757bb10 | 817 | /* Free the lookahead. */ |
99880de5 | 818 | yydestruct_ ("Error: discarding lookahead", yyilooka_, &yylval, &yylloc); |
617a8f12 | 819 | yylooka_ = yyempty_; |
762a801e | 820 | return 1; |
2b548aa6 RA |
821 | } |
822 | ||
69e2658b | 823 | void |
2e1f5829 | 824 | yy::]b4_parser_class_name[::yylex_ () |
69e2658b | 825 | { |
2e1f5829 | 826 | YYCDEBUG << "Reading a token: "; |
69e2658b | 827 | #if YYLSP_NEEDED |
99880de5 | 828 | yylooka_ = yylex (&yylval, &yylloc); |
69e2658b | 829 | #else |
99880de5 | 830 | yylooka_ = yylex (&yylval); |
69e2658b RA |
831 | #endif |
832 | } | |
833 | ||
f69a4142 | 834 | // Generate an error message, and invoke error. |
a08460b0 | 835 | void |
f69a4142 | 836 | yy::]b4_parser_class_name[::yyreport_syntax_error_ () |
a08460b0 AD |
837 | { |
838 | /* If not already recovering from an error, report this error. */ | |
617a8f12 | 839 | if (!yyerrstatus_) |
a08460b0 | 840 | { |
617a8f12 | 841 | ++yynerrs_; |
efeed023 | 842 | std::string message; |
a08460b0 | 843 | #if YYERROR_VERBOSE |
617a8f12 AD |
844 | yyn_ = yypact_[yystate_]; |
845 | if (yypact_ninf_ < yyn_ && yyn_ < yylast_) | |
a08460b0 | 846 | { |
fd19f271 AD |
847 | /* Start YYX at -YYN if negative to avoid negative indexes in |
848 | YYCHECK. */ | |
849 | int yyxbegin = yyn_ < 0 ? -yyn_ : 0; | |
850 | ||
851 | /* Stay within bounds of both yycheck and yytname. */ | |
852 | int yychecklim = yylast_ - yyn_; | |
853 | int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; | |
854 | int count = 0; | |
855 | for (int x = yyxbegin; x < yyxend; ++x) | |
856 | if (yycheck_[x + yyn_] == x && x != yyterror_) | |
857 | ++count; | |
858 | ||
a08460b0 | 859 | message = "syntax error, unexpected "; |
617a8f12 | 860 | message += yyname_[yyilooka_]; |
fd19f271 AD |
861 | if (count < 5) |
862 | { | |
863 | count = 0; | |
864 | for (int x = yyxbegin; x < yyxend; ++x) | |
865 | if (yycheck_[x + yyn_] == x && x != yyterror_) | |
866 | { | |
867 | message += (!count++) ? ", expecting " : " or "; | |
868 | message += yyname_[x]; | |
869 | } | |
870 | } | |
a08460b0 AD |
871 | } |
872 | else | |
873 | #endif | |
874 | message = "syntax error"; | |
99880de5 | 875 | error (yylloc, message); |
a08460b0 AD |
876 | } |
877 | } | |
878 | ||
5348bfbe | 879 | |
c5e3e510 | 880 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
2b548aa6 | 881 | STATE-NUM. */ |
617a8f12 | 882 | const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[; |
c5e3e510 | 883 | const ]b4_int_type_for([b4_pact])[ |
617a8f12 | 884 | yy::]b4_parser_class_name[::yypact_[] = |
2b548aa6 | 885 | { |
c5e3e510 | 886 | ]b4_pact[ |
2b548aa6 RA |
887 | }; |
888 | ||
c5e3e510 | 889 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
890 | doesn't specify something else to do. Zero means the default is an |
891 | error. */ | |
c5e3e510 | 892 | const ]b4_int_type_for([b4_defact])[ |
617a8f12 | 893 | yy::]b4_parser_class_name[::yydefact_[] = |
2b548aa6 | 894 | { |
c5e3e510 | 895 | ]b4_defact[ |
2b548aa6 RA |
896 | }; |
897 | ||
c5e3e510 AD |
898 | /* YYPGOTO[NTERM-NUM]. */ |
899 | const ]b4_int_type_for([b4_pgoto])[ | |
617a8f12 | 900 | yy::]b4_parser_class_name[::yypgoto_[] = |
2b548aa6 | 901 | { |
c5e3e510 | 902 | ]b4_pgoto[ |
2b548aa6 RA |
903 | }; |
904 | ||
c5e3e510 AD |
905 | /* YYDEFGOTO[NTERM-NUM]. */ |
906 | const ]b4_int_type_for([b4_defgoto])[ | |
617a8f12 | 907 | yy::]b4_parser_class_name[::yydefgoto_[] = |
2b548aa6 | 908 | { |
c5e3e510 | 909 | ]b4_defgoto[ |
2b548aa6 RA |
910 | }; |
911 | ||
c5e3e510 | 912 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
913 | positive, shift that token. If negative, reduce the rule which |
914 | number is the opposite. If zero, do what YYDEFACT says. */ | |
617a8f12 | 915 | const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[; |
c5e3e510 | 916 | const ]b4_int_type_for([b4_table])[ |
617a8f12 | 917 | yy::]b4_parser_class_name[::yytable_[] = |
2b548aa6 | 918 | { |
c5e3e510 | 919 | ]b4_table[ |
2b548aa6 RA |
920 | }; |
921 | ||
922 | /* YYCHECK. */ | |
c5e3e510 | 923 | const ]b4_int_type_for([b4_check])[ |
617a8f12 | 924 | yy::]b4_parser_class_name[::yycheck_[] = |
2b548aa6 | 925 | { |
c5e3e510 | 926 | ]b4_check[ |
2b548aa6 RA |
927 | }; |
928 | ||
c5e3e510 | 929 | /* STOS_[STATE-NUM] -- The (internal number of the) accessing |
769b430f | 930 | symbol of state STATE-NUM. */ |
c5e3e510 | 931 | const ]b4_int_type_for([b4_stos])[ |
617a8f12 | 932 | yy::]b4_parser_class_name[::yystos_[] = |
769b430f | 933 | { |
c5e3e510 | 934 | ]b4_stos[ |
769b430f AD |
935 | }; |
936 | ||
45d5982f | 937 | #if YYDEBUG |
617a8f12 | 938 | /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding |
769b430f | 939 | to YYLEX-NUM. */ |
c5e3e510 | 940 | const ]b4_int_type_for([b4_toknum])[ |
617a8f12 | 941 | yy::]b4_parser_class_name[::yytoken_number_[] = |
769b430f | 942 | { |
c5e3e510 | 943 | ]b4_toknum[ |
769b430f AD |
944 | }; |
945 | #endif | |
946 | ||
c5e3e510 AD |
947 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
948 | const ]b4_int_type_for([b4_r1])[ | |
617a8f12 | 949 | yy::]b4_parser_class_name[::yyr1_[] = |
2b548aa6 | 950 | { |
c5e3e510 | 951 | ]b4_r1[ |
2b548aa6 RA |
952 | }; |
953 | ||
c5e3e510 AD |
954 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
955 | const ]b4_int_type_for([b4_r2])[ | |
617a8f12 | 956 | yy::]b4_parser_class_name[::yyr2_[] = |
2b548aa6 | 957 | { |
c5e3e510 | 958 | ]b4_r2[ |
2b548aa6 RA |
959 | }; |
960 | ||
69e2658b | 961 | #if YYDEBUG || YYERROR_VERBOSE |
c5e3e510 | 962 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
617a8f12 | 963 | First, the terminals, then, starting at \a yyntokens_, nonterminals. */ |
2b548aa6 | 964 | const char* |
617a8f12 | 965 | const yy::]b4_parser_class_name[::yyname_[] = |
2b548aa6 | 966 | { |
c5e3e510 | 967 | ]b4_tname[ |
2b548aa6 | 968 | }; |
69e2658b | 969 | #endif |
2b548aa6 | 970 | |
69e2658b | 971 | #if YYDEBUG |
2b548aa6 | 972 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
99880de5 | 973 | const yy::]b4_parser_class_name[::rhs_number_type |
617a8f12 | 974 | yy::]b4_parser_class_name[::yyrhs_[] = |
2b548aa6 | 975 | { |
c5e3e510 | 976 | ]b4_rhs[ |
2b548aa6 RA |
977 | }; |
978 | ||
c5e3e510 | 979 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 980 | YYRHS. */ |
c5e3e510 | 981 | const ]b4_int_type_for([b4_prhs])[ |
617a8f12 | 982 | yy::]b4_parser_class_name[::yyprhs_[] = |
2b548aa6 | 983 | { |
c5e3e510 | 984 | ]b4_prhs[ |
2b548aa6 RA |
985 | }; |
986 | ||
617a8f12 | 987 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
c5e3e510 | 988 | const ]b4_int_type_for([b4_rline])[ |
617a8f12 | 989 | yy::]b4_parser_class_name[::yyrline_[] = |
69e2658b | 990 | { |
c5e3e510 | 991 | ]b4_rline[ |
69e2658b | 992 | }; |
5348bfbe | 993 | |
617a8f12 | 994 | // Print the state stack on the debug stream. |
25f66e1a | 995 | void |
f69a4142 | 996 | yy::]b4_parser_class_name[::yystack_print_ () |
25f66e1a | 997 | { |
9a1e9989 | 998 | *yycdebug_ << "Stack now"; |
99880de5 | 999 | for (state_stack::const_iterator i = yystate_stack_.begin (); |
617a8f12 | 1000 | i != yystate_stack_.end (); ++i) |
9a1e9989 AD |
1001 | *yycdebug_ << ' ' << *i; |
1002 | *yycdebug_ << std::endl; | |
25f66e1a AD |
1003 | } |
1004 | ||
617a8f12 | 1005 | // Report on the debug stream that the rule \a yyrule is going to be reduced. |
5348bfbe | 1006 | void |
f69a4142 | 1007 | yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule) |
5348bfbe | 1008 | { |
617a8f12 | 1009 | unsigned int yylno = yyrline_[yyrule]; |
5348bfbe | 1010 | /* Print the symbols being reduced, and their result. */ |
617a8f12 | 1011 | *yycdebug_ << "Reducing stack by rule " << yyn_ - 1 |
9a1e9989 | 1012 | << " (line " << yylno << "), "; |
617a8f12 AD |
1013 | for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyn_]; |
1014 | 0 <= yyrhs_[i]; ++i) | |
1015 | *yycdebug_ << yyname_[yyrhs_[i]] << ' '; | |
1016 | *yycdebug_ << "-> " << yyname_[yyr1_[yyn_]] << std::endl; | |
5348bfbe AD |
1017 | } |
1018 | #endif // YYDEBUG | |
69e2658b | 1019 | |
2b548aa6 | 1020 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
99880de5 | 1021 | yy::]b4_parser_class_name[::token_number_type |
f69a4142 | 1022 | yy::]b4_parser_class_name[::yytranslate_ (int token) |
2b548aa6 | 1023 | { |
a75c057f | 1024 | static |
99880de5 | 1025 | const token_number_type |
1d4055aa | 1026 | translate_table[] = |
2b548aa6 | 1027 | { |
c5e3e510 | 1028 | ]b4_translate[ |
2b548aa6 | 1029 | }; |
617a8f12 | 1030 | if ((unsigned int) token <= yyuser_token_number_max_) |
1d4055aa | 1031 | return translate_table[token]; |
007a50a4 | 1032 | else |
617a8f12 | 1033 | return yyundef_token_; |
2b548aa6 RA |
1034 | } |
1035 | ||
617a8f12 AD |
1036 | const int yy::]b4_parser_class_name[::yyeof_ = 0; |
1037 | const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[; | |
1038 | const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[; | |
1039 | const int yy::]b4_parser_class_name[::yyempty_ = -2; | |
1040 | const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[; | |
1041 | const int yy::]b4_parser_class_name[::yyterror_ = 1; | |
1042 | const int yy::]b4_parser_class_name[::yyerrcode_ = 256; | |
1043 | const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[; | |
1044 | ||
1045 | const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[; | |
99880de5 | 1046 | const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[; |
2b548aa6 | 1047 | |
c5e3e510 | 1048 | ]b4_epilogue |
21846f69 | 1049 | dnl |
6ad762a8 | 1050 | @output stack.hh |
99880de5 | 1051 | b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004])[ |
98254360 | 1052 | |
2b548aa6 RA |
1053 | #ifndef BISON_STACK_HH |
1054 | # define BISON_STACK_HH | |
1055 | ||
45119f04 | 1056 | #include <deque> |
2b548aa6 RA |
1057 | |
1058 | namespace yy | |
1059 | { | |
f85a5e6f | 1060 | template <class T, class S = std::deque<T> > |
99880de5 | 1061 | class stack |
2b548aa6 RA |
1062 | { |
1063 | public: | |
1064 | ||
ecfe33e7 AD |
1065 | // Hide our reversed order. |
1066 | typedef typename S::reverse_iterator iterator; | |
1067 | typedef typename S::const_reverse_iterator const_iterator; | |
2b548aa6 | 1068 | |
99880de5 | 1069 | stack () : seq_ () |
2b548aa6 RA |
1070 | { |
1071 | } | |
1072 | ||
99880de5 | 1073 | stack (unsigned int n) : seq_ (n) |
2b548aa6 RA |
1074 | { |
1075 | } | |
1076 | ||
1077 | inline | |
1078 | T& | |
779e7ceb | 1079 | operator [] (unsigned int i) |
2b548aa6 | 1080 | { |
1d4055aa | 1081 | return seq_[i]; |
2b548aa6 RA |
1082 | } |
1083 | ||
1084 | inline | |
1085 | const T& | |
779e7ceb | 1086 | operator [] (unsigned int i) const |
2b548aa6 | 1087 | { |
1d4055aa | 1088 | return seq_[i]; |
2b548aa6 RA |
1089 | } |
1090 | ||
1091 | inline | |
1092 | void | |
1093 | push (const T& t) | |
1094 | { | |
45119f04 | 1095 | seq_.push_front (t); |
2b548aa6 RA |
1096 | } |
1097 | ||
1098 | inline | |
1099 | void | |
779e7ceb | 1100 | pop (unsigned int n = 1) |
2b548aa6 RA |
1101 | { |
1102 | for (; n; --n) | |
45119f04 | 1103 | seq_.pop_front (); |
2b548aa6 RA |
1104 | } |
1105 | ||
762a801e | 1106 | inline |
779e7ceb | 1107 | unsigned int |
762a801e RA |
1108 | height () const |
1109 | { | |
1110 | return seq_.size (); | |
1111 | } | |
1112 | ||
ecfe33e7 AD |
1113 | inline const_iterator begin () const { return seq_.rbegin (); } |
1114 | inline const_iterator end () const { return seq_.rend (); } | |
2b548aa6 RA |
1115 | |
1116 | private: | |
1117 | ||
1118 | S seq_; | |
1119 | }; | |
374f5a14 | 1120 | |
99880de5 AD |
1121 | template <class T, class S = stack<T> > |
1122 | class slice | |
374f5a14 RA |
1123 | { |
1124 | public: | |
1125 | ||
99880de5 | 1126 | slice (const S& stack, |
779e7ceb PE |
1127 | unsigned int range) : stack_ (stack), |
1128 | range_ (range) | |
374f5a14 RA |
1129 | { |
1130 | } | |
1131 | ||
1132 | inline | |
1133 | const T& | |
779e7ceb | 1134 | operator [] (unsigned int i) const |
374f5a14 | 1135 | { |
1d4055aa | 1136 | return stack_[range_ - i]; |
374f5a14 RA |
1137 | } |
1138 | ||
1139 | private: | |
1140 | ||
1141 | const S& stack_; | |
779e7ceb | 1142 | unsigned int range_; |
374f5a14 | 1143 | }; |
2b548aa6 RA |
1144 | } |
1145 | ||
c5e3e510 | 1146 | #endif // not BISON_STACK_HH] |
21846f69 | 1147 | dnl |
5d003116 | 1148 | @output position.hh |
779e7ceb | 1149 | b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004])[ |
98254360 | 1150 | |
5d003116 AD |
1151 | /** |
1152 | ** \file position.hh | |
99880de5 | 1153 | ** Define the position class. |
5d003116 AD |
1154 | */ |
1155 | ||
1156 | #ifndef BISON_POSITION_HH | |
1157 | # define BISON_POSITION_HH | |
2b548aa6 | 1158 | |
7548fed2 AD |
1159 | # include <iostream> |
1160 | # include <string> | |
1161 | ||
2b548aa6 RA |
1162 | namespace yy |
1163 | { | |
99880de5 AD |
1164 | /// Abstract a position. |
1165 | class position | |
2b548aa6 | 1166 | { |
7548fed2 | 1167 | public: |
f69a4142 | 1168 | /// Initial column number. |
5d003116 | 1169 | static const unsigned int initial_column = 0; |
f69a4142 | 1170 | /// Initial line number. |
5d003116 AD |
1171 | static const unsigned int initial_line = 1; |
1172 | ||
1173 | /** \name Ctor & dtor. | |
1174 | ** \{ */ | |
1175 | public: | |
99880de5 AD |
1176 | /// Construct a position. |
1177 | position () : | |
9a0d8bec | 1178 | filename (0), |
5d003116 AD |
1179 | line (initial_line), |
1180 | column (initial_column) | |
1181 | { | |
1182 | } | |
1183 | /** \} */ | |
1184 | ||
7548fed2 | 1185 | |
5d003116 AD |
1186 | /** \name Line and Column related manipulators |
1187 | ** \{ */ | |
1188 | public: | |
f69a4142 | 1189 | /// (line related) Advance to the COUNT next lines. |
2ffbee0e | 1190 | inline void lines (int count = 1) |
5d003116 AD |
1191 | { |
1192 | column = initial_column; | |
2ffbee0e | 1193 | line += count; |
5d003116 AD |
1194 | } |
1195 | ||
f69a4142 | 1196 | /// (column related) Advance to the COUNT next columns. |
2ffbee0e | 1197 | inline void columns (int count = 1) |
5d003116 | 1198 | { |
f939fc12 AD |
1199 | int leftmost = initial_column; |
1200 | int current = column; | |
2ffbee0e PE |
1201 | if (leftmost <= current + count) |
1202 | column += count; | |
2cdc240e AD |
1203 | else |
1204 | column = initial_column; | |
5d003116 AD |
1205 | } |
1206 | /** \} */ | |
1207 | ||
1208 | public: | |
f69a4142 | 1209 | /// File name to which this position refers. |
9a0d8bec | 1210 | ]b4_filename_type[* filename; |
f69a4142 | 1211 | /// Current line number. |
5d003116 | 1212 | unsigned int line; |
f69a4142 | 1213 | /// Current column number. |
5d003116 | 1214 | unsigned int column; |
2b548aa6 RA |
1215 | }; |
1216 | ||
99880de5 AD |
1217 | /// Add and assign a position. |
1218 | inline const position& | |
1219 | operator+= (position& res, const int width) | |
5d003116 AD |
1220 | { |
1221 | res.columns (width); | |
1222 | return res; | |
1223 | } | |
1224 | ||
99880de5 AD |
1225 | /// Add two position objects. |
1226 | inline const position | |
1227 | operator+ (const position& begin, const int width) | |
5d003116 | 1228 | { |
99880de5 | 1229 | position res = begin; |
5d003116 AD |
1230 | return res += width; |
1231 | } | |
1232 | ||
99880de5 AD |
1233 | /// Add and assign a position. |
1234 | inline const position& | |
1235 | operator-= (position& res, const int width) | |
5d003116 AD |
1236 | { |
1237 | return res += -width; | |
1238 | } | |
1239 | ||
99880de5 AD |
1240 | /// Add two position objects. |
1241 | inline const position | |
1242 | operator- (const position& begin, const int width) | |
5d003116 AD |
1243 | { |
1244 | return begin + -width; | |
1245 | } | |
1246 | ||
1247 | /** \brief Intercept output stream redirection. | |
1248 | ** \param ostr the destination output stream | |
99880de5 | 1249 | ** \param pos a reference to the position to redirect |
5d003116 | 1250 | */ |
7548fed2 | 1251 | inline std::ostream& |
99880de5 | 1252 | operator<< (std::ostream& ostr, const position& pos) |
7548fed2 | 1253 | { |
9a0d8bec AD |
1254 | if (pos.filename) |
1255 | ostr << *pos.filename << ':'; | |
5d003116 | 1256 | return ostr << pos.line << '.' << pos.column; |
7548fed2 AD |
1257 | } |
1258 | ||
5d003116 AD |
1259 | } |
1260 | #endif // not BISON_POSITION_HH] | |
1261 | @output location.hh | |
779e7ceb | 1262 | b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004])[ |
7548fed2 | 1263 | |
5d003116 AD |
1264 | /** |
1265 | ** \file location.hh | |
99880de5 | 1266 | ** Define the location class. |
5d003116 | 1267 | */ |
7548fed2 | 1268 | |
5d003116 AD |
1269 | #ifndef BISON_LOCATION_HH |
1270 | # define BISON_LOCATION_HH | |
1271 | ||
1272 | # include <iostream> | |
1273 | # include <string> | |
1274 | # include "position.hh" | |
1275 | ||
1276 | namespace yy | |
1277 | { | |
1278 | ||
99880de5 AD |
1279 | /// Abstract a location. |
1280 | class location | |
2b548aa6 | 1281 | { |
5d003116 AD |
1282 | /** \name Ctor & dtor. |
1283 | ** \{ */ | |
7548fed2 | 1284 | public: |
99880de5 AD |
1285 | /// Construct a location. |
1286 | location (void) : | |
5d003116 AD |
1287 | begin (), |
1288 | end () | |
1289 | { | |
1290 | } | |
1291 | /** \} */ | |
1292 | ||
1293 | ||
1294 | /** \name Line and Column related manipulators | |
1295 | ** \{ */ | |
1296 | public: | |
f69a4142 | 1297 | /// Reset initial location to final location. |
5d003116 AD |
1298 | inline void step (void) |
1299 | { | |
1300 | begin = end; | |
1301 | } | |
1302 | ||
f69a4142 | 1303 | /// Extend the current location to the COUNT next columns. |
2ffbee0e | 1304 | inline void columns (unsigned int count = 1) |
5d003116 | 1305 | { |
2ffbee0e | 1306 | end += count; |
5d003116 AD |
1307 | } |
1308 | ||
f69a4142 | 1309 | /// Extend the current location to the COUNT next lines. |
2ffbee0e | 1310 | inline void lines (unsigned int count = 1) |
5d003116 | 1311 | { |
2ffbee0e | 1312 | end.lines (count); |
5d003116 AD |
1313 | } |
1314 | /** \} */ | |
1315 | ||
1316 | ||
1317 | public: | |
f69a4142 | 1318 | /// Beginning of the located region. |
99880de5 | 1319 | position begin; |
f69a4142 | 1320 | /// End of the located region. |
99880de5 | 1321 | position end; |
2b548aa6 | 1322 | }; |
7548fed2 | 1323 | |
99880de5 AD |
1324 | /// Join two location objects to create a location. |
1325 | inline const location operator+ (const location& begin, const location& end) | |
5d003116 | 1326 | { |
99880de5 | 1327 | location res = begin; |
5d003116 AD |
1328 | res.end = end.end; |
1329 | return res; | |
1330 | } | |
1331 | ||
99880de5 AD |
1332 | /// Add two location objects. |
1333 | inline const location operator+ (const location& begin, unsigned int width) | |
5d003116 | 1334 | { |
99880de5 | 1335 | location res = begin; |
5d003116 AD |
1336 | res.columns (width); |
1337 | return res; | |
1338 | } | |
7548fed2 | 1339 | |
99880de5 AD |
1340 | /// Add and assign a location. |
1341 | inline location& operator+= (location& res, unsigned int width) | |
5d003116 AD |
1342 | { |
1343 | res.columns (width); | |
1344 | return res; | |
1345 | } | |
1346 | ||
1347 | /** \brief Intercept output stream redirection. | |
1348 | ** \param ostr the destination output stream | |
99880de5 | 1349 | ** \param loc a reference to the location to redirect |
5d003116 | 1350 | ** |
2cdc240e | 1351 | ** Avoid duplicate information. |
5d003116 | 1352 | */ |
99880de5 | 1353 | inline std::ostream& operator<< (std::ostream& ostr, const location& loc) |
7548fed2 | 1354 | { |
99880de5 | 1355 | position last = loc.end - 1; |
2cdc240e | 1356 | ostr << loc.begin; |
9a0d8bec AD |
1357 | if (last.filename |
1358 | && (!loc.begin.filename | |
1359 | || *loc.begin.filename != *last.filename)) | |
2cdc240e AD |
1360 | ostr << '-' << last; |
1361 | else if (loc.begin.line != last.line) | |
1362 | ostr << '-' << last.line << '.' << last.column; | |
1363 | else if (loc.begin.column != last.column) | |
1364 | ostr << '-' << last.column; | |
7548fed2 AD |
1365 | return ostr; |
1366 | } | |
1367 | ||
2b548aa6 RA |
1368 | } |
1369 | ||
c5e3e510 | 1370 | #endif // not BISON_LOCATION_HH] |