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