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