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