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