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