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