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