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