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