2 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
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.
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.
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
20 ## ---------------- ##
22 ## ---------------- ##
24 # Default parser class name.
25 m4_define_default([b4_parser_class_name
], [parser
])
29 ## ----------------- ##
30 ## Semantic Values. ##
31 ## ----------------- ##
34 # b4_lhs_value([TYPE])
35 # --------------------
36 # Expansion of $<TYPE>$.
37 m4_define([b4_lhs_value
],
38 [(yyval
[]m4_ifval([$
1], [.$
1]))])
41 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42 # --------------------------------------
43 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
45 m4_define([b4_rhs_value
],
46 [(yysemantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3]))])
48 m4_define_default([b4_location_type
], [location
])
49 m4_define_default([b4_filename_type
], [std::string
])
54 m4_define([b4_lhs_location
],
58 # b4_rhs_location(RULE-LENGTH, NUM)
59 # ---------------------------------
60 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
62 m4_define([b4_rhs_location
],
63 [(yylocation_stack_@
{m4_eval([$
1 - $
2])@
})])
68 # Extra formal arguments of the constructor.
69 # Change the parameter names from "foo" into "foo_yyarg", so that
70 # there is no collision bw the user chosen attribute name, and the
71 # argument name in the constructor.
72 m4_define([b4_parse_param_decl
],
73 [m4_ifset([b4_parse_param
],
74 [m4_map_sep([b4_parse_param_decl_1
], [, ], [b4_parse_param
])])])
76 m4_define([b4_parse_param_decl_1
],
83 # Extra initialisations of the constructor.
84 m4_define([b4_parse_param_cons
],
85 [m4_ifset([b4_parse_param
],
87 b4_cc_constructor_calls(b4_parse_param
)])])
88 m4_define([b4_cc_constructor_calls
],
89 [m4_map_sep([b4_cc_constructor_call
], [,
91 m4_define([b4_cc_constructor_call
],
96 # Extra instance variables.
97 m4_define([b4_parse_param_vars
],
98 [m4_ifset([b4_parse_param
],
100 /* User arguments. */
101 b4_cc_var_decls(b4_parse_param
)])])
102 m4_define([b4_cc_var_decls
],
103 [m4_map_sep([b4_cc_var_decl
], [
105 m4_define([b4_cc_var_decl
],
110 # We do want M4 expansion after # for CPP macros.
113 m4_if(b4_defines_flag
, 0, [],
114 [@output @output_header_name@
115 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
117 /* FIXME: This is wrong, we want computed header guards.
118 I don't know why the macros are missing now. :( */
119 #ifndef PARSER_HEADER_H
120 # define PARSER_HEADER_H
125 /* Using locations. */
126 #define YYLSP_NEEDED ]b4_locations_flag[
134 ]b4_token_defines(b4_tokens
)[
136 /* Copy the first part of user declarations. */
139 ]/* Line __line__ of lalr1.cc. */
140 b4_syncline([@oline@
], [@ofile@
])[
143 #include "location.hh"
145 /* Enabling traces. */
147 # define YYDEBUG ]b4_debug[
150 /* Enabling verbose error message. */
151 #ifndef YYERROR_VERBOSE
152 # define YYERROR_VERBOSE ]b4_error_verbose[
155 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
156 ]m4_ifdef([b4_stype
],
157 [b4_syncline([b4_stype_line
], [b4_filename
])
158 union YYSTYPE b4_stype
;
159 /* Line __line__ of lalr1.cc. */
160 b4_syncline([@oline@
], [@ofile@
])],
161 [typedef int YYSTYPE
;])[
162 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
163 # define YYSTYPE_IS_DECLARED 1
164 # define YYSTYPE_IS_TRIVIAL 1
167 /* Copy the second part of user declarations. */
170 ]/* Line __line__ of lalr1.cc. */
171 b4_syncline([@oline@
], [@ofile@
])[
172 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
173 If N is 0, then set CURRENT to the empty location which ends
174 the previous symbol: RHS[0] (always defined). */
176 #ifndef YYLLOC_DEFAULT
177 # define YYLLOC_DEFAULT(Current, Rhs, N) \
181 (Current).begin = (Rhs)[1].begin; \
182 (Current).end = (Rhs)[N].end; \
186 (Current).begin = (Current).end = (Rhs)[0].end; \
193 class ]b4_parser_class_name
[;
195 template <typename P
>
201 struct traits
<]b4_parser_class_name
[>
203 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
204 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
205 typedef int state_type
;
206 typedef YYSTYPE semantic_type
;
207 typedef ]b4_location_type
[ location_type
;
214 class ]b4_parser_class_name
[
217 /// Internal symbol numbers.
218 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
219 /// A type to store symbol numbers and -1.
220 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
222 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
223 /// Symbol semantic values.
224 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
225 /// Symbol locations.
226 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
228 /// State stack type.
229 typedef stack
<state_type
> state_stack
;
230 /// Semantic value stack type.
231 typedef stack
<semantic_type
> semantic_stack
;
232 /// location stack type.
233 typedef stack
<location_type
> location_stack
;
235 /// Build a parser object.
236 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
238 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
242 virtual ~]b4_parser_class_name
[ ()
247 /// \returns 0 iff parsing succeeded.
248 virtual int parse ();
250 /// The current debugging stream.
251 std::ostream
& debug_stream () const;
252 /// Set the current debugging stream.
253 void set_debug_stream (std::ostream
&);
255 /// Type for debugging levels.
256 typedef int debug_level_type
;
257 /// The current debugging level.
258 debug_level_type
debug_level () const;
259 /// Set the current debugging level.
260 void set_debug_level (debug_level_type l
);
264 /// Call the scanner.
265 virtual void yylex_ ();
267 /// Report a syntax error.
268 /// \param loc where the syntax error is found.
269 /// \param msg a description of the syntax error.
270 virtual void error (const location_type
& loc
, const std::string
& msg
);
272 /// Generate an error message, and invoke error.
273 virtual void yyreport_syntax_error_ ();
276 /// \brief Report a symbol on the debug stream.
277 /// \param yytype The token type.
278 /// \param yyvaluep Its semantic value.
279 /// \param yylocationp Its location.
280 virtual void yysymprint_ (int yytype
,
281 const semantic_type
* yyvaluep
,
282 const location_type
* yylocationp
);
283 #endif /* ! YYDEBUG */
287 state_stack yystate_stack_
;
288 /// The semantic value stack.
289 semantic_stack yysemantic_stack_
;
290 /// The location stack.
291 location_stack yylocation_stack_
;
294 /// For a state, the index in \a yytable_ of its portion.
295 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
296 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
298 /// For a state, default rule to reduce.
299 /// Unless\a yytable_ specifies something else to do.
300 /// Zero means the default is an error.
301 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
303 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
304 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
306 /// What to do in a state.
307 /// \a yytable_[yypact_[s]]: what to do in state \a s.
308 /// - if positive, shift that token.
309 /// - if negative, reduce the rule which number is the opposite.
310 /// - if zero, do what YYDEFACT says.
311 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
312 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
314 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
316 /// For a state, its accessing symbol.
317 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
319 /// For a rule, its LHS.
320 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
321 /// For a rule, its RHS length.
322 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
324 #if YYDEBUG || YYERROR_VERBOSE
325 /// For a symbol, its name in clear.
326 static const char* const yyname_
[];
330 /// A `-1'-separated list of the rules' RHS.
331 static const rhs_number_type yyrhs_
[];
332 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
333 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
334 /// For each rule, its source line number.
335 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
336 /// For each scanner token number, its symbol number.
337 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
338 /// Report on the debug stream that the rule \a r is going to be reduced.
339 virtual void yyreduce_print_ (int r
);
340 /// Print the state stack on the debug stream.
341 virtual void yystack_print_ ();
344 /// Convert a scanner token number to a symbol number.
345 inline token_number_type
yytranslate_ (int token
);
347 /// \brief Reclaim the memory associated to a symbol.
348 /// \param yymsg Why this token is reclaimed.
349 /// \param yytype The symbol type.
350 /// \param yyvaluep Its semantic value.
351 /// \param yylocationp Its location.
352 inline void yydestruct_ (const char* yymsg
,
354 semantic_type
* yyvaluep
,
355 location_type
* yylocationp
);
357 /// Pop \a n symbols the three stacks.
358 inline void yypop_ (unsigned int n
= 1);
361 static const int yyeof_
;
362 /* LAST_ -- Last index in TABLE_. */
363 static const int yylast_
;
364 static const int yynnts_
;
365 static const int yyempty_
;
366 static const int yyfinal_
;
367 static const int yyterror_
;
368 static const int yyerrcode_
;
369 static const int yyntokens_
;
370 static const unsigned int yyuser_token_number_max_
;
371 static const token_number_type yyundef_token_
;
378 /* Error handling. */
384 std::ostream
* yycdebug_
;
386 /* Look-ahead and look-ahead in internal form. */
390 /// Semantic value of the look-ahead.
391 semantic_type yylval
;
392 /// Location of the look-ahead.
393 location_type yylloc
;
394 /// The locations where the error started and ended.
395 location yyerror_range_
[2];
401 ]b4_parse_param_vars
[
405 #endif /* ! defined PARSER_HEADER_H */]
407 @output @output_parser_name@
408 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
410 m4_if(b4_prefix
[], [yy
], [],
412 // Take the name prefix into account.
413 #define yylex b4_prefix[]lex])
414 m4_if(b4_defines_flag
, 0, [],
416 #include @output_header_name@])[
418 /* A pseudo ostream that takes yydebug_ into account. */
420 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
423 /* Enable debugging if requested. */
426 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
430 *yycdebug_ << (Title) << ' '; \
431 yysymprint_ ((Type), (Value), (Location)); \
432 *yycdebug_ << std::endl; \
436 # define YY_REDUCE_PRINT(Rule) \
439 yyreduce_print_ (Rule); \
442 # define YY_STACK_PRINT() \
450 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
451 # define YY_REDUCE_PRINT(Rule)
452 # define YY_STACK_PRINT()
454 #endif /* !YYDEBUG */
456 #define YYACCEPT goto yyacceptlab
457 #define YYABORT goto yyabortlab
458 #define YYERROR goto yyerrorlab
461 /*--------------------------------.
462 | Print this symbol on YYOUTPUT. |
463 `--------------------------------*/
466 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
467 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
469 /* Pacify ``unused variable'' warnings. */
472 /* Backward compatibility, but should be removed eventually. */
473 std::ostream
& cdebug_
= *yycdebug_
;
476 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
477 << ' ' << yyname_
[yytype
] << " ("
478 << *yylocationp
<< ": ";
481 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
487 #endif /* ! YYDEBUG */
490 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
491 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
493 /* Pacify ``unused variable'' warnings. */
497 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
501 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
508 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
510 yystate_stack_
.pop (n
);
511 yysemantic_stack_
.pop (n
);
512 yylocation_stack_
.pop (n
);
516 yy::]b4_parser_class_name
[::debug_stream () const
522 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
528 yy::]b4_parser_class_name
[::debug_level_type
529 yy::]b4_parser_class_name
[::debug_level () const
535 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
542 yy::]b4_parser_class_name
[::parse ()
544 YYCDEBUG
<< "Starting parse" << std::endl
;
553 ]m4_ifdef([b4_initial_action
], [
554 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
555 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
556 /* User initialization code. */
558 m4_popdef([b4_dollar_dollar
])dnl
559 m4_popdef([b4_at_dollar
])dnl
560 /* Line __line__ of yacc.c. */
561 b4_syncline([@oline@
], [@ofile@
])])dnl
563 [ /* Initialize the stacks. The initial state will be pushed in
564 yynewstate, since the latter expects the semantical and the
565 location values to have been already stored, initialize these
566 stacks with a primary value. */
567 yystate_stack_
= state_stack (0);
568 yysemantic_stack_
= semantic_stack (0);
569 yylocation_stack_
= location_stack (0);
570 yysemantic_stack_
.push (yylval
);
571 yylocation_stack_
.push (yylloc
);
575 yystate_stack_
.push (yystate_
);
576 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
582 /* Try to take a decision without look-ahead. */
583 yyn_
= yypact_
[yystate_
];
584 if (yyn_
== yypact_ninf_
)
587 /* Read a look-ahead token. */
588 if (yylooka_
== yyempty_
)
591 /* Convert token to internal form. */
592 if (yylooka_
<= yyeof_
)
594 yylooka_
= yyilooka_
= yyeof_
;
595 YYCDEBUG
<< "Now at end of input." << std::endl
;
599 yyilooka_
= yytranslate_ (yylooka_
);
600 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &yylval
, &yylloc
);
603 /* If the proper action on seeing token ILOOKA_ is to reduce or to
604 detect an error, take that action. */
606 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
609 /* Reduce or error. */
610 yyn_
= yytable_
[yyn_
];
613 if (yyn_
== yytable_ninf_
)
625 if (yyn_
== yyfinal_
)
628 /* Shift the look-ahead token. */
629 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &yylval
, &yylloc
);
631 /* Discard the token being shifted unless it is eof. */
632 if (yylooka_
!= yyeof_
)
635 yysemantic_stack_
.push (yylval
);
636 yylocation_stack_
.push (yylloc
);
638 /* Count tokens shifted since error; after three, turn off error
646 /*-----------------------------------------------------------.
647 | yydefault -- do the default action for the current state. |
648 `-----------------------------------------------------------*/
650 yyn_
= yydefact_
[yystate_
];
655 /*-----------------------------.
656 | yyreduce -- Do a reduction. |
657 `-----------------------------*/
659 yylen_
= yyr2_
[yyn_
];
660 /* If LEN_ is nonzero, implement the default value of the action:
661 `$$ = $1'. Otherwise, use the top of the stack.
663 Otherwise, the following line sets YYVAL to garbage.
664 This behavior is undocumented and Bison
665 users should not rely upon it. */
667 yyval
= yysemantic_stack_
[yylen_
- 1];
669 yyval
= yysemantic_stack_
[0];
672 slice
<location_type
, location_stack
> slice (yylocation_stack_
, yylen_
);
673 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
675 YY_REDUCE_PRINT (yyn_
);
681 ]/* Line __line__ of lalr1.cc. */
682 b4_syncline([@oline@
], [@ofile@
])[
688 yysemantic_stack_
.push (yyval
);
689 yylocation_stack_
.push (yyloc
);
691 /* Shift the result of the reduction. */
693 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
694 if (0 <= yystate_
&& yystate_
<= yylast_
695 && yycheck_
[yystate_
] == yystate_stack_
[0])
696 yystate_
= yytable_
[yystate_
];
698 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
701 /*------------------------------------.
702 | yyerrlab -- here on detecting error |
703 `------------------------------------*/
705 /* If not already recovering from an error, report this error. */
706 yyreport_syntax_error_ ();
708 yyerror_range_
[0] = yylloc
;
709 if (yyerrstatus_
== 3)
711 /* If just tried and failed to reuse look-ahead token after an
712 error, discard it. */
714 /* Return failure if at end of input. */
715 if (yylooka_
<= yyeof_
)
717 /* If at end of input, pop the error token,
718 then the rest of the stack, then return failure. */
719 if (yylooka_
== yyeof_
)
722 yyerror_range_
[0] = yylocation_stack_
[0];
724 if (yystate_stack_
.height () == 1)
726 yydestruct_ ("Error: popping",
727 yystos_
[yystate_stack_
[0]],
728 &yysemantic_stack_
[0],
729 &yylocation_stack_
[0]);
734 yydestruct_ ("Error: discarding", yyilooka_
, &yylval
, &yylloc
);
739 /* Else will try to reuse look-ahead token after shifting the error
744 /*---------------------------------------------------.
745 | yyerrorlab -- error raised explicitly by YYERROR. |
746 `---------------------------------------------------*/
750 /* Pacify GCC when the user code never invokes YYERROR and the label
751 yyerrorlab therefore never appears in user code. */
756 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
758 yystate_
= yystate_stack_
[0];
761 /*-------------------------------------------------------------.
762 | yyerrlab1 -- common code for both syntax error and YYERROR. |
763 `-------------------------------------------------------------*/
765 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
769 yyn_
= yypact_
[yystate_
];
770 if (yyn_
!= yypact_ninf_
)
773 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
775 yyn_
= yytable_
[yyn_
];
781 /* Pop the current state because it cannot handle the error token. */
782 if (yystate_stack_
.height () == 1)
785 yyerror_range_
[0] = yylocation_stack_
[0];
786 yydestruct_ ("Error: popping",
788 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
790 yystate_
= yystate_stack_
[0];
794 if (yyn_
== yyfinal_
)
797 yyerror_range_
[1] = yylloc
;
798 // Using YYLLOC is tempting, but would change the location of
799 // the look-ahead. YYLOC is available though.
800 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
801 yysemantic_stack_
.push (yylval
);
802 yylocation_stack_
.push (yyloc
);
804 /* Shift the error token. */
805 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
806 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
817 /* Free the lookahead. */
818 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &yylval
, &yylloc
);
824 yy::]b4_parser_class_name
[::yylex_ ()
826 YYCDEBUG
<< "Reading a token: ";
828 yylooka_
= yylex (&yylval
, &yylloc
);
830 yylooka_
= yylex (&yylval
);
834 // Generate an error message, and invoke error.
836 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
838 /* If not already recovering from an error, report this error. */
844 yyn_
= yypact_
[yystate_
];
845 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
847 /* Start YYX at -YYN if negative to avoid negative indexes in
849 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
851 /* Stay within bounds of both yycheck and yytname. */
852 int yychecklim
= yylast_
- yyn_
;
853 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
855 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
856 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
859 message
= "syntax error, unexpected ";
860 message
+= yyname_
[yyilooka_
];
864 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
865 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
867 message
+= (!count
++) ? ", expecting " : " or ";
868 message
+= yyname_
[x
];
874 message
= "syntax error";
875 error (yylloc
, message
);
880 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
882 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
883 const ]b4_int_type_for([b4_pact
])[
884 yy::]b4_parser_class_name
[::yypact_
[] =
889 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
890 doesn't specify something else to do. Zero means the default is an
892 const ]b4_int_type_for([b4_defact
])[
893 yy::]b4_parser_class_name
[::yydefact_
[] =
898 /* YYPGOTO[NTERM-NUM]. */
899 const ]b4_int_type_for([b4_pgoto
])[
900 yy::]b4_parser_class_name
[::yypgoto_
[] =
905 /* YYDEFGOTO[NTERM-NUM]. */
906 const ]b4_int_type_for([b4_defgoto
])[
907 yy::]b4_parser_class_name
[::yydefgoto_
[] =
912 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
913 positive, shift that token. If negative, reduce the rule which
914 number is the opposite. If zero, do what YYDEFACT says. */
915 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
916 const ]b4_int_type_for([b4_table
])[
917 yy::]b4_parser_class_name
[::yytable_
[] =
923 const ]b4_int_type_for([b4_check
])[
924 yy::]b4_parser_class_name
[::yycheck_
[] =
929 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
930 symbol of state STATE-NUM. */
931 const ]b4_int_type_for([b4_stos
])[
932 yy::]b4_parser_class_name
[::yystos_
[] =
938 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
940 const ]b4_int_type_for([b4_toknum
])[
941 yy::]b4_parser_class_name
[::yytoken_number_
[] =
947 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
948 const ]b4_int_type_for([b4_r1
])[
949 yy::]b4_parser_class_name
[::yyr1_
[] =
954 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
955 const ]b4_int_type_for([b4_r2
])[
956 yy::]b4_parser_class_name
[::yyr2_
[] =
961 #if YYDEBUG || YYERROR_VERBOSE
962 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
963 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
965 const yy::]b4_parser_class_name
[::yyname_
[] =
972 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
973 const yy::]b4_parser_class_name
[::rhs_number_type
974 yy::]b4_parser_class_name
[::yyrhs_
[] =
979 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
981 const ]b4_int_type_for([b4_prhs
])[
982 yy::]b4_parser_class_name
[::yyprhs_
[] =
987 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
988 const ]b4_int_type_for([b4_rline
])[
989 yy::]b4_parser_class_name
[::yyrline_
[] =
994 // Print the state stack on the debug stream.
996 yy::]b4_parser_class_name
[::yystack_print_ ()
998 *yycdebug_
<< "Stack now";
999 for (state_stack::const_iterator i
= yystate_stack_
.begin ();
1000 i
!= yystate_stack_
.end (); ++i
)
1001 *yycdebug_
<< ' ' << *i
;
1002 *yycdebug_
<< std::endl
;
1005 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1007 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1009 unsigned int yylno
= yyrline_
[yyrule
];
1010 /* Print the symbols being reduced, and their result. */
1011 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1012 << " (line " << yylno
<< "), ";
1013 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1014 0 <= yyrhs_
[i
]; ++i
)
1015 *yycdebug_
<< yyname_
[yyrhs_
[i
]] << ' ';
1016 *yycdebug_
<< "-> " << yyname_
[yyr1_
[yyn_
]] << std::endl
;
1020 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1021 yy::]b4_parser_class_name
[::token_number_type
1022 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1025 const token_number_type
1030 if ((unsigned int) token
<= yyuser_token_number_max_
)
1031 return translate_table
[token
];
1033 return yyundef_token_
;
1036 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1037 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1038 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1039 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1040 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1041 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1042 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1043 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1045 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1046 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1051 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
1053 #ifndef BISON_STACK_HH
1054 # define BISON_STACK_HH
1060 template <class T
, class S
= std::deque
<T
> >
1065 // Hide our reversed order.
1066 typedef typename
S::reverse_iterator iterator
;
1067 typedef typename
S::const_reverse_iterator const_iterator
;
1073 stack (unsigned int n
) : seq_ (n
)
1079 operator [] (unsigned int i
)
1086 operator [] (unsigned int i
) const
1095 seq_
.push_front (t
);
1100 pop (unsigned int n
= 1)
1110 return seq_
.size ();
1113 inline const_iterator
begin () const { return seq_
.rbegin (); }
1114 inline const_iterator
end () const { return seq_
.rend (); }
1121 template <class T
, class S
= stack
<T
> >
1126 slice (const S
& stack
,
1127 unsigned int range
) : stack_ (stack
),
1134 operator [] (unsigned int i
) const
1136 return stack_
[range_
- i
];
1142 unsigned int range_
;
1146 #endif // not BISON_STACK_HH]
1149 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1152 ** \file position.hh
1153 ** Define the position class.
1156 #ifndef BISON_POSITION_HH
1157 # define BISON_POSITION_HH
1159 # include <iostream>
1164 /// Abstract a position.
1168 /// Initial column number.
1169 static const unsigned int initial_column
= 0;
1170 /// Initial line number.
1171 static const unsigned int initial_line
= 1;
1173 /** \name Ctor & dtor.
1176 /// Construct a position.
1179 line (initial_line
),
1180 column (initial_column
)
1186 /** \name Line and Column related manipulators
1189 /// (line related) Advance to the COUNT next lines.
1190 inline void lines (int count
= 1)
1192 column
= initial_column
;
1196 /// (column related) Advance to the COUNT next columns.
1197 inline void columns (int count
= 1)
1199 int leftmost
= initial_column
;
1200 int current
= column
;
1201 if (leftmost
<= current
+ count
)
1204 column
= initial_column
;
1209 /// File name to which this position refers.
1210 ]b4_filename_type
[* filename
;
1211 /// Current line number.
1213 /// Current column number.
1214 unsigned int column
;
1217 /// Add and assign a position.
1218 inline const position
&
1219 operator+= (position
& res
, const int width
)
1221 res
.columns (width
);
1225 /// Add two position objects.
1226 inline const position
1227 operator+ (const position
& begin
, const int width
)
1229 position res
= begin
;
1230 return res
+= width
;
1233 /// Add and assign a position.
1234 inline const position
&
1235 operator-= (position
& res
, const int width
)
1237 return res
+= -width
;
1240 /// Add two position objects.
1241 inline const position
1242 operator- (const position
& begin
, const int width
)
1244 return begin
+ -width
;
1247 /** \brief Intercept output stream redirection.
1248 ** \param ostr the destination output stream
1249 ** \param pos a reference to the position to redirect
1251 inline std::ostream
&
1252 operator<< (std::ostream
& ostr
, const position
& pos
)
1255 ostr
<< *pos
.filename
<< ':';
1256 return ostr
<< pos
.line
<< '.' << pos
.column
;
1260 #endif // not BISON_POSITION_HH]
1262 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1265 ** \file location.hh
1266 ** Define the location class.
1269 #ifndef BISON_LOCATION_HH
1270 # define BISON_LOCATION_HH
1272 # include <iostream>
1274 # include "position.hh"
1279 /// Abstract a location.
1282 /** \name Ctor & dtor.
1285 /// Construct a location.
1294 /** \name Line and Column related manipulators
1297 /// Reset initial location to final location.
1298 inline void step (void)
1303 /// Extend the current location to the COUNT next columns.
1304 inline void columns (unsigned int count
= 1)
1309 /// Extend the current location to the COUNT next lines.
1310 inline void lines (unsigned int count
= 1)
1318 /// Beginning of the located region.
1320 /// End of the located region.
1324 /// Join two location objects to create a location.
1325 inline const location
operator+ (const location
& begin
, const location
& end
)
1327 location res
= begin
;
1332 /// Add two location objects.
1333 inline const location
operator+ (const location
& begin
, unsigned int width
)
1335 location res
= begin
;
1336 res
.columns (width
);
1340 /// Add and assign a location.
1341 inline location
& operator+= (location
& res
, unsigned int width
)
1343 res
.columns (width
);
1347 /** \brief Intercept output stream redirection.
1348 ** \param ostr the destination output stream
1349 ** \param loc a reference to the location to redirect
1351 ** Avoid duplicate information.
1353 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1355 position last
= loc
.end
- 1;
1358 && (!loc
.begin
.filename
1359 || *loc
.begin
.filename
!= *last
.filename
))
1360 ostr
<< '-' << last
;
1361 else if (loc
.begin
.line
!= last
.line
)
1362 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1363 else if (loc
.begin
.column
!= last
.column
)
1364 ostr
<< '-' << last
.column
;
1370 #endif // not BISON_LOCATION_HH]