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[
128 ]b4_token_defines(b4_tokens
)[
130 /* Copy the first part of user declarations. */
133 ]/* Line __line__ of lalr1.cc. */
134 b4_syncline([@oline@
], [@ofile@
])[
137 #include "location.hh"
139 /* Enabling traces. */
141 # define YYDEBUG ]b4_debug[
144 /* Enabling verbose error message. */
145 #ifndef YYERROR_VERBOSE
146 # define YYERROR_VERBOSE ]b4_error_verbose[
149 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
150 ]m4_ifdef([b4_stype
],
151 [b4_syncline([b4_stype_line
], [b4_filename
])
152 union YYSTYPE b4_stype
;
153 /* Line __line__ of lalr1.cc. */
154 b4_syncline([@oline@
], [@ofile@
])],
155 [typedef int YYSTYPE
;])[
156 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
157 # define YYSTYPE_IS_DECLARED 1
158 # define YYSTYPE_IS_TRIVIAL 1
161 /* Copy the second part of user declarations. */
164 ]/* Line __line__ of lalr1.cc. */
165 b4_syncline([@oline@
], [@ofile@
])[
166 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
167 If N is 0, then set CURRENT to the empty location which ends
168 the previous symbol: RHS[0] (always defined). */
170 #ifndef YYLLOC_DEFAULT
171 # define YYLLOC_DEFAULT(Current, Rhs, N) \
175 (Current).begin = (Rhs)[1].begin; \
176 (Current).end = (Rhs)[N].end; \
180 (Current).begin = (Current).end = (Rhs)[0].end; \
187 class ]b4_parser_class_name
[;
189 template <typename P
>
195 struct traits
<]b4_parser_class_name
[>
197 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
198 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
199 typedef int state_type
;
200 typedef YYSTYPE semantic_type
;
201 typedef ]b4_location_type
[ location_type
;
208 class ]b4_parser_class_name
[
211 /// Internal symbol numbers.
212 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
213 /// A type to store symbol numbers and -1.
214 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
216 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
217 /// Symbol semantic values.
218 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
219 /// Symbol locations.
220 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
222 /// State stack type.
223 typedef stack
<state_type
> state_stack
;
224 /// Semantic value stack type.
225 typedef stack
<semantic_type
> semantic_stack
;
226 /// location stack type.
227 typedef stack
<location_type
> location_stack
;
229 /// Build a parser object.
230 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
232 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
236 virtual ~]b4_parser_class_name
[ ()
241 /// \returns 0 iff parsing succeeded.
242 virtual int parse ();
244 /// The current debugging stream.
245 std::ostream
& debug_stream () const;
246 /// Set the current debugging stream.
247 void set_debug_stream (std::ostream
&);
249 /// Type for debugging levels.
250 typedef int debug_level_type
;
251 /// The current debugging level.
252 debug_level_type
debug_level () const;
253 /// Set the current debugging level.
254 void set_debug_level (debug_level_type l
);
258 /// Call the scanner.
259 virtual void yylex_ ();
261 /// Report a syntax error.
262 /// \param loc where the syntax error is found.
263 /// \param msg a description of the syntax error.
264 virtual void error (const location_type
& loc
, const std::string
& msg
);
266 /// Generate an error message, and invoke error.
267 virtual void yyreport_syntax_error_ ();
270 /// \brief Report a symbol on the debug stream.
271 /// \param yytype The token type.
272 /// \param yyvaluep Its semantic value.
273 /// \param yylocationp Its location.
274 virtual void yysymprint_ (int yytype
,
275 const semantic_type
* yyvaluep
,
276 const location_type
* yylocationp
);
277 #endif /* ! YYDEBUG */
281 state_stack yystate_stack_
;
282 /// The semantic value stack.
283 semantic_stack yysemantic_stack_
;
284 /// The location stack.
285 location_stack yylocation_stack_
;
288 /// For a state, the index in \a yytable_ of its portion.
289 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
290 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
292 /// For a state, default rule to reduce.
293 /// Unless\a yytable_ specifies something else to do.
294 /// Zero means the default is an error.
295 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
297 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
298 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
300 /// What to do in a state.
301 /// \a yytable_[yypact_[s]]: what to do in state \a s.
302 /// - if positive, shift that token.
303 /// - if negative, reduce the rule which number is the opposite.
304 /// - if zero, do what YYDEFACT says.
305 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
306 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
308 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
310 /// For a state, its accessing symbol.
311 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
313 /// For a rule, its LHS.
314 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
315 /// For a rule, its RHS length.
316 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
318 #if YYDEBUG || YYERROR_VERBOSE
319 /// For a symbol, its name in clear.
320 static const char* const yyname_
[];
324 /// A `-1'-separated list of the rules' RHS.
325 static const rhs_number_type yyrhs_
[];
326 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
327 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
328 /// For each rule, its source line number.
329 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
330 /// For each scanner token number, its symbol number.
331 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
332 /// Report on the debug stream that the rule \a r is going to be reduced.
333 virtual void yyreduce_print_ (int r
);
334 /// Print the state stack on the debug stream.
335 virtual void yystack_print_ ();
338 /// Convert a scanner token number to a symbol number.
339 inline token_number_type
yytranslate_ (int token
);
341 /// \brief Reclaim the memory associated to a symbol.
342 /// \param yymsg Why this token is reclaimed.
343 /// \param yytype The symbol type.
344 /// \param yyvaluep Its semantic value.
345 /// \param yylocationp Its location.
346 inline void yydestruct_ (const char* yymsg
,
348 semantic_type
* yyvaluep
,
349 location_type
* yylocationp
);
351 /// Pop \a n symbols the three stacks.
352 inline void yypop_ (unsigned int n
= 1);
355 static const int yyeof_
;
356 /* LAST_ -- Last index in TABLE_. */
357 static const int yylast_
;
358 static const int yynnts_
;
359 static const int yyempty_
;
360 static const int yyfinal_
;
361 static const int yyterror_
;
362 static const int yyerrcode_
;
363 static const int yyntokens_
;
364 static const unsigned int yyuser_token_number_max_
;
365 static const token_number_type yyundef_token_
;
372 /* Error handling. */
378 std::ostream
* yycdebug_
;
380 /* Look-ahead and look-ahead in internal form. */
384 /// Semantic value of the look-ahead.
385 semantic_type yylval
;
386 /// Location of the look-ahead.
387 location_type yylloc
;
388 /// The locations where the error started and ended.
389 location yyerror_range_
[2];
395 ]b4_parse_param_vars
[
399 #endif /* ! defined PARSER_HEADER_H */]
401 @output @output_parser_name@
402 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
404 m4_if(b4_prefix
[], [yy
], [],
406 // Take the name prefix into account.
407 #define yylex b4_prefix[]lex])
408 m4_if(b4_defines_flag
, 0, [],
410 #include @output_header_name@])[
412 /* A pseudo ostream that takes yydebug_ into account. */
414 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
417 /* Enable debugging if requested. */
420 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
424 *yycdebug_ << (Title) << ' '; \
425 yysymprint_ ((Type), (Value), (Location)); \
426 *yycdebug_ << std::endl; \
430 # define YY_REDUCE_PRINT(Rule) \
433 yyreduce_print_ (Rule); \
436 # define YY_STACK_PRINT() \
444 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
445 # define YY_REDUCE_PRINT(Rule)
446 # define YY_STACK_PRINT()
448 #endif /* !YYDEBUG */
450 #define YYACCEPT goto yyacceptlab
451 #define YYABORT goto yyabortlab
452 #define YYERROR goto yyerrorlab
455 /*--------------------------------.
456 | Print this symbol on YYOUTPUT. |
457 `--------------------------------*/
460 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
461 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
463 /* Pacify ``unused variable'' warnings. */
466 /* Backward compatibility, but should be removed eventually. */
467 std::ostream
& cdebug_
= *yycdebug_
;
470 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
471 << ' ' << yyname_
[yytype
] << " ("
472 << *yylocationp
<< ": ";
475 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
481 #endif /* ! YYDEBUG */
484 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
485 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
487 /* Pacify ``unused variable'' warnings. */
491 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
495 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
502 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
504 yystate_stack_
.pop (n
);
505 yysemantic_stack_
.pop (n
);
506 yylocation_stack_
.pop (n
);
510 yy::]b4_parser_class_name
[::debug_stream () const
516 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
522 yy::]b4_parser_class_name
[::debug_level_type
523 yy::]b4_parser_class_name
[::debug_level () const
529 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
536 yy::]b4_parser_class_name
[::parse ()
538 YYCDEBUG
<< "Starting parse" << std::endl
;
547 ]m4_ifdef([b4_initial_action
], [
548 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
549 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
550 /* User initialization code. */
552 m4_popdef([b4_dollar_dollar
])dnl
553 m4_popdef([b4_at_dollar
])dnl
554 /* Line __line__ of yacc.c. */
555 b4_syncline([@oline@
], [@ofile@
])])dnl
557 [ /* Initialize the stacks. The initial state will be pushed in
558 yynewstate, since the latter expects the semantical and the
559 location values to have been already stored, initialize these
560 stacks with a primary value. */
561 yystate_stack_
= state_stack (0);
562 yysemantic_stack_
= semantic_stack (0);
563 yylocation_stack_
= location_stack (0);
564 yysemantic_stack_
.push (yylval
);
565 yylocation_stack_
.push (yylloc
);
569 yystate_stack_
.push (yystate_
);
570 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
576 /* Try to take a decision without look-ahead. */
577 yyn_
= yypact_
[yystate_
];
578 if (yyn_
== yypact_ninf_
)
581 /* Read a look-ahead token. */
582 if (yylooka_
== yyempty_
)
585 /* Convert token to internal form. */
586 if (yylooka_
<= yyeof_
)
588 yylooka_
= yyilooka_
= yyeof_
;
589 YYCDEBUG
<< "Now at end of input." << std::endl
;
593 yyilooka_
= yytranslate_ (yylooka_
);
594 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &yylval
, &yylloc
);
597 /* If the proper action on seeing token ILOOKA_ is to reduce or to
598 detect an error, take that action. */
600 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
603 /* Reduce or error. */
604 yyn_
= yytable_
[yyn_
];
607 if (yyn_
== yytable_ninf_
)
619 if (yyn_
== yyfinal_
)
622 /* Shift the look-ahead token. */
623 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &yylval
, &yylloc
);
625 /* Discard the token being shifted unless it is eof. */
626 if (yylooka_
!= yyeof_
)
629 yysemantic_stack_
.push (yylval
);
630 yylocation_stack_
.push (yylloc
);
632 /* Count tokens shifted since error; after three, turn off error
640 /*-----------------------------------------------------------.
641 | yydefault -- do the default action for the current state. |
642 `-----------------------------------------------------------*/
644 yyn_
= yydefact_
[yystate_
];
649 /*-----------------------------.
650 | yyreduce -- Do a reduction. |
651 `-----------------------------*/
653 yylen_
= yyr2_
[yyn_
];
654 /* If LEN_ is nonzero, implement the default value of the action:
655 `$$ = $1'. Otherwise, use the top of the stack.
657 Otherwise, the following line sets YYVAL to garbage.
658 This behavior is undocumented and Bison
659 users should not rely upon it. */
661 yyval
= yysemantic_stack_
[yylen_
- 1];
663 yyval
= yysemantic_stack_
[0];
666 slice
<location_type
, location_stack
> slice (yylocation_stack_
, yylen_
);
667 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
669 YY_REDUCE_PRINT (yyn_
);
675 ]/* Line __line__ of lalr1.cc. */
676 b4_syncline([@oline@
], [@ofile@
])[
682 yysemantic_stack_
.push (yyval
);
683 yylocation_stack_
.push (yyloc
);
685 /* Shift the result of the reduction. */
687 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
688 if (0 <= yystate_
&& yystate_
<= yylast_
689 && yycheck_
[yystate_
] == yystate_stack_
[0])
690 yystate_
= yytable_
[yystate_
];
692 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
695 /*------------------------------------.
696 | yyerrlab -- here on detecting error |
697 `------------------------------------*/
699 /* If not already recovering from an error, report this error. */
700 yyreport_syntax_error_ ();
702 yyerror_range_
[0] = yylloc
;
703 if (yyerrstatus_
== 3)
705 /* If just tried and failed to reuse look-ahead token after an
706 error, discard it. */
708 /* Return failure if at end of input. */
709 if (yylooka_
<= yyeof_
)
711 /* If at end of input, pop the error token,
712 then the rest of the stack, then return failure. */
713 if (yylooka_
== yyeof_
)
716 yyerror_range_
[0] = yylocation_stack_
[0];
718 if (yystate_stack_
.height () == 1)
720 yydestruct_ ("Error: popping",
721 yystos_
[yystate_stack_
[0]],
722 &yysemantic_stack_
[0],
723 &yylocation_stack_
[0]);
728 yydestruct_ ("Error: discarding", yyilooka_
, &yylval
, &yylloc
);
733 /* Else will try to reuse look-ahead token after shifting the error
738 /*---------------------------------------------------.
739 | yyerrorlab -- error raised explicitly by YYERROR. |
740 `---------------------------------------------------*/
744 /* Pacify GCC when the user code never invokes YYERROR and the label
745 yyerrorlab therefore never appears in user code. */
750 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
752 yystate_
= yystate_stack_
[0];
755 /*-------------------------------------------------------------.
756 | yyerrlab1 -- common code for both syntax error and YYERROR. |
757 `-------------------------------------------------------------*/
759 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
763 yyn_
= yypact_
[yystate_
];
764 if (yyn_
!= yypact_ninf_
)
767 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
769 yyn_
= yytable_
[yyn_
];
775 /* Pop the current state because it cannot handle the error token. */
776 if (yystate_stack_
.height () == 1)
779 yyerror_range_
[0] = yylocation_stack_
[0];
780 yydestruct_ ("Error: popping",
782 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
784 yystate_
= yystate_stack_
[0];
788 if (yyn_
== yyfinal_
)
791 yyerror_range_
[1] = yylloc
;
792 // Using YYLLOC is tempting, but would change the location of
793 // the look-ahead. YYLOC is available though.
794 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
795 yysemantic_stack_
.push (yylval
);
796 yylocation_stack_
.push (yyloc
);
798 /* Shift the error token. */
799 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
800 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
811 /* Free the lookahead. */
812 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &yylval
, &yylloc
);
818 yy::]b4_parser_class_name
[::yylex_ ()
820 YYCDEBUG
<< "Reading a token: ";
822 yylooka_
= yylex (&yylval
, &yylloc
);
824 yylooka_
= yylex (&yylval
);
828 // Generate an error message, and invoke error.
830 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
832 /* If not already recovering from an error, report this error. */
838 yyn_
= yypact_
[yystate_
];
839 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
841 /* Start YYX at -YYN if negative to avoid negative indexes in
843 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
845 /* Stay within bounds of both yycheck and yytname. */
846 int yychecklim
= yylast_
- yyn_
;
847 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
849 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
850 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
853 message
= "syntax error, unexpected ";
854 message
+= yyname_
[yyilooka_
];
858 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
859 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
861 message
+= (!count
++) ? ", expecting " : " or ";
862 message
+= yyname_
[x
];
868 message
= "syntax error";
869 error (yylloc
, message
);
874 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
876 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
877 const ]b4_int_type_for([b4_pact
])[
878 yy::]b4_parser_class_name
[::yypact_
[] =
883 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
884 doesn't specify something else to do. Zero means the default is an
886 const ]b4_int_type_for([b4_defact
])[
887 yy::]b4_parser_class_name
[::yydefact_
[] =
892 /* YYPGOTO[NTERM-NUM]. */
893 const ]b4_int_type_for([b4_pgoto
])[
894 yy::]b4_parser_class_name
[::yypgoto_
[] =
899 /* YYDEFGOTO[NTERM-NUM]. */
900 const ]b4_int_type_for([b4_defgoto
])[
901 yy::]b4_parser_class_name
[::yydefgoto_
[] =
906 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
907 positive, shift that token. If negative, reduce the rule which
908 number is the opposite. If zero, do what YYDEFACT says. */
909 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
910 const ]b4_int_type_for([b4_table
])[
911 yy::]b4_parser_class_name
[::yytable_
[] =
917 const ]b4_int_type_for([b4_check
])[
918 yy::]b4_parser_class_name
[::yycheck_
[] =
923 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
924 symbol of state STATE-NUM. */
925 const ]b4_int_type_for([b4_stos
])[
926 yy::]b4_parser_class_name
[::yystos_
[] =
932 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
934 const ]b4_int_type_for([b4_toknum
])[
935 yy::]b4_parser_class_name
[::yytoken_number_
[] =
941 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
942 const ]b4_int_type_for([b4_r1
])[
943 yy::]b4_parser_class_name
[::yyr1_
[] =
948 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
949 const ]b4_int_type_for([b4_r2
])[
950 yy::]b4_parser_class_name
[::yyr2_
[] =
955 #if YYDEBUG || YYERROR_VERBOSE
956 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
957 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
959 const yy::]b4_parser_class_name
[::yyname_
[] =
966 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
967 const yy::]b4_parser_class_name
[::rhs_number_type
968 yy::]b4_parser_class_name
[::yyrhs_
[] =
973 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
975 const ]b4_int_type_for([b4_prhs
])[
976 yy::]b4_parser_class_name
[::yyprhs_
[] =
981 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
982 const ]b4_int_type_for([b4_rline
])[
983 yy::]b4_parser_class_name
[::yyrline_
[] =
988 // Print the state stack on the debug stream.
990 yy::]b4_parser_class_name
[::yystack_print_ ()
992 *yycdebug_
<< "Stack now";
993 for (state_stack::const_iterator i
= yystate_stack_
.begin ();
994 i
!= yystate_stack_
.end (); ++i
)
995 *yycdebug_
<< ' ' << *i
;
996 *yycdebug_
<< std::endl
;
999 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1001 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1003 unsigned int yylno
= yyrline_
[yyrule
];
1004 /* Print the symbols being reduced, and their result. */
1005 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1006 << " (line " << yylno
<< "), ";
1007 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1008 0 <= yyrhs_
[i
]; ++i
)
1009 *yycdebug_
<< yyname_
[yyrhs_
[i
]] << ' ';
1010 *yycdebug_
<< "-> " << yyname_
[yyr1_
[yyn_
]] << std::endl
;
1014 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1015 yy::]b4_parser_class_name
[::token_number_type
1016 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1019 const token_number_type
1024 if ((unsigned int) token
<= yyuser_token_number_max_
)
1025 return translate_table
[token
];
1027 return yyundef_token_
;
1030 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1031 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1032 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1033 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1034 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1035 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1036 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1037 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1039 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1040 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1045 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
1047 #ifndef BISON_STACK_HH
1048 # define BISON_STACK_HH
1054 template <class T
, class S
= std::deque
<T
> >
1059 // Hide our reversed order.
1060 typedef typename
S::reverse_iterator iterator
;
1061 typedef typename
S::const_reverse_iterator const_iterator
;
1067 stack (unsigned int n
) : seq_ (n
)
1073 operator [] (unsigned int i
)
1080 operator [] (unsigned int i
) const
1089 seq_
.push_front (t
);
1094 pop (unsigned int n
= 1)
1104 return seq_
.size ();
1107 inline const_iterator
begin () const { return seq_
.rbegin (); }
1108 inline const_iterator
end () const { return seq_
.rend (); }
1115 template <class T
, class S
= stack
<T
> >
1120 slice (const S
& stack
,
1121 unsigned int range
) : stack_ (stack
),
1128 operator [] (unsigned int i
) const
1130 return stack_
[range_
- i
];
1136 unsigned int range_
;
1140 #endif // not BISON_STACK_HH]
1143 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1146 ** \file position.hh
1147 ** Define the position class.
1150 #ifndef BISON_POSITION_HH
1151 # define BISON_POSITION_HH
1153 # include <iostream>
1158 /// Abstract a position.
1162 /// Initial column number.
1163 static const unsigned int initial_column
= 0;
1164 /// Initial line number.
1165 static const unsigned int initial_line
= 1;
1167 /** \name Ctor & dtor.
1170 /// Construct a position.
1173 line (initial_line
),
1174 column (initial_column
)
1180 /** \name Line and Column related manipulators
1183 /// (line related) Advance to the COUNT next lines.
1184 inline void lines (int count
= 1)
1186 column
= initial_column
;
1190 /// (column related) Advance to the COUNT next columns.
1191 inline void columns (int count
= 1)
1193 int leftmost
= initial_column
;
1194 int current
= column
;
1195 if (leftmost
<= current
+ count
)
1198 column
= initial_column
;
1203 /// File name to which this position refers.
1204 ]b4_filename_type
[* filename
;
1205 /// Current line number.
1207 /// Current column number.
1208 unsigned int column
;
1211 /// Add and assign a position.
1212 inline const position
&
1213 operator+= (position
& res
, const int width
)
1215 res
.columns (width
);
1219 /// Add two position objects.
1220 inline const position
1221 operator+ (const position
& begin
, const int width
)
1223 position res
= begin
;
1224 return res
+= width
;
1227 /// Add and assign a position.
1228 inline const position
&
1229 operator-= (position
& res
, const int width
)
1231 return res
+= -width
;
1234 /// Add two position objects.
1235 inline const position
1236 operator- (const position
& begin
, const int width
)
1238 return begin
+ -width
;
1241 /** \brief Intercept output stream redirection.
1242 ** \param ostr the destination output stream
1243 ** \param pos a reference to the position to redirect
1245 inline std::ostream
&
1246 operator<< (std::ostream
& ostr
, const position
& pos
)
1249 ostr
<< *pos
.filename
<< ':';
1250 return ostr
<< pos
.line
<< '.' << pos
.column
;
1254 #endif // not BISON_POSITION_HH]
1256 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1259 ** \file location.hh
1260 ** Define the location class.
1263 #ifndef BISON_LOCATION_HH
1264 # define BISON_LOCATION_HH
1266 # include <iostream>
1268 # include "position.hh"
1273 /// Abstract a location.
1276 /** \name Ctor & dtor.
1279 /// Construct a location.
1288 /** \name Line and Column related manipulators
1291 /// Reset initial location to final location.
1292 inline void step (void)
1297 /// Extend the current location to the COUNT next columns.
1298 inline void columns (unsigned int count
= 1)
1303 /// Extend the current location to the COUNT next lines.
1304 inline void lines (unsigned int count
= 1)
1312 /// Beginning of the located region.
1314 /// End of the located region.
1318 /// Join two location objects to create a location.
1319 inline const location
operator+ (const location
& begin
, const location
& end
)
1321 location res
= begin
;
1326 /// Add two location objects.
1327 inline const location
operator+ (const location
& begin
, unsigned int width
)
1329 location res
= begin
;
1330 res
.columns (width
);
1334 /// Add and assign a location.
1335 inline location
& operator+= (location
& res
, unsigned int width
)
1337 res
.columns (width
);
1341 /** \brief Intercept output stream redirection.
1342 ** \param ostr the destination output stream
1343 ** \param loc a reference to the location to redirect
1345 ** Avoid duplicate information.
1347 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1349 position last
= loc
.end
- 1;
1352 && (!loc
.begin
.filename
1353 || *loc
.begin
.filename
!= *last
.filename
))
1354 ostr
<< '-' << last
;
1355 else if (loc
.begin
.line
!= last
.line
)
1356 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1357 else if (loc
.begin
.column
!= last
.column
)
1358 ostr
<< '-' << last
.column
;
1364 #endif // not BISON_LOCATION_HH]