]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
29301b696cabac79debcf4595df6ece6535b6dc2
[bison.git] / data / lalr1.cc
1 m4_divert(-1)
2 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307 USA
19
20 ## ---------------- ##
21 ## Default values. ##
22 ## ---------------- ##
23
24 # Default Parser class name.
25 m4_define_default([b4_parser_class_name], [Parser])
26
27
28
29 ## ----------------- ##
30 ## Semantic Values. ##
31 ## ----------------- ##
32
33
34 # b4_lhs_value([TYPE])
35 # --------------------
36 # Expansion of $<TYPE>$.
37 m4_define([b4_lhs_value],
38 [yyval[]m4_ifval([$1], [.$1])])
39
40
41 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42 # --------------------------------------
43 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
44 # symbols on RHS.
45 m4_define([b4_rhs_value],
46 [semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
47
48 m4_define_default([b4_location_type], [Location])
49
50 # b4_lhs_location()
51 # -----------------
52 # Expansion of @$.
53 m4_define([b4_lhs_location],
54 [yyloc])
55
56
57 # b4_rhs_location(RULE-LENGTH, NUM)
58 # ---------------------------------
59 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60 # on RHS.
61 m4_define([b4_rhs_location],
62 [location_stack_@{m4_eval([$1 - $2])@}])
63
64
65 m4_define([b4_inherit],
66 [m4_ifdef([b4_root],
67 [: public b4_root
68 ],
69 [])])
70
71 m4_define([b4_param],
72 [m4_ifdef([b4_root],
73 [,
74 const Param& param],
75 [])])
76
77 m4_define([b4_constructor],
78 [m4_ifdef([b4_root],
79 [b4_root (param),
80 ],
81 [])])
82
83
84 # b4_parse_param_decl
85 # -------------------
86 # Extra formal arguments of the constructor.
87 # Change the parameter names from "foo" into "foo_yyarg", so that
88 # there is no collision bw the user chosen attribute name, and the
89 # argument name in the constructor.
90 m4_define([b4_parse_param_decl],
91 [m4_ifset([b4_parse_param],
92 [, m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
93
94 m4_define([b4_parse_param_decl_1],
95 [$1_yyarg])
96
97
98
99 # b4_parse_param_cons
100 # -------------------
101 # Extra initialisations of the constructor.
102 m4_define([b4_parse_param_cons],
103 [m4_ifset([b4_parse_param],
104 [,
105 b4_cc_constructor_calls(b4_parse_param)])])
106 m4_define([b4_cc_constructor_calls],
107 [m4_map_sep([b4_cc_constructor_call], [,
108 ], [$@])])
109 m4_define([b4_cc_constructor_call],
110 [$2 ($2_yyarg)])
111
112 # b4_parse_param_vars
113 # -------------------
114 # Extra instance variables.
115 m4_define([b4_parse_param_vars],
116 [m4_ifset([b4_parse_param],
117 [
118 /* User arguments. */
119 b4_cc_var_decls(b4_parse_param)])])
120 m4_define([b4_cc_var_decls],
121 [m4_map_sep([b4_cc_var_decl], [
122 ], [$@])])
123 m4_define([b4_cc_var_decl],
124 [ $1;])
125
126
127
128 # We do want M4 expansion after # for CPP macros.
129 m4_changecom()
130 m4_divert(0)dnl
131 m4_if(b4_defines_flag, 0, [],
132 [@output @output_header_name@
133 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
134 [2002, 2003, 2004])[
135 /* FIXME: This is wrong, we want computed header guards.
136 I don't know why the macros are missing now. :( */
137 #ifndef PARSER_HEADER_H
138 # define PARSER_HEADER_H
139
140 #include "stack.hh"
141 #include "location.hh"
142
143 #include <string>
144 #include <iostream>
145
146 /* Using locations. */
147 #define YYLSP_NEEDED ]b4_locations_flag[
148
149 ]b4_token_defines(b4_tokens)[
150
151 /* Copy the first part of user declarations. */
152 ]b4_pre_prologue[
153
154 ]/* Line __line__ of lalr1.cc. */
155 b4_syncline([@oline@], [@ofile@])[
156
157 /* Enabling traces. */
158 #ifndef YYDEBUG
159 # define YYDEBUG ]b4_debug[
160 #endif
161
162 /* Enabling verbose error message. */
163 #ifndef YYERROR_VERBOSE
164 # define YYERROR_VERBOSE ]b4_error_verbose[
165 #endif
166
167 #ifdef YYSTYPE
168 typedef YYSTYPE yystype;
169 #else
170 ]m4_ifdef([b4_stype],
171 [b4_syncline([b4_stype_line], [b4_filename])
172 typedef union b4_stype yystype;
173 /* Line __line__ of lalr1.cc. */
174 b4_syncline([@oline@], [@ofile@])],
175 [typedef int yystype;])[
176 # define YYSTYPE yystype
177 #endif
178
179 /* Copy the second part of user declarations. */
180 ]b4_post_prologue[
181
182 ]/* Line __line__ of lalr1.cc. */
183 b4_syncline([@oline@], [@ofile@])[
184 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
185 If N is 0, then set CURRENT to the empty location which ends
186 the previous symbol: RHS[0] (always defined). */
187
188 #ifndef YYLLOC_DEFAULT
189 # define YYLLOC_DEFAULT(Current, Rhs, N) \
190 do { \
191 if (N) \
192 { \
193 (Current).begin = (Rhs)[1].begin; \
194 (Current).end = (Rhs)[N].end; \
195 } \
196 else \
197 { \
198 (Current).begin = (Current).end = (Rhs)[0].end; \
199 } \
200 } while (0)
201 #endif
202
203 namespace yy
204 {
205 class ]b4_parser_class_name[;
206
207 template <typename P>
208 struct Traits
209 {
210 };
211
212 template <>
213 struct Traits<]b4_parser_class_name[>
214 {
215 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
216 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
217 typedef int StateType;
218 typedef yystype SemanticType;
219 typedef ]b4_location_type[ LocationType;
220 };
221 }
222
223 namespace yy
224 {
225 class ]b4_parser_class_name b4_inherit[
226 {
227 public:
228
229 typedef Traits<]b4_parser_class_name[>::TokenNumberType TokenNumberType;
230 typedef Traits<]b4_parser_class_name[>::RhsNumberType RhsNumberType;
231 typedef Traits<]b4_parser_class_name[>::StateType StateType;
232 typedef Traits<]b4_parser_class_name[>::SemanticType SemanticType;
233 typedef Traits<]b4_parser_class_name[>::LocationType LocationType;
234
235 typedef Stack<StateType> StateStack;
236 typedef Stack<SemanticType> SemanticStack;
237 typedef Stack<LocationType> LocationStack;
238
239 ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
240 ]b4_constructor[][debug_ (debug),
241 yycdebug_ (&std::cerr)]b4_parse_param_cons[
242 {
243 }
244
245 ]b4_parser_class_name[ (bool debug,
246 LocationType][]b4_param[]b4_parse_param_decl[) :
247 ]b4_constructor[][debug_ (debug),
248 yycdebug_ (&std::cerr)]b4_parse_param_cons[
249 {
250 *yycdebug_ << __FILE__ << ':' << __LINE__
251 << ": this constructor is provided by backward compatibility"
252 << ", but will be removed in the near future."
253 << std::endl;
254 }
255
256 virtual ~]b4_parser_class_name[ ()
257 {
258 }
259
260 virtual int parse ();
261
262 /// Return the current debugging stream.
263 std::ostream& debug_stream () const;
264 /// Set the current debugging stream.
265 void set_debug_stream (std::ostream &);
266
267 private:
268
269 virtual void lex_ ();
270 virtual void error_ ();
271 virtual void report_syntax_error_ ();
272 #if YYDEBUG
273 virtual void symprint_ (int yytype,
274 const SemanticType* yyvaluep,
275 const LocationType* yylocationp);
276 #endif /* ! YYDEBUG */
277
278
279 /* Stacks. */
280 StateStack state_stack_;
281 SemanticStack semantic_stack_;
282 LocationStack location_stack_;
283
284 /* Tables. */
285 static const ]b4_int_type_for([b4_pact])[ pact_[];
286 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ pact_ninf_;
287 static const ]b4_int_type_for([b4_defact])[ defact_[];
288 static const ]b4_int_type_for([b4_pgoto])[ pgoto_[];
289 static const ]b4_int_type_for([b4_defgoto])[ defgoto_[];
290 static const ]b4_int_type_for([b4_table])[ table_[];
291 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ table_ninf_;
292 static const ]b4_int_type_for([b4_check])[ check_[];
293 static const ]b4_int_type_for([b4_stos])[ stos_[];
294 static const ]b4_int_type_for([b4_r1])[ r1_[];
295 static const ]b4_int_type_for([b4_r2])[ r2_[];
296
297 #if YYDEBUG || YYERROR_VERBOSE
298 static const char* const name_[];
299 #endif
300
301 /* More tables, for debugging. */
302 #if YYDEBUG
303 static const RhsNumberType rhs_[];
304 static const ]b4_int_type_for([b4_prhs])[ prhs_[];
305 static const ]b4_int_type_for([b4_rline])[ rline_[];
306 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
307 virtual void reduce_print_ (int yyrule);
308 virtual void stack_print_ ();
309 #endif
310
311 /* Even more tables. */
312 inline TokenNumberType translate_ (int token);
313 inline void destruct_ (const char* yymsg,
314 int yytype,
315 SemanticType* yyvaluep, LocationType* yylocationp);
316
317 /// Pop \a n symbols the three stacks.
318 inline void pop (unsigned int n = 1);
319
320 /* Constants. */
321 static const int eof_;
322 /* LAST_ -- Last index in TABLE_. */
323 static const int last_;
324 static const int nnts_;
325 static const int empty_;
326 static const int final_;
327 static const int terror_;
328 static const int errcode_;
329 static const int ntokens_;
330 static const unsigned int user_token_number_max_;
331 static const TokenNumberType undef_token_;
332
333 /* State. */
334 int n_;
335 int len_;
336 int state_;
337
338 /* Error handling. */
339 int nerrs_;
340 int errstatus_;
341
342 /* Debugging. */
343 int debug_;
344 std::ostream* yycdebug_;
345
346 /* Look-ahead and look-ahead in internal form. */
347 int looka_;
348 int ilooka_;
349
350 /* Message. */
351 std::string message;
352
353 /// Semantic value of the look-ahead.
354 SemanticType value;
355 /// Location of the look-ahead.
356 LocationType location;
357 /// The locations where the error started and ended.
358 Location error_range_[2];
359
360 /// $$.
361 SemanticType yyval;
362 /// @@$.
363 LocationType yyloc;
364 ]b4_parse_param_vars[
365 };
366 }
367
368 #endif /* ! defined PARSER_HEADER_H */]
369 ])dnl
370 @output @output_parser_name@
371 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
372 [2002, 2003, 2004])
373
374 m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
375
376 /* A pseudo ostream that takes debug_ into account. */
377 # define YYCDEBUG \
378 for (bool yydebugcond_ = debug_; yydebugcond_; yydebugcond_ = false) \
379 (*yycdebug_)
380
381 /* Enable debugging if requested. */
382 #if YYDEBUG
383
384 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
385 do { \
386 if (debug_) \
387 { \
388 *yycdebug_ << (Title) << ' '; \
389 symprint_ ((Type), (Value), (Location)); \
390 *yycdebug_ << std::endl; \
391 } \
392 } while (0)
393
394 # define YY_REDUCE_PRINT(Rule) \
395 do { \
396 if (debug_) \
397 reduce_print_ (Rule); \
398 } while (0)
399
400 # define YY_STACK_PRINT() \
401 do { \
402 if (debug_) \
403 stack_print_ (); \
404 } while (0)
405
406 #else /* !YYDEBUG */
407
408 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
409 # define YY_REDUCE_PRINT(Rule)
410 # define YY_STACK_PRINT()
411
412 #endif /* !YYDEBUG */
413
414 #define YYACCEPT goto yyacceptlab
415 #define YYABORT goto yyabortlab
416 #define YYERROR goto yyerrorlab
417
418 #if YYDEBUG
419 /*--------------------------------.
420 | Print this symbol on YYOUTPUT. |
421 `--------------------------------*/
422
423 void
424 yy::]b4_parser_class_name[::symprint_ (int yytype,
425 const SemanticType* yyvaluep, const LocationType* yylocationp)
426 {
427 /* Pacify ``unused variable'' warnings. */
428 (void) yyvaluep;
429 (void) yylocationp;
430 /* Backward compatibility, but should be removed eventually. */
431 std::ostream& cdebug_ = *yycdebug_;
432
433 *yycdebug_ << (yytype < ntokens_ ? "token" : "nterm")
434 << ' ' << name_[yytype] << " ("
435 << *yylocationp << ": ";
436 switch (yytype)
437 {
438 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
439 [ default:
440 break;
441 }
442 *yycdebug_ << ')';
443 }
444 #endif /* ! YYDEBUG */
445
446 void
447 yy::]b4_parser_class_name[::destruct_ (const char* yymsg,
448 int yytype, SemanticType* yyvaluep, LocationType* yylocationp)
449 {
450 /* Pacify ``unused variable'' warnings. */
451 (void) yyvaluep;
452 (void) yylocationp;
453
454 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
455
456 switch (yytype)
457 {
458 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
459 default:
460 break;
461 }
462 }
463
464 void
465 yy::]b4_parser_class_name[::pop (unsigned int n)
466 {
467 state_stack_.pop (n);
468 semantic_stack_.pop (n);
469 location_stack_.pop (n);
470 }
471
472 std::ostream&
473 yy::]b4_parser_class_name[::debug_stream () const
474 {
475 return *yycdebug_;
476 }
477
478 void
479 yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
480 {
481 yycdebug_ = &o;
482 }
483
484
485 int
486 yy::]b4_parser_class_name[::parse ()
487 {
488 YYCDEBUG << "Starting parse" << std::endl;
489
490 nerrs_ = 0;
491 errstatus_ = 0;
492
493 /* Start. */
494 state_ = 0;
495 looka_ = empty_;
496
497 ]m4_ifdef([b4_initial_action], [
498 m4_pushdef([b4_at_dollar], [location])dnl
499 m4_pushdef([b4_dollar_dollar], [value])dnl
500 /* User initialization code. */
501 b4_initial_action
502 m4_popdef([b4_dollar_dollar])dnl
503 m4_popdef([b4_at_dollar])dnl
504 /* Line __line__ of yacc.c. */
505 b4_syncline([@oline@], [@ofile@])])dnl
506
507 [ /* Initialize the stacks. The initial state will be pushed in
508 yynewstate, since the latter expects the semantical and the
509 location values to have been already stored, initialize these
510 stacks with a primary value. */
511 state_stack_ = StateStack (0);
512 semantic_stack_ = SemanticStack (0);
513 location_stack_ = LocationStack (0);
514 semantic_stack_.push (value);
515 location_stack_.push (location);
516
517 /* New state. */
518 yynewstate:
519 state_stack_.push (state_);
520 YYCDEBUG << "Entering state " << state_ << std::endl;
521 goto yybackup;
522
523 /* Backup. */
524 yybackup:
525
526 /* Try to take a decision without look-ahead. */
527 n_ = pact_[state_];
528 if (n_ == pact_ninf_)
529 goto yydefault;
530
531 /* Read a look-ahead token. */
532 if (looka_ == empty_)
533 {
534 YYCDEBUG << "Reading a token: ";
535 lex_ ();
536 }
537
538 /* Convert token to internal form. */
539 if (looka_ <= eof_)
540 {
541 looka_ = ilooka_ = eof_;
542 YYCDEBUG << "Now at end of input." << std::endl;
543 }
544 else
545 {
546 ilooka_ = translate_ (looka_);
547 YY_SYMBOL_PRINT ("Next token is", ilooka_, &value, &location);
548 }
549
550 /* If the proper action on seeing token ILOOKA_ is to reduce or to
551 detect an error, take that action. */
552 n_ += ilooka_;
553 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
554 goto yydefault;
555
556 /* Reduce or error. */
557 n_ = table_[n_];
558 if (n_ < 0)
559 {
560 if (n_ == table_ninf_)
561 goto yyerrlab;
562 else
563 {
564 n_ = -n_;
565 goto yyreduce;
566 }
567 }
568 else if (n_ == 0)
569 goto yyerrlab;
570
571 /* Accept? */
572 if (n_ == final_)
573 goto yyacceptlab;
574
575 /* Shift the look-ahead token. */
576 YY_SYMBOL_PRINT ("Shifting", ilooka_, &value, &location);
577
578 /* Discard the token being shifted unless it is eof. */
579 if (looka_ != eof_)
580 looka_ = empty_;
581
582 semantic_stack_.push (value);
583 location_stack_.push (location);
584
585 /* Count tokens shifted since error; after three, turn off error
586 status. */
587 if (errstatus_)
588 --errstatus_;
589
590 state_ = n_;
591 goto yynewstate;
592
593 /*-----------------------------------------------------------.
594 | yydefault -- do the default action for the current state. |
595 `-----------------------------------------------------------*/
596 yydefault:
597 n_ = defact_[state_];
598 if (n_ == 0)
599 goto yyerrlab;
600 goto yyreduce;
601
602 /*-----------------------------.
603 | yyreduce -- Do a reduction. |
604 `-----------------------------*/
605 yyreduce:
606 len_ = r2_[n_];
607 /* If LEN_ is nonzero, implement the default value of the action:
608 `$$ = $1'. Otherwise, use the top of the stack.
609
610 Otherwise, the following line sets YYVAL to garbage.
611 This behavior is undocumented and Bison
612 users should not rely upon it. */
613 if (len_)
614 yyval = semantic_stack_[len_ - 1];
615 else
616 yyval = semantic_stack_[0];
617
618 {
619 Slice<LocationType, LocationStack> slice (location_stack_, len_);
620 YYLLOC_DEFAULT (yyloc, slice, len_);
621 }
622 YY_REDUCE_PRINT (n_);
623 switch (n_)
624 {
625 ]b4_actions[
626 }
627
628 ]/* Line __line__ of lalr1.cc. */
629 b4_syncline([@oline@], [@ofile@])[
630
631 pop (len_);
632
633 YY_STACK_PRINT ();
634
635 semantic_stack_.push (yyval);
636 location_stack_.push (yyloc);
637
638 /* Shift the result of the reduction. */
639 n_ = r1_[n_];
640 state_ = pgoto_[n_ - ntokens_] + state_stack_[0];
641 if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0])
642 state_ = table_[state_];
643 else
644 state_ = defgoto_[n_ - ntokens_];
645 goto yynewstate;
646
647 /*------------------------------------.
648 | yyerrlab -- here on detecting error |
649 `------------------------------------*/
650 yyerrlab:
651 /* If not already recovering from an error, report this error. */
652 report_syntax_error_ ();
653
654 error_range_[0] = location;
655 if (errstatus_ == 3)
656 {
657 /* If just tried and failed to reuse look-ahead token after an
658 error, discard it. */
659
660 /* Return failure if at end of input. */
661 if (looka_ <= eof_)
662 {
663 /* If at end of input, pop the error token,
664 then the rest of the stack, then return failure. */
665 if (looka_ == eof_)
666 for (;;)
667 {
668 error_range_[0] = location_stack_[0];
669 pop ();
670 if (state_stack_.height () == 1)
671 YYABORT;
672 destruct_ ("Error: popping",
673 stos_[state_stack_[0]],
674 &semantic_stack_[0],
675 &location_stack_[0]);
676 }
677 }
678 else
679 {
680 destruct_ ("Error: discarding", ilooka_, &value, &location);
681 looka_ = empty_;
682 }
683 }
684
685 /* Else will try to reuse look-ahead token after shifting the error
686 token. */
687 goto yyerrlab1;
688
689
690 /*---------------------------------------------------.
691 | yyerrorlab -- error raised explicitly by YYERROR. |
692 `---------------------------------------------------*/
693 yyerrorlab:
694
695 #ifdef __GNUC__
696 /* Pacify GCC when the user code never invokes YYERROR and the label
697 yyerrorlab therefore never appears in user code. */
698 if (0)
699 goto yyerrorlab;
700 #endif
701
702 error_range_[0] = location_stack_[len_ - 1];
703 pop (len_);
704 state_ = state_stack_[0];
705 goto yyerrlab1;
706
707 /*-------------------------------------------------------------.
708 | yyerrlab1 -- common code for both syntax error and YYERROR. |
709 `-------------------------------------------------------------*/
710 yyerrlab1:
711 errstatus_ = 3; /* Each real token shifted decrements this. */
712
713 for (;;)
714 {
715 n_ = pact_[state_];
716 if (n_ != pact_ninf_)
717 {
718 n_ += terror_;
719 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
720 {
721 n_ = table_[n_];
722 if (0 < n_)
723 break;
724 }
725 }
726
727 /* Pop the current state because it cannot handle the error token. */
728 if (state_stack_.height () == 1)
729 YYABORT;
730
731 error_range_[0] = location_stack_[0];
732 destruct_ ("Error: popping",
733 stos_[state_], &semantic_stack_[0], &location_stack_[0]);
734 pop ();
735 state_ = state_stack_[0];
736 YY_STACK_PRINT ();
737 }
738
739 if (n_ == final_)
740 goto yyacceptlab;
741
742 error_range_[1] = location;
743 // Using LOCATION is tempting, but would change the location of
744 // the look-ahead. YYLOC is available though.
745 YYLLOC_DEFAULT (yyloc, error_range_ - 1, 2);
746 semantic_stack_.push (value);
747 location_stack_.push (yyloc);
748
749 /* Shift the error token. */
750 YY_SYMBOL_PRINT ("Shifting", stos_[n_],
751 &semantic_stack_[0], &location_stack_[0]);
752
753 state_ = n_;
754 goto yynewstate;
755
756 /* Accept. */
757 yyacceptlab:
758 return 0;
759
760 /* Abort. */
761 yyabortlab:
762 /* Free the lookahead. */
763 destruct_ ("Error: discarding lookahead", ilooka_, &value, &location);
764 looka_ = empty_;
765 return 1;
766 }
767
768 void
769 yy::]b4_parser_class_name[::lex_ ()
770 {
771 #if YYLSP_NEEDED
772 looka_ = yylex (&value, &location);
773 #else
774 looka_ = yylex (&value);
775 #endif
776 }
777
778 /** Generate an error message, and invoke yyerror. */
779 void
780 yy::]b4_parser_class_name[::report_syntax_error_ ()
781 {
782 /* If not already recovering from an error, report this error. */
783 if (!errstatus_)
784 {
785 ++nerrs_;
786
787 #if YYERROR_VERBOSE
788 n_ = pact_[state_];
789 if (pact_ninf_ < n_ && n_ < last_)
790 {
791 message = "syntax error, unexpected ";
792 message += name_[ilooka_];
793 {
794 int count = 0;
795 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
796 if (check_[x + n_] == x && x != terror_)
797 ++count;
798 if (count < 5)
799 {
800 count = 0;
801 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
802 if (check_[x + n_] == x && x != terror_)
803 {
804 message += (!count++) ? ", expecting " : " or ";
805 message += name_[x];
806 }
807 }
808 }
809 }
810 else
811 #endif
812 message = "syntax error";
813 error_ ();
814 }
815 }
816
817
818 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
819 STATE-NUM. */
820 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
821 const ]b4_int_type_for([b4_pact])[
822 yy::]b4_parser_class_name[::pact_[] =
823 {
824 ]b4_pact[
825 };
826
827 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
828 doesn't specify something else to do. Zero means the default is an
829 error. */
830 const ]b4_int_type_for([b4_defact])[
831 yy::]b4_parser_class_name[::defact_[] =
832 {
833 ]b4_defact[
834 };
835
836 /* YYPGOTO[NTERM-NUM]. */
837 const ]b4_int_type_for([b4_pgoto])[
838 yy::]b4_parser_class_name[::pgoto_[] =
839 {
840 ]b4_pgoto[
841 };
842
843 /* YYDEFGOTO[NTERM-NUM]. */
844 const ]b4_int_type_for([b4_defgoto])[
845 yy::]b4_parser_class_name[::defgoto_[] =
846 {
847 ]b4_defgoto[
848 };
849
850 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
851 positive, shift that token. If negative, reduce the rule which
852 number is the opposite. If zero, do what YYDEFACT says. */
853 const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
854 const ]b4_int_type_for([b4_table])[
855 yy::]b4_parser_class_name[::table_[] =
856 {
857 ]b4_table[
858 };
859
860 /* YYCHECK. */
861 const ]b4_int_type_for([b4_check])[
862 yy::]b4_parser_class_name[::check_[] =
863 {
864 ]b4_check[
865 };
866
867 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
868 symbol of state STATE-NUM. */
869 const ]b4_int_type_for([b4_stos])[
870 yy::]b4_parser_class_name[::stos_[] =
871 {
872 ]b4_stos[
873 };
874
875 #if YYDEBUG
876 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
877 to YYLEX-NUM. */
878 const ]b4_int_type_for([b4_toknum])[
879 yy::]b4_parser_class_name[::token_number_[] =
880 {
881 ]b4_toknum[
882 };
883 #endif
884
885 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
886 const ]b4_int_type_for([b4_r1])[
887 yy::]b4_parser_class_name[::r1_[] =
888 {
889 ]b4_r1[
890 };
891
892 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
893 const ]b4_int_type_for([b4_r2])[
894 yy::]b4_parser_class_name[::r2_[] =
895 {
896 ]b4_r2[
897 };
898
899 #if YYDEBUG || YYERROR_VERBOSE
900 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
901 First, the terminals, then, starting at NTOKENS_, nonterminals. */
902 const char*
903 const yy::]b4_parser_class_name[::name_[] =
904 {
905 ]b4_tname[
906 };
907 #endif
908
909 #if YYDEBUG
910 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
911 const yy::]b4_parser_class_name[::RhsNumberType
912 yy::]b4_parser_class_name[::rhs_[] =
913 {
914 ]b4_rhs[
915 };
916
917 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
918 YYRHS. */
919 const ]b4_int_type_for([b4_prhs])[
920 yy::]b4_parser_class_name[::prhs_[] =
921 {
922 ]b4_prhs[
923 };
924
925 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
926 const ]b4_int_type_for([b4_rline])[
927 yy::]b4_parser_class_name[::rline_[] =
928 {
929 ]b4_rline[
930 };
931
932 /** Print the state stack from its BOTTOM up to its TOP (included). */
933
934 void
935 yy::]b4_parser_class_name[::stack_print_ ()
936 {
937 *yycdebug_ << "Stack now";
938 for (StateStack::const_iterator i = state_stack_.begin ();
939 i != state_stack_.end (); ++i)
940 *yycdebug_ << ' ' << *i;
941 *yycdebug_ << std::endl;
942 }
943
944 /** Report that the YYRULE is going to be reduced. */
945
946 void
947 yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
948 {
949 unsigned int yylno = rline_[yyrule];
950 /* Print the symbols being reduced, and their result. */
951 *yycdebug_ << "Reducing stack by rule " << n_ - 1
952 << " (line " << yylno << "), ";
953 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
954 0 <= rhs_[i]; ++i)
955 *yycdebug_ << name_[rhs_[i]] << ' ';
956 *yycdebug_ << "-> " << name_[r1_[n_]] << std::endl;
957 }
958 #endif // YYDEBUG
959
960 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
961 yy::]b4_parser_class_name[::TokenNumberType
962 yy::]b4_parser_class_name[::translate_ (int token)
963 {
964 static
965 const TokenNumberType
966 translate_table[] =
967 {
968 ]b4_translate[
969 };
970 if ((unsigned int) token <= user_token_number_max_)
971 return translate_table[token];
972 else
973 return undef_token_;
974 }
975
976 const int yy::]b4_parser_class_name[::eof_ = 0;
977 const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
978 const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
979 const int yy::]b4_parser_class_name[::empty_ = -2;
980 const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
981 const int yy::]b4_parser_class_name[::terror_ = 1;
982 const int yy::]b4_parser_class_name[::errcode_ = 256;
983 const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
984
985 const unsigned int yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
986 const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
987
988 ]b4_epilogue
989 dnl
990 @output stack.hh
991 b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003, 2004])[
992
993 #ifndef BISON_STACK_HH
994 # define BISON_STACK_HH
995
996 #include <deque>
997
998 namespace yy
999 {
1000 template <class T, class S = std::deque<T> >
1001 class Stack
1002 {
1003 public:
1004
1005 // Hide our reversed order.
1006 typedef typename S::reverse_iterator iterator;
1007 typedef typename S::const_reverse_iterator const_iterator;
1008
1009 Stack () : seq_ ()
1010 {
1011 }
1012
1013 Stack (unsigned int n) : seq_ (n)
1014 {
1015 }
1016
1017 inline
1018 T&
1019 operator [] (unsigned int i)
1020 {
1021 return seq_[i];
1022 }
1023
1024 inline
1025 const T&
1026 operator [] (unsigned int i) const
1027 {
1028 return seq_[i];
1029 }
1030
1031 inline
1032 void
1033 push (const T& t)
1034 {
1035 seq_.push_front (t);
1036 }
1037
1038 inline
1039 void
1040 pop (unsigned int n = 1)
1041 {
1042 for (; n; --n)
1043 seq_.pop_front ();
1044 }
1045
1046 inline
1047 unsigned int
1048 height () const
1049 {
1050 return seq_.size ();
1051 }
1052
1053 inline const_iterator begin () const { return seq_.rbegin (); }
1054 inline const_iterator end () const { return seq_.rend (); }
1055
1056 private:
1057
1058 S seq_;
1059 };
1060
1061 template <class T, class S = Stack<T> >
1062 class Slice
1063 {
1064 public:
1065
1066 Slice (const S& stack,
1067 unsigned int range) : stack_ (stack),
1068 range_ (range)
1069 {
1070 }
1071
1072 inline
1073 const T&
1074 operator [] (unsigned int i) const
1075 {
1076 return stack_[range_ - i];
1077 }
1078
1079 private:
1080
1081 const S& stack_;
1082 unsigned int range_;
1083 };
1084 }
1085
1086 #endif // not BISON_STACK_HH]
1087 dnl
1088 @output position.hh
1089 b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004])[
1090
1091 /**
1092 ** \file position.hh
1093 ** Define the Location class.
1094 */
1095
1096 #ifndef BISON_POSITION_HH
1097 # define BISON_POSITION_HH
1098
1099 # include <iostream>
1100 # include <string>
1101
1102 namespace yy
1103 {
1104 /** \brief Abstract a Position. */
1105 class Position
1106 {
1107 public:
1108 /** \brief Initial column number. */
1109 static const unsigned int initial_column = 0;
1110 /** \brief Initial line number. */
1111 static const unsigned int initial_line = 1;
1112
1113 /** \name Ctor & dtor.
1114 ** \{ */
1115 public:
1116 /** \brief Construct a Position. */
1117 Position () :
1118 filename (),
1119 line (initial_line),
1120 column (initial_column)
1121 {
1122 }
1123 /** \} */
1124
1125
1126 /** \name Line and Column related manipulators
1127 ** \{ */
1128 public:
1129 /** \brief (line related) Advance to the COUNT next lines. */
1130 inline void lines (int count = 1)
1131 {
1132 column = initial_column;
1133 line += count;
1134 }
1135
1136 /** \brief (column related) Advance to the COUNT next columns. */
1137 inline void columns (int count = 1)
1138 {
1139 int leftmost = initial_column;
1140 int current = column;
1141 if (leftmost <= current + count)
1142 column += count;
1143 else
1144 column = initial_column;
1145 }
1146 /** \} */
1147
1148 public:
1149 /** \brief File name to which this position refers. */
1150 std::string filename;
1151 /** \brief Current line number. */
1152 unsigned int line;
1153 /** \brief Current column number. */
1154 unsigned int column;
1155 };
1156
1157 /** \brief Add and assign a Position. */
1158 inline const Position&
1159 operator+= (Position& res, const int width)
1160 {
1161 res.columns (width);
1162 return res;
1163 }
1164
1165 /** \brief Add two Position objects. */
1166 inline const Position
1167 operator+ (const Position& begin, const int width)
1168 {
1169 Position res = begin;
1170 return res += width;
1171 }
1172
1173 /** \brief Add and assign a Position. */
1174 inline const Position&
1175 operator-= (Position& res, const int width)
1176 {
1177 return res += -width;
1178 }
1179
1180 /** \brief Add two Position objects. */
1181 inline const Position
1182 operator- (const Position& begin, const int width)
1183 {
1184 return begin + -width;
1185 }
1186
1187 /** \brief Intercept output stream redirection.
1188 ** \param ostr the destination output stream
1189 ** \param pos a reference to the Position to redirect
1190 */
1191 inline std::ostream&
1192 operator<< (std::ostream& ostr, const Position& pos)
1193 {
1194 if (!pos.filename.empty ())
1195 ostr << pos.filename << ':';
1196 return ostr << pos.line << '.' << pos.column;
1197 }
1198
1199 }
1200 #endif // not BISON_POSITION_HH]
1201 @output location.hh
1202 b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004])[
1203
1204 /**
1205 ** \file location.hh
1206 ** Define the Location class.
1207 */
1208
1209 #ifndef BISON_LOCATION_HH
1210 # define BISON_LOCATION_HH
1211
1212 # include <iostream>
1213 # include <string>
1214 # include "position.hh"
1215
1216 namespace yy
1217 {
1218
1219 /** \brief Abstract a Location. */
1220 class Location
1221 {
1222 /** \name Ctor & dtor.
1223 ** \{ */
1224 public:
1225 /** \brief Construct a Location. */
1226 Location (void) :
1227 begin (),
1228 end ()
1229 {
1230 }
1231 /** \} */
1232
1233
1234 /** \name Line and Column related manipulators
1235 ** \{ */
1236 public:
1237 /** \brief Reset initial location to final location. */
1238 inline void step (void)
1239 {
1240 begin = end;
1241 }
1242
1243 /** \brief Extend the current location to the COUNT next columns. */
1244 inline void columns (unsigned int count = 1)
1245 {
1246 end += count;
1247 }
1248
1249 /** \brief Extend the current location to the COUNT next lines. */
1250 inline void lines (unsigned int count = 1)
1251 {
1252 end.lines (count);
1253 }
1254 /** \} */
1255
1256
1257 public:
1258 /** \brief Beginning of the located region. */
1259 Position begin;
1260 /** \brief End of the located region. */
1261 Position end;
1262 };
1263
1264 /** \brief Join two Location objects to create a Location. */
1265 inline const Location operator+ (const Location& begin, const Location& end)
1266 {
1267 Location res = begin;
1268 res.end = end.end;
1269 return res;
1270 }
1271
1272 /** \brief Add two Location objects */
1273 inline const Location operator+ (const Location& begin, unsigned int width)
1274 {
1275 Location res = begin;
1276 res.columns (width);
1277 return res;
1278 }
1279
1280 /** \brief Add and assign a Location */
1281 inline Location& operator+= (Location& res, unsigned int width)
1282 {
1283 res.columns (width);
1284 return res;
1285 }
1286
1287 /** \brief Intercept output stream redirection.
1288 ** \param ostr the destination output stream
1289 ** \param loc a reference to the Location to redirect
1290 **
1291 ** Avoid duplicate information.
1292 */
1293 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
1294 {
1295 Position last = loc.end - 1;
1296 ostr << loc.begin;
1297 if (loc.begin.filename != last.filename)
1298 ostr << '-' << last;
1299 else if (loc.begin.line != last.line)
1300 ostr << '-' << last.line << '.' << last.column;
1301 else if (loc.begin.column != last.column)
1302 ostr << '-' << last.column;
1303 return ostr;
1304 }
1305
1306 }
1307
1308 #endif // not BISON_LOCATION_HH]