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