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
])
53 m4_define([b4_lhs_location
],
57 # b4_rhs_location(RULE-LENGTH, NUM)
58 # ---------------------------------
59 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
61 m4_define([b4_rhs_location
],
62 [yylocation_stack_@
{m4_eval([$
1 - $
2])@
}])
67 # Extra formal arguments of the constructor.
68 # Change the parameter names from "foo" into "foo_yyarg", so that
69 # there is no collision bw the user chosen attribute name, and the
70 # argument name in the constructor.
71 m4_define([b4_parse_param_decl
],
72 [m4_ifset([b4_parse_param
],
73 [m4_map_sep([b4_parse_param_decl_1
], [, ], [b4_parse_param
])])])
75 m4_define([b4_parse_param_decl_1
],
82 # Extra initialisations of the constructor.
83 m4_define([b4_parse_param_cons
],
84 [m4_ifset([b4_parse_param
],
86 b4_cc_constructor_calls(b4_parse_param
)])])
87 m4_define([b4_cc_constructor_calls
],
88 [m4_map_sep([b4_cc_constructor_call
], [,
90 m4_define([b4_cc_constructor_call
],
95 # Extra instance variables.
96 m4_define([b4_parse_param_vars
],
97 [m4_ifset([b4_parse_param
],
100 b4_cc_var_decls(b4_parse_param
)])])
101 m4_define([b4_cc_var_decls
],
102 [m4_map_sep([b4_cc_var_decl
], [
104 m4_define([b4_cc_var_decl
],
109 # We do want M4 expansion after # for CPP macros.
112 m4_if(b4_defines_flag
, 0, [],
113 [@output @output_header_name@
114 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
116 /* FIXME: This is wrong, we want computed header guards.
117 I don't know why the macros are missing now. :( */
118 #ifndef PARSER_HEADER_H
119 # define PARSER_HEADER_H
122 #include "location.hh"
127 /* Using locations. */
128 #define YYLSP_NEEDED ]b4_locations_flag[
130 ]b4_token_defines(b4_tokens
)[
132 /* Copy the first part of user declarations. */
135 ]/* Line __line__ of lalr1.cc. */
136 b4_syncline([@oline@
], [@ofile@
])[
138 /* Enabling traces. */
140 # define YYDEBUG ]b4_debug[
143 /* Enabling verbose error message. */
144 #ifndef YYERROR_VERBOSE
145 # define YYERROR_VERBOSE ]b4_error_verbose[
148 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
149 ]m4_ifdef([b4_stype
],
150 [b4_syncline([b4_stype_line
], [b4_filename
])
151 union YYSTYPE b4_stype
;
152 /* Line __line__ of lalr1.cc. */
153 b4_syncline([@oline@
], [@ofile@
])],
154 [typedef int YYSTYPE
;])[
155 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
156 # define YYSTYPE_IS_DECLARED 1
157 # define YYSTYPE_IS_TRIVIAL 1
160 /* Copy the second part of user declarations. */
163 ]/* Line __line__ of lalr1.cc. */
164 b4_syncline([@oline@
], [@ofile@
])[
165 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
166 If N is 0, then set CURRENT to the empty location which ends
167 the previous symbol: RHS[0] (always defined). */
169 #ifndef YYLLOC_DEFAULT
170 # define YYLLOC_DEFAULT(Current, Rhs, N) \
174 (Current).begin = (Rhs)[1].begin; \
175 (Current).end = (Rhs)[N].end; \
179 (Current).begin = (Current).end = (Rhs)[0].end; \
186 class ]b4_parser_class_name
[;
188 template <typename P
>
194 struct Traits
<]b4_parser_class_name
[>
196 typedef ]b4_int_type_for([b4_translate
])[ TokenNumberType
;
197 typedef ]b4_int_type_for([b4_rhs
])[ RhsNumberType
;
198 typedef int StateType
;
199 typedef YYSTYPE SemanticType
;
200 typedef ]b4_location_type
[ LocationType
;
206 class ]b4_parser_class_name
[
209 /// Internal symbol numbers.
210 typedef Traits
<]b4_parser_class_name
[>::TokenNumberType TokenNumberType
;
211 /// A type to store symbol numbers and -1.
212 typedef Traits
<]b4_parser_class_name
[>::RhsNumberType RhsNumberType
;
214 typedef Traits
<]b4_parser_class_name
[>::StateType StateType
;
215 /// Symbol semantic values.
216 typedef Traits
<]b4_parser_class_name
[>::SemanticType SemanticType
;
217 /// Symbol locations.
218 typedef Traits
<]b4_parser_class_name
[>::LocationType LocationType
;
220 typedef Stack
<StateType
> StateStack
;
221 typedef Stack
<SemanticType
> SemanticStack
;
222 typedef Stack
<LocationType
> LocationStack
;
224 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
226 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
230 virtual ~]b4_parser_class_name
[ ()
235 /// \returns 0 iff parsing succeeded.
236 virtual int parse ();
238 /// The current debugging stream.
239 std::ostream
& debug_stream () const;
240 /// Set the current debugging stream.
241 void set_debug_stream (std::ostream
&);
243 /// Type for debugging levels.
244 typedef int debug_level_type
;
245 /// The current debugging level.
246 debug_level_type
debug_level () const;
247 /// Set the current debugging level.
248 void set_debug_level (debug_level_type l
);
252 /// Call the scanner.
253 virtual void yylex_ ();
254 virtual void error_ ();
255 /// Generate an error message, and invoke error. */
256 virtual void yyreport_syntax_error_ ();
258 /// \brief Report a symbol on the debug stream.
259 /// \param yytype The token type.
260 /// \param yyvaluep Its semantic value.
261 /// \param yylocationp Its location.
262 virtual void yysymprint_ (int yytype
,
263 const SemanticType
* yyvaluep
,
264 const LocationType
* yylocationp
);
265 #endif /* ! YYDEBUG */
269 StateStack yystate_stack_
;
270 /// The semantic value stack.
271 SemanticStack yysemantic_stack_
;
272 /// The location stack.
273 LocationStack yylocation_stack_
;
276 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
277 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
278 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
279 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
280 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
281 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
282 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
283 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
284 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
285 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
286 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
288 #if YYDEBUG || YYERROR_VERBOSE
289 static const char* const yyname_
[];
293 /// A `-1'-separated list of the rules' RHS.
294 static const RhsNumberType yyrhs_
[];
295 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
296 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
297 /// For each rule, its source line number.
298 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
299 /// For each scanner token number, its symbol number.
300 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
301 /// Report on the debug stream that the rule \a yyrule is going to be reduced.
302 virtual void yyreduce_print_ (int yyrule
);
303 /// Print the state stack on the debug stream.
304 virtual void yystack_print_ ();
307 /// Convert a scanner token number to a symbol number.
308 inline TokenNumberType
yytranslate_ (int token
);
310 /// \brief Reclaim the memory associated to a symbol.
311 /// \param yymsg Why this token is reclaimed.
312 /// \param yytype The symbol type.
313 /// \param yyvaluep Its semantic value.
314 /// \param yylocationp Its location.
315 inline void yydestruct_ (const char* yymsg
,
317 SemanticType
* yyvaluep
,
318 LocationType
* yylocationp
);
320 /// Pop \a n symbols the three stacks.
321 inline void yypop_ (unsigned int n
= 1);
324 static const int yyeof_
;
325 /* LAST_ -- Last index in TABLE_. */
326 static const int yylast_
;
327 static const int yynnts_
;
328 static const int yyempty_
;
329 static const int yyfinal_
;
330 static const int yyterror_
;
331 static const int yyerrcode_
;
332 static const int yyntokens_
;
333 static const unsigned int yyuser_token_number_max_
;
334 static const TokenNumberType yyundef_token_
;
341 /* Error handling. */
347 std::ostream
* yycdebug_
;
349 /* Look-ahead and look-ahead in internal form. */
356 /// Semantic value of the look-ahead.
358 /// Location of the look-ahead.
359 LocationType location
;
360 /// The locations where the error started and ended.
361 Location yyerror_range_
[2];
367 ]b4_parse_param_vars
[
371 #endif /* ! defined PARSER_HEADER_H */]
373 @output @output_parser_name@
374 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
377 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
379 /* A pseudo ostream that takes yydebug_ into account. */
381 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
384 /* Enable debugging if requested. */
387 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
391 *yycdebug_ << (Title) << ' '; \
392 yysymprint_ ((Type), (Value), (Location)); \
393 *yycdebug_ << std::endl; \
397 # define YY_REDUCE_PRINT(Rule) \
400 yyreduce_print_ (Rule); \
403 # define YY_STACK_PRINT() \
411 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
412 # define YY_REDUCE_PRINT(Rule)
413 # define YY_STACK_PRINT()
415 #endif /* !YYDEBUG */
417 #define YYACCEPT goto yyacceptlab
418 #define YYABORT goto yyabortlab
419 #define YYERROR goto yyerrorlab
422 /*--------------------------------.
423 | Print this symbol on YYOUTPUT. |
424 `--------------------------------*/
427 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
428 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
430 /* Pacify ``unused variable'' warnings. */
433 /* Backward compatibility, but should be removed eventually. */
434 std::ostream
& cdebug_
= *yycdebug_
;
437 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
438 << ' ' << yyname_
[yytype
] << " ("
439 << *yylocationp
<< ": ";
442 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
448 #endif /* ! YYDEBUG */
451 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
452 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
454 /* Pacify ``unused variable'' warnings. */
458 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
462 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
469 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
471 yystate_stack_
.pop (n
);
472 yysemantic_stack_
.pop (n
);
473 yylocation_stack_
.pop (n
);
477 yy::]b4_parser_class_name
[::debug_stream () const
483 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
489 yy::]b4_parser_class_name
[::debug_level_type
490 yy::]b4_parser_class_name
[::debug_level () const
496 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
503 yy::]b4_parser_class_name
[::parse ()
505 YYCDEBUG
<< "Starting parse" << std::endl
;
514 ]m4_ifdef([b4_initial_action
], [
515 m4_pushdef([b4_at_dollar
], [location
])dnl
516 m4_pushdef([b4_dollar_dollar
], [value
])dnl
517 /* User initialization code. */
519 m4_popdef([b4_dollar_dollar
])dnl
520 m4_popdef([b4_at_dollar
])dnl
521 /* Line __line__ of yacc.c. */
522 b4_syncline([@oline@
], [@ofile@
])])dnl
524 [ /* Initialize the stacks. The initial state will be pushed in
525 yynewstate, since the latter expects the semantical and the
526 location values to have been already stored, initialize these
527 stacks with a primary value. */
528 yystate_stack_
= StateStack (0);
529 yysemantic_stack_
= SemanticStack (0);
530 yylocation_stack_
= LocationStack (0);
531 yysemantic_stack_
.push (value
);
532 yylocation_stack_
.push (location
);
536 yystate_stack_
.push (yystate_
);
537 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
543 /* Try to take a decision without look-ahead. */
544 yyn_
= yypact_
[yystate_
];
545 if (yyn_
== yypact_ninf_
)
548 /* Read a look-ahead token. */
549 if (yylooka_
== yyempty_
)
552 /* Convert token to internal form. */
553 if (yylooka_
<= yyeof_
)
555 yylooka_
= yyilooka_
= yyeof_
;
556 YYCDEBUG
<< "Now at end of input." << std::endl
;
560 yyilooka_
= yytranslate_ (yylooka_
);
561 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &value
, &location
);
564 /* If the proper action on seeing token ILOOKA_ is to reduce or to
565 detect an error, take that action. */
567 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
570 /* Reduce or error. */
571 yyn_
= yytable_
[yyn_
];
574 if (yyn_
== yytable_ninf_
)
586 if (yyn_
== yyfinal_
)
589 /* Shift the look-ahead token. */
590 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &value
, &location
);
592 /* Discard the token being shifted unless it is eof. */
593 if (yylooka_
!= yyeof_
)
596 yysemantic_stack_
.push (value
);
597 yylocation_stack_
.push (location
);
599 /* Count tokens shifted since error; after three, turn off error
607 /*-----------------------------------------------------------.
608 | yydefault -- do the default action for the current state. |
609 `-----------------------------------------------------------*/
611 yyn_
= yydefact_
[yystate_
];
616 /*-----------------------------.
617 | yyreduce -- Do a reduction. |
618 `-----------------------------*/
620 yylen_
= yyr2_
[yyn_
];
621 /* If LEN_ is nonzero, implement the default value of the action:
622 `$$ = $1'. Otherwise, use the top of the stack.
624 Otherwise, the following line sets YYVAL to garbage.
625 This behavior is undocumented and Bison
626 users should not rely upon it. */
628 yyval
= yysemantic_stack_
[yylen_
- 1];
630 yyval
= yysemantic_stack_
[0];
633 Slice
<LocationType
, LocationStack
> slice (yylocation_stack_
, yylen_
);
634 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
636 YY_REDUCE_PRINT (yyn_
);
642 ]/* Line __line__ of lalr1.cc. */
643 b4_syncline([@oline@
], [@ofile@
])[
649 yysemantic_stack_
.push (yyval
);
650 yylocation_stack_
.push (yyloc
);
652 /* Shift the result of the reduction. */
654 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
655 if (0 <= yystate_
&& yystate_
<= yylast_
656 && yycheck_
[yystate_
] == yystate_stack_
[0])
657 yystate_
= yytable_
[yystate_
];
659 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
662 /*------------------------------------.
663 | yyerrlab -- here on detecting error |
664 `------------------------------------*/
666 /* If not already recovering from an error, report this error. */
667 yyreport_syntax_error_ ();
669 yyerror_range_
[0] = location
;
670 if (yyerrstatus_
== 3)
672 /* If just tried and failed to reuse look-ahead token after an
673 error, discard it. */
675 /* Return failure if at end of input. */
676 if (yylooka_
<= yyeof_
)
678 /* If at end of input, pop the error token,
679 then the rest of the stack, then return failure. */
680 if (yylooka_
== yyeof_
)
683 yyerror_range_
[0] = yylocation_stack_
[0];
685 if (yystate_stack_
.height () == 1)
687 yydestruct_ ("Error: popping",
688 yystos_
[yystate_stack_
[0]],
689 &yysemantic_stack_
[0],
690 &yylocation_stack_
[0]);
695 yydestruct_ ("Error: discarding", yyilooka_
, &value
, &location
);
700 /* Else will try to reuse look-ahead token after shifting the error
705 /*---------------------------------------------------.
706 | yyerrorlab -- error raised explicitly by YYERROR. |
707 `---------------------------------------------------*/
711 /* Pacify GCC when the user code never invokes YYERROR and the label
712 yyerrorlab therefore never appears in user code. */
717 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
719 yystate_
= yystate_stack_
[0];
722 /*-------------------------------------------------------------.
723 | yyerrlab1 -- common code for both syntax error and YYERROR. |
724 `-------------------------------------------------------------*/
726 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
730 yyn_
= yypact_
[yystate_
];
731 if (yyn_
!= yypact_ninf_
)
734 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
736 yyn_
= yytable_
[yyn_
];
742 /* Pop the current state because it cannot handle the error token. */
743 if (yystate_stack_
.height () == 1)
746 yyerror_range_
[0] = yylocation_stack_
[0];
747 yydestruct_ ("Error: popping",
749 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
751 yystate_
= yystate_stack_
[0];
755 if (yyn_
== yyfinal_
)
758 yyerror_range_
[1] = location
;
759 // Using LOCATION is tempting, but would change the location of
760 // the look-ahead. YYLOC is available though.
761 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
762 yysemantic_stack_
.push (value
);
763 yylocation_stack_
.push (yyloc
);
765 /* Shift the error token. */
766 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
767 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
778 /* Free the lookahead. */
779 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &value
, &location
);
785 yy::]b4_parser_class_name
[::yylex_ ()
787 YYCDEBUG
<< "Reading a token: ";
789 yylooka_
= ]m4_default(b4_prefix
, [yy
])[lex (&value
, &location
);
791 yylooka_
= ]m4_default(b4_prefix
, [yy
])[lex (&value
);
795 // Generate an error message, and invoke error.
797 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
799 /* If not already recovering from an error, report this error. */
805 yyn_
= yypact_
[yystate_
];
806 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
808 message
= "syntax error, unexpected ";
809 message
+= yyname_
[yyilooka_
];
812 for (int x
= (yyn_
< 0 ? -yyn_
: 0); x
< yyntokens_
+ yynnts_
; ++x
)
813 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
818 for (int x
= (yyn_
< 0 ? -yyn_
: 0); x
< yyntokens_
+ yynnts_
; ++x
)
819 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
821 message
+= (!count
++) ? ", expecting " : " or ";
822 message
+= yyname_
[x
];
829 message
= "syntax error";
835 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
837 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
838 const ]b4_int_type_for([b4_pact
])[
839 yy::]b4_parser_class_name
[::yypact_
[] =
844 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
845 doesn't specify something else to do. Zero means the default is an
847 const ]b4_int_type_for([b4_defact
])[
848 yy::]b4_parser_class_name
[::yydefact_
[] =
853 /* YYPGOTO[NTERM-NUM]. */
854 const ]b4_int_type_for([b4_pgoto
])[
855 yy::]b4_parser_class_name
[::yypgoto_
[] =
860 /* YYDEFGOTO[NTERM-NUM]. */
861 const ]b4_int_type_for([b4_defgoto
])[
862 yy::]b4_parser_class_name
[::yydefgoto_
[] =
867 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
868 positive, shift that token. If negative, reduce the rule which
869 number is the opposite. If zero, do what YYDEFACT says. */
870 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
871 const ]b4_int_type_for([b4_table
])[
872 yy::]b4_parser_class_name
[::yytable_
[] =
878 const ]b4_int_type_for([b4_check
])[
879 yy::]b4_parser_class_name
[::yycheck_
[] =
884 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
885 symbol of state STATE-NUM. */
886 const ]b4_int_type_for([b4_stos
])[
887 yy::]b4_parser_class_name
[::yystos_
[] =
893 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
895 const ]b4_int_type_for([b4_toknum
])[
896 yy::]b4_parser_class_name
[::yytoken_number_
[] =
902 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
903 const ]b4_int_type_for([b4_r1
])[
904 yy::]b4_parser_class_name
[::yyr1_
[] =
909 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
910 const ]b4_int_type_for([b4_r2
])[
911 yy::]b4_parser_class_name
[::yyr2_
[] =
916 #if YYDEBUG || YYERROR_VERBOSE
917 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
918 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
920 const yy::]b4_parser_class_name
[::yyname_
[] =
927 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
928 const yy::]b4_parser_class_name
[::RhsNumberType
929 yy::]b4_parser_class_name
[::yyrhs_
[] =
934 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
936 const ]b4_int_type_for([b4_prhs
])[
937 yy::]b4_parser_class_name
[::yyprhs_
[] =
942 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
943 const ]b4_int_type_for([b4_rline
])[
944 yy::]b4_parser_class_name
[::yyrline_
[] =
949 // Print the state stack on the debug stream.
951 yy::]b4_parser_class_name
[::yystack_print_ ()
953 *yycdebug_
<< "Stack now";
954 for (StateStack::const_iterator i
= yystate_stack_
.begin ();
955 i
!= yystate_stack_
.end (); ++i
)
956 *yycdebug_
<< ' ' << *i
;
957 *yycdebug_
<< std::endl
;
960 // Report on the debug stream that the rule \a yyrule is going to be reduced.
962 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
964 unsigned int yylno
= yyrline_
[yyrule
];
965 /* Print the symbols being reduced, and their result. */
966 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
967 << " (line " << yylno
<< "), ";
968 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
970 *yycdebug_
<< yyname_
[yyrhs_
[i
]] << ' ';
971 *yycdebug_
<< "-> " << yyname_
[yyr1_
[yyn_
]] << std::endl
;
975 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
976 yy::]b4_parser_class_name
[::TokenNumberType
977 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
980 const TokenNumberType
985 if ((unsigned int) token
<= yyuser_token_number_max_
)
986 return translate_table
[token
];
988 return yyundef_token_
;
991 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
992 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
993 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
994 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
995 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
996 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
997 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
998 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1000 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1001 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1006 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
1008 #ifndef BISON_STACK_HH
1009 # define BISON_STACK_HH
1015 template <class T
, class S
= std::deque
<T
> >
1020 // Hide our reversed order.
1021 typedef typename
S::reverse_iterator iterator
;
1022 typedef typename
S::const_reverse_iterator const_iterator
;
1028 Stack (unsigned int n
) : seq_ (n
)
1034 operator [] (unsigned int i
)
1041 operator [] (unsigned int i
) const
1050 seq_
.push_front (t
);
1055 pop (unsigned int n
= 1)
1065 return seq_
.size ();
1068 inline const_iterator
begin () const { return seq_
.rbegin (); }
1069 inline const_iterator
end () const { return seq_
.rend (); }
1076 template <class T
, class S
= Stack
<T
> >
1081 Slice (const S
& stack
,
1082 unsigned int range
) : stack_ (stack
),
1089 operator [] (unsigned int i
) const
1091 return stack_
[range_
- i
];
1097 unsigned int range_
;
1101 #endif // not BISON_STACK_HH]
1104 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1107 ** \file position.hh
1108 ** Define the Location class.
1111 #ifndef BISON_POSITION_HH
1112 # define BISON_POSITION_HH
1114 # include <iostream>
1119 /// Abstract a Position.
1123 /// Initial column number.
1124 static const unsigned int initial_column
= 0;
1125 /// Initial line number.
1126 static const unsigned int initial_line
= 1;
1128 /** \name Ctor & dtor.
1131 /// Construct a Position.
1134 line (initial_line
),
1135 column (initial_column
)
1141 /** \name Line and Column related manipulators
1144 /// (line related) Advance to the COUNT next lines.
1145 inline void lines (int count
= 1)
1147 column
= initial_column
;
1151 /// (column related) Advance to the COUNT next columns.
1152 inline void columns (int count
= 1)
1154 int leftmost
= initial_column
;
1155 int current
= column
;
1156 if (leftmost
<= current
+ count
)
1159 column
= initial_column
;
1164 /// File name to which this position refers.
1165 std::string filename
;
1166 /// Current line number.
1168 /// Current column number.
1169 unsigned int column
;
1172 /// Add and assign a Position.
1173 inline const Position
&
1174 operator+= (Position
& res
, const int width
)
1176 res
.columns (width
);
1180 /// Add two Position objects.
1181 inline const Position
1182 operator+ (const Position
& begin
, const int width
)
1184 Position res
= begin
;
1185 return res
+= width
;
1188 /// Add and assign a Position.
1189 inline const Position
&
1190 operator-= (Position
& res
, const int width
)
1192 return res
+= -width
;
1195 /// Add two Position objects.
1196 inline const Position
1197 operator- (const Position
& begin
, const int width
)
1199 return begin
+ -width
;
1202 /** \brief Intercept output stream redirection.
1203 ** \param ostr the destination output stream
1204 ** \param pos a reference to the Position to redirect
1206 inline std::ostream
&
1207 operator<< (std::ostream
& ostr
, const Position
& pos
)
1209 if (!pos
.filename
.empty ())
1210 ostr
<< pos
.filename
<< ':';
1211 return ostr
<< pos
.line
<< '.' << pos
.column
;
1215 #endif // not BISON_POSITION_HH]
1217 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1220 ** \file location.hh
1221 ** Define the Location class.
1224 #ifndef BISON_LOCATION_HH
1225 # define BISON_LOCATION_HH
1227 # include <iostream>
1229 # include "position.hh"
1234 /// Abstract a Location.
1237 /** \name Ctor & dtor.
1240 /// Construct a Location.
1249 /** \name Line and Column related manipulators
1252 /// Reset initial location to final location.
1253 inline void step (void)
1258 /// Extend the current location to the COUNT next columns.
1259 inline void columns (unsigned int count
= 1)
1264 /// Extend the current location to the COUNT next lines.
1265 inline void lines (unsigned int count
= 1)
1273 /// Beginning of the located region.
1275 /// End of the located region.
1279 /// Join two Location objects to create a Location.
1280 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1282 Location res
= begin
;
1287 /// Add two Location objects.
1288 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1290 Location res
= begin
;
1291 res
.columns (width
);
1295 /// Add and assign a Location.
1296 inline Location
& operator+= (Location
& res
, unsigned int width
)
1298 res
.columns (width
);
1302 /** \brief Intercept output stream redirection.
1303 ** \param ostr the destination output stream
1304 ** \param loc a reference to the Location to redirect
1306 ** Avoid duplicate information.
1308 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1310 Position last
= loc
.end
- 1;
1312 if (loc
.begin
.filename
!= last
.filename
)
1313 ostr
<< '-' << last
;
1314 else if (loc
.begin
.line
!= last
.line
)
1315 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1316 else if (loc
.begin
.column
!= last
.column
)
1317 ostr
<< '-' << last
.column
;
1323 #endif // not BISON_LOCATION_HH]