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