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