]>
Commit | Line | Data |
---|---|---|
a75c057f AD |
1 | m4_divert(-1) |
2 | ||
680e8701 AD |
3 | # b4_sint_type(MAX) |
4 | # ----------------- | |
5 | # Return the smallest signed int type able to handle the number MAX. | |
6 | m4_define([b4_sint_type], | |
7 | [m4_if(m4_eval([$1 <= 127]), [1], [signed char], | |
8 | m4_eval([$1 <= 32767]), [1], [signed short], | |
9 | m4_eval([$1 <= 2147483647]), [1], [signed int], | |
10 | [m4_fatal([no signed int type for $1])])]) | |
11 | ||
12 | ||
13 | # b4_uint_type(MAX) | |
14 | # ----------------- | |
15 | # Return the smallest unsigned int type able to handle the number MAX. | |
16 | m4_define([b4_uint_type], | |
17 | [m4_if(m4_eval([$1 <= 255]), [1], [unsigned char], | |
18 | m4_eval([$1 <= 65535]), [1], [unsigned short], | |
19 | m4_eval([$1 <= 4294967295]), [1], [unsigned int], | |
20 | [m4_fatal([no unsigned int type for $1])])]) | |
21 | ||
22 | ||
0d8bed56 AD |
23 | # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) |
24 | # ------------------------------------------ | |
25 | # Output the definition of this token as #define. | |
26 | m4_define([b4_token_define], | |
27 | [#define $1 $2 | |
28 | ]) | |
29 | ||
30 | ||
31 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
32 | # ------------------------------------------------------- | |
33 | # Output the definition of the tokens as #define. | |
34 | m4_define([b4_token_defines], | |
35 | [m4_map([b4_token_define], [$@])]) | |
a75c057f AD |
36 | |
37 | m4_define_default([b4_input_suffix], [.y]) | |
38 | ||
39 | m4_define_default([b4_output_parser_suffix], | |
40 | [m4_translit(b4_input_suffix, [yY], [cC])]) | |
41 | ||
42 | m4_define_default([b4_output_parser_name], | |
43 | [b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]]) | |
44 | ||
45 | ||
46 | m4_define_default([b4_output_header_suffix], | |
47 | [m4_translit(b4_input_suffix, [yY], [hH])]) | |
48 | ||
49 | m4_define_default([b4_output_header_name], | |
50 | [b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]]) | |
51 | ||
52 | m4_define_default([b4_header_guard], | |
53 | [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name), | |
54 | [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) | |
55 | ||
af27eacb | 56 | m4_define([b4_inherit], |
0d8bed56 | 57 | [m4_ifdef([b4_root], |
af27eacb RA |
58 | [: public b4_root |
59 | ], | |
60 | [])]) | |
61 | ||
62 | m4_define([b4_param], | |
63 | [m4_ifdef([b4_root], | |
64 | [, | |
65 | const Param& param], | |
66 | [])]) | |
67 | ||
68 | m4_define([b4_constructor], | |
69 | [m4_ifdef([b4_root], | |
70 | [b4_root (param), | |
71 | ], | |
72 | [])]) | |
73 | ||
98254360 RA |
74 | m4_define([b4_copyright], |
75 | [/* -*- C++ -*- */ | |
69e2658b RA |
76 | /* A Bison parser, made from b4_filename, |
77 | by GNU bison b4_version. */ | |
2b548aa6 RA |
78 | |
79 | /* Skeleton output parser for bison, | |
98254360 | 80 | Copyright 2002 Free Software Foundation, Inc. |
2b548aa6 RA |
81 | |
82 | This program is free software; you can redistribute it and/or modify | |
83 | it under the terms of the GNU General Public License as published by | |
84 | the Free Software Foundation; either version 2, or (at your option) | |
85 | any later version. | |
86 | ||
87 | This program is distributed in the hope that it will be useful, | |
88 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
89 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
90 | GNU General Public License for more details. | |
91 | ||
92 | You should have received a copy of the GNU General Public License | |
93 | along with this program; if not, write to the Free Software | |
94 | Foundation, Inc., 59 Temple Place - Suite 330, | |
95 | Boston, MA 02111-1307, USA. */ | |
96 | ||
97 | /* As a special exception, when this file is copied by Bison into a | |
98 | Bison output file, you may use that output file without restriction. | |
99 | This special exception was added by the Free Software Foundation | |
98254360 RA |
100 | in version 1.24 of Bison. */]) |
101 | ||
102 | m4_divert(0)dnl | |
103 | #output "b4_output_header_name" | |
104 | b4_copyright | |
105 | #ifndef b4_header_guard | |
106 | # define b4_header_guard | |
2b548aa6 RA |
107 | |
108 | #include "stack.hh" | |
2b548aa6 RA |
109 | #include "location.hh" |
110 | ||
8d69a1a3 | 111 | #include <string> |
50997c6e | 112 | |
4162fa07 RA |
113 | /* Using locations. */ |
114 | #define YYLSP_NEEDED b4_locations_flag | |
115 | ||
116 | b4_prologue | |
117 | ||
98254360 | 118 | /* Tokens. */ |
e53c6322 | 119 | b4_token_defines(b4_tokens) |
98254360 | 120 | |
69e2658b RA |
121 | /* Enabling traces. */ |
122 | #ifndef YYDEBUG | |
123 | # define YYDEBUG b4_debug | |
124 | #endif | |
125 | ||
126 | /* Enabling verbose error message. */ | |
127 | #ifndef YYERROR_VERBOSE | |
128 | # define YYERROR_VERBOSE b4_error_verbose | |
129 | #endif | |
130 | ||
98254360 | 131 | #ifndef YYSTYPE |
642cb8f8 AD |
132 | m4_ifdef([b4_stype_line], |
133 | [#line b4_stype_line "b4_filename" | |
134 | ])dnl | |
98254360 RA |
135 | typedef b4_stype |
136 | yystype; | |
137 | # define YYSTYPE yystype | |
138 | #endif | |
139 | ||
374f5a14 RA |
140 | #ifndef YYLLOC_DEFAULT |
141 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
142 | Current.last_line = Rhs[[N]].last_line; \ | |
143 | Current.last_column = Rhs[[N]].last_column; | |
144 | #endif | |
145 | ||
98254360 RA |
146 | m4_if(b4_locations_flag, [0], [], |
147 | [#ifndef YYLTYPE | |
148 | typedef struct yyltype | |
149 | { | |
150 | int first_line; | |
151 | int first_column; | |
152 | int last_line; | |
153 | int last_column; | |
154 | } yyltype; | |
155 | # define YYLTYPE yyltype | |
156 | #endif]) | |
50997c6e | 157 | |
2b548aa6 RA |
158 | namespace yy |
159 | { | |
3f3eed27 AD |
160 | class b4_name; |
161 | ||
2b548aa6 RA |
162 | template < typename P > |
163 | struct Traits | |
164 | { | |
165 | }; | |
166 | ||
167 | template < > | |
3f3eed27 | 168 | struct Traits< b4_name > |
2b548aa6 | 169 | { |
680e8701 | 170 | typedef typedef b4_uint_type(b4_token_number_max) TokenNumberType; |
50997c6e RA |
171 | typedef int StateType; |
172 | typedef yystype SemanticType; | |
173 | typedef b4_ltype LocationType; | |
2b548aa6 RA |
174 | }; |
175 | } | |
176 | ||
2b548aa6 RA |
177 | namespace yy |
178 | { | |
af27eacb | 179 | class b4_name b4_inherit |
2b548aa6 RA |
180 | { |
181 | public: | |
3f3eed27 | 182 | |
680e8701 AD |
183 | typedef Traits< b4_name >::TokenNumberType TokenNumberType; |
184 | typedef Traits< b4_name >::StateType StateType; | |
185 | typedef Traits< b4_name >::SemanticType SemanticType; | |
186 | typedef Traits< b4_name >::LocationType LocationType; | |
2b548aa6 RA |
187 | |
188 | typedef Stack< StateType > StateStack; | |
189 | typedef Stack< SemanticType > SemanticStack; | |
190 | typedef Stack< LocationType > LocationStack; | |
191 | ||
8d69a1a3 RA |
192 | #if YYLSP_NEEDED |
193 | b4_name (bool debug, | |
0d8bed56 | 194 | LocationType initlocation[]b4_param) : |
af27eacb RA |
195 | b4_constructor[]debug_ (debug), |
196 | initlocation_ (initlocation) | |
8d69a1a3 | 197 | #else |
af27eacb RA |
198 | b4_name (bool debug[]b4_param) : |
199 | b4_constructor[]debug_ (debug) | |
8d69a1a3 | 200 | #endif |
50997c6e | 201 | { |
50997c6e RA |
202 | } |
203 | ||
204 | virtual ~b4_name () | |
2b548aa6 | 205 | { |
2b548aa6 RA |
206 | } |
207 | ||
208 | virtual int parse (); | |
209 | ||
210 | private: | |
3f3eed27 | 211 | |
69e2658b | 212 | virtual void lex_ (); |
4bb2bc3f | 213 | virtual void error_ (); |
4aacc3a7 | 214 | virtual void print_ (); |
4bb2bc3f | 215 | |
2b548aa6 | 216 | /* Stacks. */ |
69e2658b RA |
217 | StateStack state_stack_; |
218 | SemanticStack semantic_stack_; | |
219 | LocationStack location_stack_; | |
2b548aa6 RA |
220 | |
221 | /* Tables. */ | |
3f3eed27 AD |
222 | static const short pact_[[]]; |
223 | static const short defact_[[]]; | |
224 | static const short pgoto_[[]]; | |
225 | static const short defgoto_[[]]; | |
226 | static const short table_[[]]; | |
227 | static const short check_[[]]; | |
3f3eed27 AD |
228 | static const short r1_[[]]; |
229 | static const short r2_[[]]; | |
69e2658b RA |
230 | |
231 | #if YYDEBUG || YYERROR_VERBOSE | |
3f3eed27 | 232 | static const char* const name_[[]]; |
69e2658b | 233 | #endif |
2b548aa6 RA |
234 | |
235 | /* More tables, for debugging. */ | |
69e2658b | 236 | #if YYDEBUG |
3f3eed27 AD |
237 | static const short rhs_[[]]; |
238 | static const short prhs_[[]]; | |
239 | static const short rline_[[]]; | |
69e2658b | 240 | #endif |
2b548aa6 RA |
241 | |
242 | /* Even more tables. */ | |
680e8701 | 243 | static inline TokenNumberType translate_ (int token); |
2b548aa6 | 244 | |
762a801e | 245 | /* Constants. */ |
50997c6e | 246 | static const int eof_; |
69e2658b RA |
247 | static const int last_; |
248 | static const int flag_; | |
249 | static const int nnts_; | |
250 | static const int nsym_; | |
50997c6e | 251 | static const int empty_; |
69e2658b | 252 | static const int final_; |
762a801e RA |
253 | static const int terror_; |
254 | static const int errcode_; | |
50997c6e | 255 | static const int ntokens_; |
69e2658b RA |
256 | static const int initdepth_; |
257 | static const unsigned maxtok_; | |
2b548aa6 RA |
258 | |
259 | /* State. */ | |
69e2658b RA |
260 | int n_; |
261 | int len_; | |
50997c6e | 262 | int debug_; |
69e2658b | 263 | int state_; |
4bb2bc3f | 264 | |
69e2658b RA |
265 | /* Lookahead and lookahead in internal form. */ |
266 | int looka_; | |
267 | int ilooka_; | |
4bb2bc3f RA |
268 | |
269 | /* Message. */ | |
270 | std::string message; | |
271 | ||
374f5a14 | 272 | /* Semantic value and location of lookahead token. */ |
2b548aa6 RA |
273 | SemanticType value; |
274 | LocationType location; | |
8d69a1a3 | 275 | |
374f5a14 RA |
276 | /* @$ and $$. */ |
277 | SemanticType yyval; | |
278 | LocationType yyloc; | |
279 | ||
8d69a1a3 RA |
280 | /* Initial location. */ |
281 | LocationType initlocation_; | |
2b548aa6 RA |
282 | }; |
283 | } | |
284 | ||
98254360 RA |
285 | #endif /* not b4_header_guard */ |
286 | ||
3f3eed27 | 287 | #output "b4_output_prefix[]b4_output_infix[].cc" |
98254360 RA |
288 | b4_copyright |
289 | ||
290 | #include "b4_output_header_name" | |
50997c6e | 291 | |
2b548aa6 | 292 | /* Enable debugging if requested. */ |
50997c6e | 293 | #if YYDEBUG |
2b548aa6 RA |
294 | # include <cstdio> |
295 | # define YYFPRINTF std::fprintf | |
2b548aa6 RA |
296 | # define YYDPRINTF(Args) \ |
297 | do { \ | |
50997c6e | 298 | if (debug_) \ |
2b548aa6 RA |
299 | YYFPRINTF Args; \ |
300 | } while (0) | |
2b548aa6 RA |
301 | #else /* !YYDEBUG */ |
302 | # define YYDPRINTF(Args) | |
303 | #endif /* !YYDEBUG */ | |
304 | ||
2b548aa6 | 305 | int |
3f3eed27 | 306 | yy::b4_name::parse () |
2b548aa6 | 307 | { |
4bb2bc3f RA |
308 | int nerrs = 0; |
309 | int errstatus = 0; | |
310 | ||
2b548aa6 | 311 | /* Initialize stack. */ |
69e2658b RA |
312 | state_stack_ = StateStack (0); |
313 | semantic_stack_ = SemanticStack (1); | |
314 | location_stack_ = LocationStack (1); | |
2b548aa6 RA |
315 | |
316 | /* Reserve initial space. The C parser needed that, but is it really | |
317 | useful here? */ | |
69e2658b RA |
318 | state_stack_.reserve (initdepth_); |
319 | semantic_stack_.reserve (initdepth_); | |
320 | location_stack_.reserve (initdepth_); | |
2b548aa6 RA |
321 | |
322 | /* Start. */ | |
69e2658b RA |
323 | state_ = 0; |
324 | looka_ = empty_; | |
8d69a1a3 RA |
325 | #if YYLSP_NEEDED |
326 | location = initlocation_; | |
327 | #endif | |
2b548aa6 RA |
328 | YYDPRINTF ((stderr, "Starting parse\n")); |
329 | ||
330 | /* New state. */ | |
331 | yynewstate: | |
69e2658b RA |
332 | state_stack_.push (state_); |
333 | YYDPRINTF ((stderr, "Entering state %d\n", state_)); | |
50997c6e | 334 | goto yybackup; |
2b548aa6 RA |
335 | |
336 | /* Backup. */ | |
337 | yybackup: | |
338 | ||
339 | /* Try to take a decision without lookahead. */ | |
69e2658b RA |
340 | n_ = pact_[[state_]]; |
341 | if (n_ == flag_) | |
2b548aa6 RA |
342 | goto yydefault; |
343 | ||
344 | /* Read a lookahead token. */ | |
69e2658b | 345 | if (looka_ == empty_) |
2b548aa6 RA |
346 | { |
347 | YYDPRINTF ((stderr, "Reading a token: ")); | |
69e2658b | 348 | lex_ (); |
2b548aa6 RA |
349 | } |
350 | ||
351 | /* Convert token to internal form. */ | |
69e2658b | 352 | if (looka_ <= 0) |
2b548aa6 | 353 | { |
69e2658b RA |
354 | looka_ = eof_; |
355 | ilooka_ = 0; | |
2b548aa6 RA |
356 | YYDPRINTF ((stderr, "Now at end of input.\n")); |
357 | } | |
358 | else | |
359 | { | |
69e2658b | 360 | ilooka_ = translate_ (looka_); |
50997c6e RA |
361 | #if YYDEBUG |
362 | if (debug_) | |
363 | { | |
69e2658b | 364 | YYFPRINTF (stderr, "Next token is %d (%s", looka_, name_[[ilooka_]]); |
4aacc3a7 | 365 | print_ (); |
50997c6e RA |
366 | YYFPRINTF (stderr, ")\n"); |
367 | } | |
2b548aa6 RA |
368 | #endif |
369 | } | |
370 | ||
69e2658b RA |
371 | n_ += ilooka_; |
372 | if (n_ < 0 || n_ > last_ || check_[[n_]] != ilooka_) | |
2b548aa6 RA |
373 | goto yydefault; |
374 | ||
375 | /* Reduce or error. */ | |
69e2658b RA |
376 | n_ = table_[[n_]]; |
377 | if (n_ < 0) | |
2b548aa6 | 378 | { |
69e2658b | 379 | if (n_ == flag_) |
2b548aa6 RA |
380 | goto yyerrlab; |
381 | else | |
382 | { | |
69e2658b | 383 | n_ = -n_; |
2b548aa6 RA |
384 | goto yyreduce; |
385 | } | |
386 | } | |
69e2658b | 387 | else if (n_ == 0) |
2b548aa6 | 388 | goto yyerrlab; |
a75c057f | 389 | |
2b548aa6 | 390 | /* Accept? */ |
69e2658b | 391 | if (n_ == final_) |
2b548aa6 RA |
392 | goto yyacceptlab; |
393 | ||
394 | /* Shift the lookahead token. */ | |
69e2658b | 395 | YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka_, name_[[ilooka_]])); |
2b548aa6 RA |
396 | |
397 | /* Discard the token being shifted unless it is eof. */ | |
69e2658b RA |
398 | if (looka_ != eof_) |
399 | looka_ = empty_; | |
2b548aa6 | 400 | |
69e2658b RA |
401 | semantic_stack_.push (value); |
402 | location_stack_.push (location); | |
8d69a1a3 RA |
403 | |
404 | /* Count tokens shifted since error; after three, turn off error | |
405 | status. */ | |
406 | if (errstatus) | |
407 | --errstatus; | |
408 | ||
69e2658b | 409 | state_ = n_; |
2b548aa6 RA |
410 | goto yynewstate; |
411 | ||
412 | /* Default action. */ | |
413 | yydefault: | |
69e2658b RA |
414 | n_ = defact_[[state_]]; |
415 | if (n_ == 0) | |
2b548aa6 | 416 | goto yyerrlab; |
50997c6e | 417 | goto yyreduce; |
2b548aa6 RA |
418 | |
419 | /* Reduce. */ | |
420 | yyreduce: | |
69e2658b RA |
421 | len_ = r2_[[n_]]; |
422 | if (len_) | |
50997c6e | 423 | { |
374f5a14 RA |
424 | yyval = semantic_stack_[[1 - len_]]; |
425 | yyloc = location_stack_[[1 - len_]]; | |
50997c6e RA |
426 | } |
427 | else | |
69e2658b | 428 | { |
374f5a14 RA |
429 | yyval = semantic_stack_[[0]]; |
430 | yyloc = location_stack_[[0]]; | |
50997c6e | 431 | } |
2b548aa6 | 432 | |
50997c6e RA |
433 | #if YYDEBUG |
434 | if (debug_) | |
2b548aa6 | 435 | { |
69e2658b RA |
436 | YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]); |
437 | for (unsigned i = prhs_[[n_]]; | |
3f3eed27 AD |
438 | rhs_[[i]] >= 0; ++i) |
439 | YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]); | |
69e2658b | 440 | YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n_]]]); |
2b548aa6 RA |
441 | } |
442 | #endif | |
a75c057f | 443 | |
374f5a14 RA |
444 | if (len_) |
445 | { | |
446 | Slice< LocationType, LocationStack > slice (location_stack_, len_); | |
447 | YYLLOC_DEFAULT (yyloc, slice, len_); | |
448 | } | |
449 | ||
2b548aa6 | 450 | { |
69e2658b RA |
451 | SemanticStack& yyvsp (semantic_stack_); |
452 | LocationStack& yylsp (location_stack_); | |
2b548aa6 | 453 | |
69e2658b | 454 | switch (n_) |
2b548aa6 | 455 | { |
3f3eed27 | 456 | b4_actions |
2b548aa6 RA |
457 | } |
458 | } | |
a75c057f | 459 | |
69e2658b RA |
460 | state_stack_.pop (len_); |
461 | semantic_stack_.pop (len_); | |
462 | location_stack_.pop (len_); | |
2b548aa6 | 463 | |
50997c6e RA |
464 | #if YYDEBUG |
465 | if (debug_) | |
2b548aa6 RA |
466 | { |
467 | YYFPRINTF (stderr, "state stack now"); | |
a75c057f | 468 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 469 | i != state_stack_.end (); ++i) |
2b548aa6 RA |
470 | YYFPRINTF (stderr, " %d", *i); |
471 | YYFPRINTF (stderr, "\n"); | |
472 | } | |
473 | #endif | |
a75c057f | 474 | |
374f5a14 RA |
475 | semantic_stack_.push (yyval); |
476 | location_stack_.push (yyloc); | |
2b548aa6 RA |
477 | |
478 | /* Shift the result of the reduction. */ | |
69e2658b RA |
479 | n_ = r1_[[n_]]; |
480 | state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]]; | |
481 | if (state_ >= 0 && state_ <= last_ && check_[[state_]] == state_stack_[[0]]) | |
482 | state_ = table_[[state_]]; | |
2b548aa6 | 483 | else |
69e2658b | 484 | state_ = defgoto_[[n_ - ntokens_]]; |
2b548aa6 RA |
485 | goto yynewstate; |
486 | ||
487 | /* Report and recover from errors. This is very incomplete. */ | |
488 | yyerrlab: | |
4bb2bc3f RA |
489 | /* If not already recovering from an error, report this error. */ |
490 | if (!errstatus) | |
491 | { | |
492 | ++nerrs; | |
a75c057f | 493 | |
69e2658b RA |
494 | #if YYERROR_VERBOSE |
495 | n_ = pact_[[state_]]; | |
496 | if (n_ > flag_ && n_ < last_) | |
4bb2bc3f RA |
497 | { |
498 | message = "parse error, unexpected "; | |
69e2658b | 499 | message += name_[[ilooka_]]; |
4bb2bc3f RA |
500 | { |
501 | int count = 0; | |
69e2658b RA |
502 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
503 | if (check_[[x + n_]] == x) | |
4bb2bc3f RA |
504 | ++count; |
505 | if (count < 5) | |
506 | { | |
507 | count = 0; | |
69e2658b RA |
508 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
509 | if (check_[[x + n_]] == x) | |
4bb2bc3f | 510 | { |
a75c057f | 511 | message += (!count++) ? ", expecting " : " or "; |
4bb2bc3f RA |
512 | message += name_[[x]]; |
513 | } | |
514 | } | |
515 | } | |
516 | } | |
517 | else | |
69e2658b | 518 | #endif |
4bb2bc3f | 519 | message = "parse error"; |
8d69a1a3 | 520 | error_ (); |
4bb2bc3f | 521 | } |
762a801e | 522 | goto yyerrlab1; |
a75c057f | 523 | |
762a801e RA |
524 | /* Error raised explicitly by an action. */ |
525 | yyerrlab1: | |
526 | if (errstatus == 3) | |
527 | { | |
528 | /* If just tried and failed to reuse lookahead token after an | |
529 | error, discard it. */ | |
530 | ||
531 | /* Return failure if at end of input. */ | |
69e2658b | 532 | if (looka_ == eof_) |
762a801e | 533 | goto yyabortlab; |
69e2658b RA |
534 | YYDPRINTF ((stderr, "Discarding token %d (%s).\n", looka_, name_[[ilooka_]])); |
535 | looka_ = empty_; | |
762a801e RA |
536 | } |
537 | ||
538 | /* Else will try to reuse lookahead token after shifting the error | |
539 | token. */ | |
540 | ||
541 | errstatus = 3; | |
542 | goto yyerrhandle; | |
543 | ||
544 | /* Pop the current state because it cannot handle the error token. */ | |
545 | yyerrdefault: | |
546 | yyerrpop: | |
69e2658b | 547 | if (!state_stack_.height ()) |
762a801e | 548 | goto yyabortlab; |
69e2658b RA |
549 | state_ = (state_stack_.pop (), state_stack_[[0]]); |
550 | semantic_stack_.pop (); | |
551 | location_stack_.pop ();; | |
762a801e RA |
552 | |
553 | #if YYDEBUG | |
554 | if (debug_) | |
555 | { | |
556 | YYFPRINTF (stderr, "Error: state stack now"); | |
a75c057f | 557 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 558 | i != state_stack_.end (); ++i) |
762a801e | 559 | YYFPRINTF (stderr, " %d", *i); |
a75c057f | 560 | YYFPRINTF (stderr, "\n"); |
762a801e RA |
561 | } |
562 | #endif | |
563 | ||
564 | yyerrhandle: | |
69e2658b RA |
565 | n_ = pact_[[state_]]; |
566 | if (n_ == flag_) | |
762a801e RA |
567 | goto yyerrdefault; |
568 | ||
69e2658b RA |
569 | n_ += terror_; |
570 | if (n_ < 0 || n_ > last_ || check_[[n_]] != terror_) | |
762a801e RA |
571 | goto yyerrdefault; |
572 | ||
69e2658b RA |
573 | n_ = table_[[n_]]; |
574 | if (n_ < 0) | |
762a801e | 575 | { |
69e2658b | 576 | if (n_ == flag_) |
762a801e | 577 | goto yyerrpop; |
69e2658b | 578 | n_ = -n_; |
762a801e RA |
579 | goto yyreduce; |
580 | } | |
69e2658b | 581 | else if (!n_) |
762a801e RA |
582 | goto yyerrpop; |
583 | ||
69e2658b | 584 | if (n_ == final_) |
762a801e RA |
585 | goto yyacceptlab; |
586 | ||
587 | YYDPRINTF ((stderr, "Shifting error token, ")); | |
588 | ||
69e2658b RA |
589 | semantic_stack_.push (value); |
590 | location_stack_.push (location); | |
762a801e | 591 | |
69e2658b | 592 | state_ = n_; |
762a801e RA |
593 | goto yynewstate; |
594 | ||
2b548aa6 RA |
595 | /* Accept. */ |
596 | yyacceptlab: | |
597 | return 0; | |
762a801e RA |
598 | |
599 | /* Abort. */ | |
600 | yyabortlab: | |
601 | return 1; | |
2b548aa6 RA |
602 | } |
603 | ||
69e2658b RA |
604 | void |
605 | yy::b4_name::lex_ () | |
606 | { | |
607 | #if YYLSP_NEEDED | |
608 | looka_ = yylex (&value, &location); | |
609 | #else | |
610 | looka_ = yylex (&value); | |
611 | #endif | |
612 | } | |
613 | ||
6b45a3ca | 614 | /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing |
2b548aa6 | 615 | STATE-NUM. */ |
69e2658b | 616 | const short |
3f3eed27 | 617 | yy::b4_name::pact_[[]] = |
2b548aa6 | 618 | { |
3f3eed27 | 619 | b4_pact |
2b548aa6 RA |
620 | }; |
621 | ||
6b45a3ca | 622 | /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
623 | doesn't specify something else to do. Zero means the default is an |
624 | error. */ | |
69e2658b | 625 | const short |
3f3eed27 | 626 | yy::b4_name::defact_[[]] = |
2b548aa6 | 627 | { |
3f3eed27 | 628 | b4_defact |
2b548aa6 RA |
629 | }; |
630 | ||
6b45a3ca | 631 | /* YYPGOTO[[NTERM-NUM]]. */ |
69e2658b | 632 | const short |
3f3eed27 | 633 | yy::b4_name::pgoto_[[]] = |
2b548aa6 | 634 | { |
3f3eed27 | 635 | b4_pgoto |
2b548aa6 RA |
636 | }; |
637 | ||
6b45a3ca | 638 | /* YYDEFGOTO[[NTERM-NUM]]. */ |
69e2658b | 639 | const short |
3f3eed27 | 640 | yy::b4_name::defgoto_[[]] = |
2b548aa6 | 641 | { |
3f3eed27 | 642 | b4_defgoto |
2b548aa6 RA |
643 | }; |
644 | ||
6b45a3ca | 645 | /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
646 | positive, shift that token. If negative, reduce the rule which |
647 | number is the opposite. If zero, do what YYDEFACT says. */ | |
69e2658b | 648 | const short |
3f3eed27 | 649 | yy::b4_name::table_[[]] = |
2b548aa6 | 650 | { |
3f3eed27 | 651 | b4_table |
2b548aa6 RA |
652 | }; |
653 | ||
654 | /* YYCHECK. */ | |
69e2658b | 655 | const short |
3f3eed27 | 656 | yy::b4_name::check_[[]] = |
2b548aa6 | 657 | { |
3f3eed27 | 658 | b4_check |
2b548aa6 RA |
659 | }; |
660 | ||
6b45a3ca | 661 | /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ |
a75c057f | 662 | const short |
3f3eed27 | 663 | yy::b4_name::r1_[[]] = |
2b548aa6 | 664 | { |
3f3eed27 | 665 | b4_r1 |
2b548aa6 RA |
666 | }; |
667 | ||
6b45a3ca | 668 | /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ |
a75c057f | 669 | const short |
3f3eed27 | 670 | yy::b4_name::r2_[[]] = |
2b548aa6 | 671 | { |
3f3eed27 | 672 | b4_r2 |
2b548aa6 RA |
673 | }; |
674 | ||
69e2658b | 675 | #if YYDEBUG || YYERROR_VERBOSE |
6b45a3ca | 676 | /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
677 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
678 | const char* | |
3f3eed27 | 679 | const yy::b4_name::name_[[]] = |
2b548aa6 | 680 | { |
3f3eed27 | 681 | b4_tname |
2b548aa6 | 682 | }; |
69e2658b | 683 | #endif |
2b548aa6 | 684 | |
69e2658b | 685 | #if YYDEBUG |
2b548aa6 | 686 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
a75c057f | 687 | const short |
3f3eed27 | 688 | yy::b4_name::rhs_[[]] = |
2b548aa6 | 689 | { |
3f3eed27 | 690 | b4_rhs |
2b548aa6 RA |
691 | }; |
692 | ||
6b45a3ca | 693 | /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 694 | YYRHS. */ |
69e2658b | 695 | const short |
3f3eed27 | 696 | yy::b4_name::prhs_[[]] = |
2b548aa6 | 697 | { |
3f3eed27 | 698 | b4_prhs |
2b548aa6 RA |
699 | }; |
700 | ||
69e2658b RA |
701 | /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ |
702 | const short | |
703 | yy::b4_name::rline_[[]] = | |
704 | { | |
705 | b4_rline | |
706 | }; | |
707 | #endif | |
708 | ||
2b548aa6 | 709 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
680e8701 | 710 | TokenNumberType |
69e2658b | 711 | yy::b4_name::translate_ (int token) |
2b548aa6 | 712 | { |
a75c057f | 713 | static |
680e8701 | 714 | const TokenNumberType |
3f3eed27 | 715 | translate_[[]] = |
2b548aa6 | 716 | { |
3f3eed27 | 717 | b4_translate |
2b548aa6 | 718 | }; |
680e8701 | 719 | return (unsigned)(token) <= maxtok_ ? translate_[[token]] : nsym_; |
2b548aa6 RA |
720 | } |
721 | ||
50997c6e | 722 | const int yy::b4_name::eof_ = 0; |
69e2658b RA |
723 | const int yy::b4_name::last_ = b4_last; |
724 | const int yy::b4_name::flag_ = b4_flag; | |
725 | const int yy::b4_name::nnts_ = b4_nnts; | |
726 | const int yy::b4_name::nsym_ = b4_nsym; | |
50997c6e | 727 | const int yy::b4_name::empty_ = -2; |
69e2658b | 728 | const int yy::b4_name::final_ = b4_final; |
762a801e RA |
729 | const int yy::b4_name::terror_ = 1; |
730 | const int yy::b4_name::errcode_ = 256; | |
50997c6e | 731 | const int yy::b4_name::ntokens_ = b4_ntokens; |
69e2658b RA |
732 | const int yy::b4_name::initdepth_ = b4_initdepth; |
733 | ||
734 | const unsigned yy::b4_name::maxtok_ = b4_maxtok; | |
2b548aa6 | 735 | |
3f3eed27 | 736 | b4_epilogue |
2b548aa6 | 737 | |
3f3eed27 | 738 | #output "stack.hh" |
98254360 RA |
739 | b4_copyright |
740 | ||
2b548aa6 RA |
741 | #ifndef BISON_STACK_HH |
742 | # define BISON_STACK_HH | |
743 | ||
744 | #include <vector> | |
745 | ||
746 | namespace yy | |
747 | { | |
748 | template < class T, class S = std::vector< T > > | |
749 | class Stack | |
750 | { | |
751 | public: | |
752 | ||
753 | typedef typename S::iterator Iterator; | |
754 | typedef typename S::const_iterator ConstIterator; | |
755 | ||
756 | Stack () : seq_ () | |
757 | { | |
758 | } | |
759 | ||
760 | Stack (unsigned n) : seq_ (n) | |
761 | { | |
762 | } | |
763 | ||
764 | inline | |
765 | T& | |
3f3eed27 | 766 | operator [[]] (int index) |
2b548aa6 | 767 | { |
374f5a14 | 768 | return seq_[[height () - 1 + index]]; |
2b548aa6 RA |
769 | } |
770 | ||
771 | inline | |
772 | const T& | |
3f3eed27 | 773 | operator [[]] (int index) const |
2b548aa6 | 774 | { |
374f5a14 | 775 | return seq_[[height () - 1 + index]]; |
2b548aa6 RA |
776 | } |
777 | ||
778 | inline | |
779 | void | |
780 | push (const T& t) | |
781 | { | |
782 | seq_.push_back (t); | |
783 | } | |
784 | ||
785 | inline | |
786 | void | |
787 | pop (unsigned n = 1) | |
788 | { | |
789 | for (; n; --n) | |
790 | seq_.pop_back (); | |
791 | } | |
a75c057f | 792 | |
2b548aa6 RA |
793 | inline |
794 | void | |
795 | reserve (unsigned n) | |
796 | { | |
797 | seq_.reserve (n); | |
798 | } | |
799 | ||
762a801e RA |
800 | inline |
801 | unsigned | |
802 | height () const | |
803 | { | |
804 | return seq_.size (); | |
805 | } | |
806 | ||
2b548aa6 RA |
807 | inline ConstIterator begin () const { return seq_.begin (); } |
808 | inline ConstIterator end () const { return seq_.end (); } | |
809 | ||
810 | private: | |
811 | ||
812 | S seq_; | |
813 | }; | |
374f5a14 RA |
814 | |
815 | template < class T, class S = Stack< T > > | |
816 | class Slice | |
817 | { | |
818 | public: | |
819 | ||
820 | Slice (const S& stack, | |
821 | unsigned range) : stack_ (stack), | |
822 | range_ (range) | |
823 | { | |
824 | } | |
825 | ||
826 | inline | |
827 | const T& | |
828 | operator [[]] (unsigned index) const | |
829 | { | |
830 | return stack_[[index - range_]]; | |
831 | } | |
832 | ||
833 | private: | |
834 | ||
835 | const S& stack_; | |
836 | unsigned range_; | |
837 | }; | |
2b548aa6 RA |
838 | } |
839 | ||
840 | #endif // not BISON_STACK_HH | |
841 | ||
3f3eed27 | 842 | #output "location.hh" |
98254360 RA |
843 | b4_copyright |
844 | ||
2b548aa6 RA |
845 | #ifndef BISON_LOCATION_HH |
846 | # define BISON_LOCATION_HH | |
847 | ||
848 | namespace yy | |
849 | { | |
850 | struct Position | |
851 | { | |
852 | int line; | |
853 | int column; | |
854 | }; | |
855 | ||
856 | struct Location | |
857 | { | |
858 | Position first; | |
859 | Position last; | |
860 | }; | |
861 | } | |
862 | ||
863 | #endif // not BISON_LOCATION_HH |