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