3 # C++ skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 ## ---------------- ##
24 ## ---------------- ##
26 # Default parser class name.
27 m4_define_default([b4_parser_class_name
], [parser
])
31 ## ----------------- ##
32 ## Semantic Values. ##
33 ## ----------------- ##
36 # b4_lhs_value([TYPE])
37 # --------------------
38 # Expansion of $<TYPE>$.
39 m4_define([b4_lhs_value
],
40 [(yyval
[]m4_ifval([$
1], [.$
1]))])
43 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
44 # --------------------------------------
45 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
47 m4_define([b4_rhs_value
],
48 [(yysemantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3]))])
50 m4_define_default([b4_location_type
], [location
])
51 m4_define_default([b4_filename_type
], [std::string
])
56 m4_define([b4_lhs_location
],
60 # b4_rhs_location(RULE-LENGTH, NUM)
61 # ---------------------------------
62 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
64 m4_define([b4_rhs_location
],
65 [(yylocation_stack_@
{m4_eval([$
1 - $
2])@
})])
70 # Extra formal arguments of the constructor.
71 # Change the parameter names from "foo" into "foo_yyarg", so that
72 # there is no collision bw the user chosen attribute name, and the
73 # argument name in the constructor.
74 m4_define([b4_parse_param_decl
],
75 [m4_ifset([b4_parse_param
],
76 [m4_map_sep([b4_parse_param_decl_1
], [, ], [b4_parse_param
])])])
78 m4_define([b4_parse_param_decl_1
],
85 # Extra initialisations of the constructor.
86 m4_define([b4_parse_param_cons
],
87 [m4_ifset([b4_parse_param
],
89 b4_cc_constructor_calls(b4_parse_param
)])])
90 m4_define([b4_cc_constructor_calls
],
91 [m4_map_sep([b4_cc_constructor_call
], [,
93 m4_define([b4_cc_constructor_call
],
98 # Extra instance variables.
99 m4_define([b4_parse_param_vars
],
100 [m4_ifset([b4_parse_param
],
102 /* User arguments. */
103 b4_cc_var_decls(b4_parse_param
)])])
104 m4_define([b4_cc_var_decls
],
105 [m4_map_sep([b4_cc_var_decl
], [
107 m4_define([b4_cc_var_decl
],
112 # We do want M4 expansion after # for CPP macros.
115 m4_if(b4_defines_flag
, 0, [],
116 [@output @output_header_name@
117 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
119 /* FIXME: This is wrong, we want computed header guards.
120 I don't know why the macros are missing now. :( */
121 #ifndef PARSER_HEADER_H
122 # define PARSER_HEADER_H
127 /* Using locations. */
128 #define YYLSP_NEEDED ]b4_locations_flag[
136 ]b4_token_defines(b4_tokens
)[
138 /* Copy the first part of user declarations. */
141 ]/* Line __line__ of lalr1.cc. */
142 b4_syncline([@oline@
], [@ofile@
])[
145 #include "location.hh"
147 /* Enabling traces. */
149 # define YYDEBUG ]b4_debug[
152 /* Enabling verbose error message. */
153 #ifndef YYERROR_VERBOSE
154 # define YYERROR_VERBOSE ]b4_error_verbose[
157 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
158 ]m4_ifdef([b4_stype
],
159 [b4_syncline([b4_stype_line
], [b4_filename
])
160 union YYSTYPE b4_stype
;
161 /* Line __line__ of lalr1.cc. */
162 b4_syncline([@oline@
], [@ofile@
])],
163 [typedef int YYSTYPE
;])[
164 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
165 # define YYSTYPE_IS_DECLARED 1
166 # define YYSTYPE_IS_TRIVIAL 1
169 /* Copy the second part of user declarations. */
172 ]/* Line __line__ of lalr1.cc. */
173 b4_syncline([@oline@
], [@ofile@
])[
174 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
175 If N is 0, then set CURRENT to the empty location which ends
176 the previous symbol: RHS[0] (always defined). */
178 #ifndef YYLLOC_DEFAULT
179 # define YYLLOC_DEFAULT(Current, Rhs, N) \
183 (Current).begin = (Rhs)[1].begin; \
184 (Current).end = (Rhs)[N].end; \
188 (Current).begin = (Current).end = (Rhs)[0].end; \
195 class ]b4_parser_class_name
[;
197 template <typename P
>
203 struct traits
<]b4_parser_class_name
[>
205 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
206 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
207 typedef int state_type
;
208 typedef YYSTYPE semantic_type
;
209 typedef ]b4_location_type
[ location_type
;
216 class ]b4_parser_class_name
[
218 /// Symbol semantic values.
219 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
220 /// Symbol locations.
221 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
224 /// Build a parser object.
225 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
227 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
231 virtual ~]b4_parser_class_name
[ ()
236 /// \returns 0 iff parsing succeeded.
237 virtual int parse ();
239 /// The current debugging stream.
240 std::ostream
& debug_stream () const;
241 /// Set the current debugging stream.
242 void set_debug_stream (std::ostream
&);
244 /// Type for debugging levels.
245 typedef int debug_level_type
;
246 /// The current debugging level.
247 debug_level_type
debug_level () const;
248 /// Set the current debugging level.
249 void set_debug_level (debug_level_type l
);
253 /// Call the scanner.
254 virtual void yylex_ ();
256 /// Report a syntax error.
257 /// \param loc where the syntax error is found.
258 /// \param msg a description of the syntax error.
259 virtual void error (const location_type
& loc
, const std::string
& msg
);
261 /// Generate an error message, and invoke error.
262 virtual void yyreport_syntax_error_ ();
265 /// \brief Report a symbol on the debug stream.
266 /// \param yytype The token type.
267 /// \param yyvaluep Its semantic value.
268 /// \param yylocationp Its location.
269 virtual void yysymprint_ (int yytype
,
270 const semantic_type
* yyvaluep
,
271 const location_type
* yylocationp
);
272 #endif /* ! YYDEBUG */
276 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
277 /// State stack type.
278 typedef stack
<state_type
> state_stack_type
;
279 /// Semantic value stack type.
280 typedef stack
<semantic_type
> semantic_stack_type
;
281 /// location stack type.
282 typedef stack
<location_type
> location_stack_type
;
285 state_stack_type yystate_stack_
;
286 /// The semantic value stack.
287 semantic_stack_type yysemantic_stack_
;
288 /// The location stack.
289 location_stack_type yylocation_stack_
;
291 /// Internal symbol numbers.
292 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
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 type to store symbol numbers and -1.
331 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
332 /// A `-1'-separated list of the rules' RHS.
333 static const rhs_number_type yyrhs_
[];
334 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
335 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
336 /// For each rule, its source line number.
337 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
338 /// For each scanner token number, its symbol number.
339 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
340 /// Report on the debug stream that the rule \a r is going to be reduced.
341 virtual void yyreduce_print_ (int r
);
342 /// Print the state stack on the debug stream.
343 virtual void yystack_print_ ();
346 /// Convert a scanner token number to a symbol number.
347 inline token_number_type
yytranslate_ (int token
);
349 /// \brief Reclaim the memory associated to a symbol.
350 /// \param yymsg Why this token is reclaimed.
351 /// \param yytype The symbol type.
352 /// \param yyvaluep Its semantic value.
353 /// \param yylocationp Its location.
354 inline void yydestruct_ (const char* yymsg
,
356 semantic_type
* yyvaluep
,
357 location_type
* yylocationp
);
359 /// Pop \a n symbols the three stacks.
360 inline void yypop_ (unsigned int n
= 1);
363 static const int yyeof_
;
364 /* LAST_ -- Last index in TABLE_. */
365 static const int yylast_
;
366 static const int yynnts_
;
367 static const int yyempty_
;
368 static const int yyfinal_
;
369 static const int yyterror_
;
370 static const int yyerrcode_
;
371 static const int yyntokens_
;
372 static const unsigned int yyuser_token_number_max_
;
373 static const token_number_type yyundef_token_
;
380 /* Error handling. */
386 std::ostream
* yycdebug_
;
388 /* Look-ahead and look-ahead in internal form. */
392 /// Semantic value of the look-ahead.
393 semantic_type yylval
;
394 /// Location of the look-ahead.
395 location_type yylloc
;
396 /// The locations where the error started and ended.
397 location yyerror_range_
[2];
403 ]b4_parse_param_vars
[
407 #endif /* ! defined PARSER_HEADER_H */]
409 @output @output_parser_name@
410 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
412 m4_if(b4_prefix
[], [yy
], [],
414 // Take the name prefix into account.
415 #define yylex b4_prefix[]lex])
416 m4_if(b4_defines_flag
, 0, [],
418 #include @output_header_name@])[
420 /* A pseudo ostream that takes yydebug_ into account. */
422 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
425 /* Enable debugging if requested. */
428 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
432 *yycdebug_ << (Title) << ' '; \
433 yysymprint_ ((Type), (Value), (Location)); \
434 *yycdebug_ << std::endl; \
438 # define YY_REDUCE_PRINT(Rule) \
441 yyreduce_print_ (Rule); \
444 # define YY_STACK_PRINT() \
452 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
453 # define YY_REDUCE_PRINT(Rule)
454 # define YY_STACK_PRINT()
456 #endif /* !YYDEBUG */
458 #define YYACCEPT goto yyacceptlab
459 #define YYABORT goto yyabortlab
460 #define YYERROR goto yyerrorlab
463 /*--------------------------------.
464 | Print this symbol on YYOUTPUT. |
465 `--------------------------------*/
468 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
469 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
471 /* Pacify ``unused variable'' warnings. */
474 /* Backward compatibility, but should be removed eventually. */
475 std::ostream
& cdebug_
= *yycdebug_
;
478 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
479 << ' ' << yyname_
[yytype
] << " ("
480 << *yylocationp
<< ": ";
483 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
489 #endif /* ! YYDEBUG */
492 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
493 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
495 /* Pacify ``unused variable'' warnings. */
500 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
504 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
511 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
513 yystate_stack_
.pop (n
);
514 yysemantic_stack_
.pop (n
);
515 yylocation_stack_
.pop (n
);
519 yy::]b4_parser_class_name
[::debug_stream () const
525 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
531 yy::]b4_parser_class_name
[::debug_level_type
532 yy::]b4_parser_class_name
[::debug_level () const
538 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
545 yy::]b4_parser_class_name
[::parse ()
547 YYCDEBUG
<< "Starting parse" << std::endl
;
556 ]m4_ifdef([b4_initial_action
], [
557 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
558 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
559 /* User initialization code. */
561 m4_popdef([b4_dollar_dollar
])dnl
562 m4_popdef([b4_at_dollar
])dnl
563 /* Line __line__ of yacc.c. */
564 b4_syncline([@oline@
], [@ofile@
])])dnl
566 [ /* Initialize the stacks. The initial state will be pushed in
567 yynewstate, since the latter expects the semantical and the
568 location values to have been already stored, initialize these
569 stacks with a primary value. */
570 yystate_stack_
= state_stack_type (0);
571 yysemantic_stack_
= semantic_stack_type (0);
572 yylocation_stack_
= location_stack_type (0);
573 yysemantic_stack_
.push (yylval
);
574 yylocation_stack_
.push (yylloc
);
578 yystate_stack_
.push (yystate_
);
579 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
585 /* Try to take a decision without look-ahead. */
586 yyn_
= yypact_
[yystate_
];
587 if (yyn_
== yypact_ninf_
)
590 /* Read a look-ahead token. */
591 if (yylooka_
== yyempty_
)
594 /* Convert token to internal form. */
595 if (yylooka_
<= yyeof_
)
597 yylooka_
= yyilooka_
= yyeof_
;
598 YYCDEBUG
<< "Now at end of input." << std::endl
;
602 yyilooka_
= yytranslate_ (yylooka_
);
603 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &yylval
, &yylloc
);
606 /* If the proper action on seeing token ILOOKA_ is to reduce or to
607 detect an error, take that action. */
609 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
612 /* Reduce or error. */
613 yyn_
= yytable_
[yyn_
];
616 if (yyn_
== yytable_ninf_
)
628 if (yyn_
== yyfinal_
)
631 /* Shift the look-ahead token. */
632 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &yylval
, &yylloc
);
634 /* Discard the token being shifted unless it is eof. */
635 if (yylooka_
!= yyeof_
)
638 yysemantic_stack_
.push (yylval
);
639 yylocation_stack_
.push (yylloc
);
641 /* Count tokens shifted since error; after three, turn off error
649 /*-----------------------------------------------------------.
650 | yydefault -- do the default action for the current state. |
651 `-----------------------------------------------------------*/
653 yyn_
= yydefact_
[yystate_
];
658 /*-----------------------------.
659 | yyreduce -- Do a reduction. |
660 `-----------------------------*/
662 yylen_
= yyr2_
[yyn_
];
663 /* If LEN_ is nonzero, implement the default value of the action:
664 `$$ = $1'. Otherwise, use the top of the stack.
666 Otherwise, the following line sets YYVAL to garbage.
667 This behavior is undocumented and Bison
668 users should not rely upon it. */
670 yyval
= yysemantic_stack_
[yylen_
- 1];
672 yyval
= yysemantic_stack_
[0];
675 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
676 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
678 YY_REDUCE_PRINT (yyn_
);
685 ]/* Line __line__ of lalr1.cc. */
686 b4_syncline([@oline@
], [@ofile@
])[
692 yysemantic_stack_
.push (yyval
);
693 yylocation_stack_
.push (yyloc
);
695 /* Shift the result of the reduction. */
697 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
698 if (0 <= yystate_
&& yystate_
<= yylast_
699 && yycheck_
[yystate_
] == yystate_stack_
[0])
700 yystate_
= yytable_
[yystate_
];
702 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
705 /*------------------------------------.
706 | yyerrlab -- here on detecting error |
707 `------------------------------------*/
709 /* If not already recovering from an error, report this error. */
710 yyreport_syntax_error_ ();
712 yyerror_range_
[0] = yylloc
;
713 if (yyerrstatus_
== 3)
715 /* If just tried and failed to reuse look-ahead token after an
716 error, discard it. */
718 /* Return failure if at end of input. */
719 if (yylooka_
<= yyeof_
)
721 /* If at end of input, pop the error token,
722 then the rest of the stack, then return failure. */
723 if (yylooka_
== yyeof_
)
726 yyerror_range_
[0] = yylocation_stack_
[0];
728 if (yystate_stack_
.height () == 1)
730 yydestruct_ ("Error: popping",
731 yystos_
[yystate_stack_
[0]],
732 &yysemantic_stack_
[0],
733 &yylocation_stack_
[0]);
738 yydestruct_ ("Error: discarding", yyilooka_
, &yylval
, &yylloc
);
743 /* Else will try to reuse look-ahead token after shifting the error
748 /*---------------------------------------------------.
749 | yyerrorlab -- error raised explicitly by YYERROR. |
750 `---------------------------------------------------*/
753 /* Pacify compilers like GCC when the user code never invokes
754 YYERROR and the label yyerrorlab therefore never appears in user
759 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
761 yystate_
= yystate_stack_
[0];
764 /*-------------------------------------------------------------.
765 | yyerrlab1 -- common code for both syntax error and YYERROR. |
766 `-------------------------------------------------------------*/
768 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
772 yyn_
= yypact_
[yystate_
];
773 if (yyn_
!= yypact_ninf_
)
776 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
778 yyn_
= yytable_
[yyn_
];
784 /* Pop the current state because it cannot handle the error token. */
785 if (yystate_stack_
.height () == 1)
788 yyerror_range_
[0] = yylocation_stack_
[0];
789 yydestruct_ ("Error: popping",
791 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
793 yystate_
= yystate_stack_
[0];
797 if (yyn_
== yyfinal_
)
800 yyerror_range_
[1] = yylloc
;
801 // Using YYLLOC is tempting, but would change the location of
802 // the look-ahead. YYLOC is available though.
803 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
804 yysemantic_stack_
.push (yylval
);
805 yylocation_stack_
.push (yyloc
);
807 /* Shift the error token. */
808 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
809 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
820 /* Free the lookahead. */
821 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &yylval
, &yylloc
);
827 yy::]b4_parser_class_name
[::yylex_ ()
829 YYCDEBUG
<< "Reading a token: ";
831 yylooka_
= yylex (&yylval
, &yylloc
);
833 yylooka_
= yylex (&yylval
);
837 // Generate an error message, and invoke error.
839 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
841 /* If not already recovering from an error, report this error. */
847 yyn_
= yypact_
[yystate_
];
848 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
850 /* Start YYX at -YYN if negative to avoid negative indexes in
852 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
854 /* Stay within bounds of both yycheck and yytname. */
855 int yychecklim
= yylast_
- yyn_
;
856 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
858 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
859 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
862 message
= "syntax error, unexpected ";
863 message
+= yyname_
[yyilooka_
];
867 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
868 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
870 message
+= (!count
++) ? ", expecting " : " or ";
871 message
+= yyname_
[x
];
877 message
= "syntax error";
878 error (yylloc
, message
);
883 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
885 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
886 const ]b4_int_type_for([b4_pact
])[
887 yy::]b4_parser_class_name
[::yypact_
[] =
892 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
893 doesn't specify something else to do. Zero means the default is an
895 const ]b4_int_type_for([b4_defact
])[
896 yy::]b4_parser_class_name
[::yydefact_
[] =
901 /* YYPGOTO[NTERM-NUM]. */
902 const ]b4_int_type_for([b4_pgoto
])[
903 yy::]b4_parser_class_name
[::yypgoto_
[] =
908 /* YYDEFGOTO[NTERM-NUM]. */
909 const ]b4_int_type_for([b4_defgoto
])[
910 yy::]b4_parser_class_name
[::yydefgoto_
[] =
915 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
916 positive, shift that token. If negative, reduce the rule which
917 number is the opposite. If zero, do what YYDEFACT says. */
918 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
919 const ]b4_int_type_for([b4_table
])[
920 yy::]b4_parser_class_name
[::yytable_
[] =
926 const ]b4_int_type_for([b4_check
])[
927 yy::]b4_parser_class_name
[::yycheck_
[] =
932 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
933 symbol of state STATE-NUM. */
934 const ]b4_int_type_for([b4_stos
])[
935 yy::]b4_parser_class_name
[::yystos_
[] =
941 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
943 const ]b4_int_type_for([b4_toknum
])[
944 yy::]b4_parser_class_name
[::yytoken_number_
[] =
950 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
951 const ]b4_int_type_for([b4_r1
])[
952 yy::]b4_parser_class_name
[::yyr1_
[] =
957 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
958 const ]b4_int_type_for([b4_r2
])[
959 yy::]b4_parser_class_name
[::yyr2_
[] =
964 #if YYDEBUG || YYERROR_VERBOSE
965 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
966 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
968 const yy::]b4_parser_class_name
[::yyname_
[] =
975 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
976 const yy::]b4_parser_class_name
[::rhs_number_type
977 yy::]b4_parser_class_name
[::yyrhs_
[] =
982 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
984 const ]b4_int_type_for([b4_prhs
])[
985 yy::]b4_parser_class_name
[::yyprhs_
[] =
990 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
991 const ]b4_int_type_for([b4_rline
])[
992 yy::]b4_parser_class_name
[::yyrline_
[] =
997 // Print the state stack on the debug stream.
999 yy::]b4_parser_class_name
[::yystack_print_ ()
1001 *yycdebug_
<< "Stack now";
1002 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1003 i
!= yystate_stack_
.end (); ++i
)
1004 *yycdebug_
<< ' ' << *i
;
1005 *yycdebug_
<< std::endl
;
1008 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1010 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1012 unsigned int yylno
= yyrline_
[yyrule
];
1013 /* Print the symbols being reduced, and their result. */
1014 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1015 << " (line " << yylno
<< "), ";
1016 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1017 0 <= yyrhs_
[i
]; ++i
)
1018 *yycdebug_
<< yyname_
[yyrhs_
[i
]] << ' ';
1019 *yycdebug_
<< "-> " << yyname_
[yyr1_
[yyn_
]] << std::endl
;
1023 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1024 yy::]b4_parser_class_name
[::token_number_type
1025 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1028 const token_number_type
1033 if ((unsigned int) token
<= yyuser_token_number_max_
)
1034 return translate_table
[token
];
1036 return yyundef_token_
;
1039 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1040 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1041 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1042 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1043 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1044 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1045 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1046 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1048 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1049 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1054 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
1056 #ifndef BISON_STACK_HH
1057 # define BISON_STACK_HH
1063 template <class T
, class S
= std::deque
<T
> >
1068 // Hide our reversed order.
1069 typedef typename
S::reverse_iterator iterator
;
1070 typedef typename
S::const_reverse_iterator const_iterator
;
1076 stack (unsigned int n
) : seq_ (n
)
1082 operator [] (unsigned int i
)
1089 operator [] (unsigned int i
) const
1098 seq_
.push_front (t
);
1103 pop (unsigned int n
= 1)
1113 return seq_
.size ();
1116 inline const_iterator
begin () const { return seq_
.rbegin (); }
1117 inline const_iterator
end () const { return seq_
.rend (); }
1124 /// Present a slice of the top of a stack.
1125 template <class T
, class S
= stack
<T
> >
1130 slice (const S
& stack
,
1131 unsigned int range
) : stack_ (stack
),
1138 operator [] (unsigned int i
) const
1140 return stack_
[range_
- i
];
1146 unsigned int range_
;
1150 #endif // not BISON_STACK_HH]
1153 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1156 ** \file position.hh
1157 ** Define the position class.
1160 #ifndef BISON_POSITION_HH
1161 # define BISON_POSITION_HH
1163 # include <iostream>
1168 /// Abstract a position.
1172 /// Initial column number.
1173 static const unsigned int initial_column
= 0;
1174 /// Initial line number.
1175 static const unsigned int initial_line
= 1;
1177 /** \name Ctor & dtor.
1180 /// Construct a position.
1183 line (initial_line
),
1184 column (initial_column
)
1190 /** \name Line and Column related manipulators
1193 /// (line related) Advance to the COUNT next lines.
1194 inline void lines (int count
= 1)
1196 column
= initial_column
;
1200 /// (column related) Advance to the COUNT next columns.
1201 inline void columns (int count
= 1)
1203 int leftmost
= initial_column
;
1204 int current
= column
;
1205 if (leftmost
<= current
+ count
)
1208 column
= initial_column
;
1213 /// File name to which this position refers.
1214 ]b4_filename_type
[* filename
;
1215 /// Current line number.
1217 /// Current column number.
1218 unsigned int column
;
1221 /// Add and assign a position.
1222 inline const position
&
1223 operator+= (position
& res
, const int width
)
1225 res
.columns (width
);
1229 /// Add two position objects.
1230 inline const position
1231 operator+ (const position
& begin
, const int width
)
1233 position res
= begin
;
1234 return res
+= width
;
1237 /// Add and assign a position.
1238 inline const position
&
1239 operator-= (position
& res
, const int width
)
1241 return res
+= -width
;
1244 /// Add two position objects.
1245 inline const position
1246 operator- (const position
& begin
, const int width
)
1248 return begin
+ -width
;
1251 /** \brief Intercept output stream redirection.
1252 ** \param ostr the destination output stream
1253 ** \param pos a reference to the position to redirect
1255 inline std::ostream
&
1256 operator<< (std::ostream
& ostr
, const position
& pos
)
1259 ostr
<< *pos
.filename
<< ':';
1260 return ostr
<< pos
.line
<< '.' << pos
.column
;
1264 #endif // not BISON_POSITION_HH]
1266 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1269 ** \file location.hh
1270 ** Define the location class.
1273 #ifndef BISON_LOCATION_HH
1274 # define BISON_LOCATION_HH
1276 # include <iostream>
1278 # include "position.hh"
1283 /// Abstract a location.
1286 /** \name Ctor & dtor.
1289 /// Construct a location.
1298 /** \name Line and Column related manipulators
1301 /// Reset initial location to final location.
1307 /// Extend the current location to the COUNT next columns.
1308 inline void columns (unsigned int count
= 1)
1313 /// Extend the current location to the COUNT next lines.
1314 inline void lines (unsigned int count
= 1)
1322 /// Beginning of the located region.
1324 /// End of the located region.
1328 /// Join two location objects to create a location.
1329 inline const location
operator+ (const location
& begin
, const location
& end
)
1331 location res
= begin
;
1336 /// Add two location objects.
1337 inline const location
operator+ (const location
& begin
, unsigned int width
)
1339 location res
= begin
;
1340 res
.columns (width
);
1344 /// Add and assign a location.
1345 inline location
& operator+= (location
& res
, unsigned int width
)
1347 res
.columns (width
);
1351 /** \brief Intercept output stream redirection.
1352 ** \param ostr the destination output stream
1353 ** \param loc a reference to the location to redirect
1355 ** Avoid duplicate information.
1357 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1359 position last
= loc
.end
- 1;
1362 && (!loc
.begin
.filename
1363 || *loc
.begin
.filename
!= *last
.filename
))
1364 ostr
<< '-' << last
;
1365 else if (loc
.begin
.line
!= last
.line
)
1366 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1367 else if (loc
.begin
.column
!= last
.column
)
1368 ostr
<< '-' << last
.column
;
1374 #endif // not BISON_LOCATION_HH]