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 [semantic_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 [location_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
[
210 typedef Traits
<]b4_parser_class_name
[>::TokenNumberType TokenNumberType
;
211 typedef Traits
<]b4_parser_class_name
[>::RhsNumberType RhsNumberType
;
212 typedef Traits
<]b4_parser_class_name
[>::StateType StateType
;
213 typedef Traits
<]b4_parser_class_name
[>::SemanticType SemanticType
;
214 typedef Traits
<]b4_parser_class_name
[>::LocationType LocationType
;
216 typedef Stack
<StateType
> StateStack
;
217 typedef Stack
<SemanticType
> SemanticStack
;
218 typedef Stack
<LocationType
> LocationStack
;
220 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
222 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
226 virtual ~]b4_parser_class_name
[ ()
230 virtual int parse ();
232 /// Return the current debugging stream.
233 std::ostream
& debug_stream () const;
234 /// Set the current debugging stream.
235 void set_debug_stream (std::ostream
&);
237 /// Type for debugging levels.
238 typedef int debug_level_type
;
239 /// The current debugging level.
240 debug_level_type
debug_level () const;
241 /// Set the current debugging level.
242 void set_debug_level (debug_level_type l
);
246 virtual void lex_ ();
247 virtual void error_ ();
248 virtual void report_syntax_error_ ();
250 virtual void symprint_ (int yytype
,
251 const SemanticType
* yyvaluep
,
252 const LocationType
* yylocationp
);
253 #endif /* ! YYDEBUG */
257 StateStack state_stack_
;
258 SemanticStack semantic_stack_
;
259 LocationStack location_stack_
;
262 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
263 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
264 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
265 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
266 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
267 static const ]b4_int_type_for([b4_table
])[ table_
[];
268 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
269 static const ]b4_int_type_for([b4_check
])[ check_
[];
270 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
271 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
272 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
274 #if YYDEBUG || YYERROR_VERBOSE
275 static const char* const name_
[];
278 /* More tables, for debugging. */
280 static const RhsNumberType rhs_
[];
281 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
282 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
283 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
284 virtual void reduce_print_ (int yyrule
);
285 virtual void stack_print_ ();
288 /* Even more tables. */
289 inline TokenNumberType
translate_ (int token
);
290 inline void destruct_ (const char* yymsg
,
292 SemanticType
* yyvaluep
, LocationType
* yylocationp
);
294 /// Pop \a n symbols the three stacks.
295 inline void pop (unsigned int n
= 1);
298 static const int eof_
;
299 /* LAST_ -- Last index in TABLE_. */
300 static const int last_
;
301 static const int nnts_
;
302 static const int empty_
;
303 static const int final_
;
304 static const int terror_
;
305 static const int errcode_
;
306 static const int ntokens_
;
307 static const unsigned int user_token_number_max_
;
308 static const TokenNumberType undef_token_
;
315 /* Error handling. */
321 std::ostream
* yycdebug_
;
323 /* Look-ahead and look-ahead in internal form. */
330 /// Semantic value of the look-ahead.
332 /// Location of the look-ahead.
333 LocationType location
;
334 /// The locations where the error started and ended.
335 Location error_range_
[2];
341 ]b4_parse_param_vars
[
345 #endif /* ! defined PARSER_HEADER_H */]
347 @output @output_parser_name@
348 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
351 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
353 /* A pseudo ostream that takes yydebug_ into account. */
355 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
358 /* Enable debugging if requested. */
361 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
365 *yycdebug_ << (Title) << ' '; \
366 symprint_ ((Type), (Value), (Location)); \
367 *yycdebug_ << std::endl; \
371 # define YY_REDUCE_PRINT(Rule) \
374 reduce_print_ (Rule); \
377 # define YY_STACK_PRINT() \
385 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
386 # define YY_REDUCE_PRINT(Rule)
387 # define YY_STACK_PRINT()
389 #endif /* !YYDEBUG */
391 #define YYACCEPT goto yyacceptlab
392 #define YYABORT goto yyabortlab
393 #define YYERROR goto yyerrorlab
396 /*--------------------------------.
397 | Print this symbol on YYOUTPUT. |
398 `--------------------------------*/
401 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
402 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
404 /* Pacify ``unused variable'' warnings. */
407 /* Backward compatibility, but should be removed eventually. */
408 std::ostream
& cdebug_
= *yycdebug_
;
411 *yycdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
412 << ' ' << name_
[yytype
] << " ("
413 << *yylocationp
<< ": ";
416 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
422 #endif /* ! YYDEBUG */
425 yy::]b4_parser_class_name
[::destruct_ (const char* yymsg
,
426 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
428 /* Pacify ``unused variable'' warnings. */
432 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
436 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
443 yy::]b4_parser_class_name
[::pop (unsigned int n
)
445 state_stack_
.pop (n
);
446 semantic_stack_
.pop (n
);
447 location_stack_
.pop (n
);
451 yy::]b4_parser_class_name
[::debug_stream () const
457 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
463 yy::]b4_parser_class_name
[::debug_level_type
464 yy::]b4_parser_class_name
[::debug_level () const
470 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
477 yy::]b4_parser_class_name
[::parse ()
479 YYCDEBUG
<< "Starting parse" << std::endl
;
488 ]m4_ifdef([b4_initial_action
], [
489 m4_pushdef([b4_at_dollar
], [location
])dnl
490 m4_pushdef([b4_dollar_dollar
], [value
])dnl
491 /* User initialization code. */
493 m4_popdef([b4_dollar_dollar
])dnl
494 m4_popdef([b4_at_dollar
])dnl
495 /* Line __line__ of yacc.c. */
496 b4_syncline([@oline@
], [@ofile@
])])dnl
498 [ /* Initialize the stacks. The initial state will be pushed in
499 yynewstate, since the latter expects the semantical and the
500 location values to have been already stored, initialize these
501 stacks with a primary value. */
502 state_stack_
= StateStack (0);
503 semantic_stack_
= SemanticStack (0);
504 location_stack_
= LocationStack (0);
505 semantic_stack_
.push (value
);
506 location_stack_
.push (location
);
510 state_stack_
.push (state_
);
511 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
517 /* Try to take a decision without look-ahead. */
519 if (n_
== pact_ninf_
)
522 /* Read a look-ahead token. */
523 if (looka_
== empty_
)
525 YYCDEBUG
<< "Reading a token: ";
529 /* Convert token to internal form. */
532 looka_
= ilooka_
= eof_
;
533 YYCDEBUG
<< "Now at end of input." << std::endl
;
537 ilooka_
= translate_ (looka_
);
538 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
541 /* If the proper action on seeing token ILOOKA_ is to reduce or to
542 detect an error, take that action. */
544 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
547 /* Reduce or error. */
551 if (n_
== table_ninf_
)
566 /* Shift the look-ahead token. */
567 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
569 /* Discard the token being shifted unless it is eof. */
573 semantic_stack_
.push (value
);
574 location_stack_
.push (location
);
576 /* Count tokens shifted since error; after three, turn off error
584 /*-----------------------------------------------------------.
585 | yydefault -- do the default action for the current state. |
586 `-----------------------------------------------------------*/
588 n_
= defact_
[state_
];
593 /*-----------------------------.
594 | yyreduce -- Do a reduction. |
595 `-----------------------------*/
598 /* If LEN_ is nonzero, implement the default value of the action:
599 `$$ = $1'. Otherwise, use the top of the stack.
601 Otherwise, the following line sets YYVAL to garbage.
602 This behavior is undocumented and Bison
603 users should not rely upon it. */
605 yyval
= semantic_stack_
[len_
- 1];
607 yyval
= semantic_stack_
[0];
610 Slice
<LocationType
, LocationStack
> slice (location_stack_
, len_
);
611 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
613 YY_REDUCE_PRINT (n_
);
619 ]/* Line __line__ of lalr1.cc. */
620 b4_syncline([@oline@
], [@ofile@
])[
626 semantic_stack_
.push (yyval
);
627 location_stack_
.push (yyloc
);
629 /* Shift the result of the reduction. */
631 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
632 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
633 state_
= table_
[state_
];
635 state_
= defgoto_
[n_
- ntokens_
];
638 /*------------------------------------.
639 | yyerrlab -- here on detecting error |
640 `------------------------------------*/
642 /* If not already recovering from an error, report this error. */
643 report_syntax_error_ ();
645 error_range_
[0] = location
;
648 /* If just tried and failed to reuse look-ahead token after an
649 error, discard it. */
651 /* Return failure if at end of input. */
654 /* If at end of input, pop the error token,
655 then the rest of the stack, then return failure. */
659 error_range_
[0] = location_stack_
[0];
661 if (state_stack_
.height () == 1)
663 destruct_ ("Error: popping",
664 stos_
[state_stack_
[0]],
666 &location_stack_
[0]);
671 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
676 /* Else will try to reuse look-ahead token after shifting the error
681 /*---------------------------------------------------.
682 | yyerrorlab -- error raised explicitly by YYERROR. |
683 `---------------------------------------------------*/
687 /* Pacify GCC when the user code never invokes YYERROR and the label
688 yyerrorlab therefore never appears in user code. */
693 error_range_
[0] = location_stack_
[len_
- 1];
695 state_
= state_stack_
[0];
698 /*-------------------------------------------------------------.
699 | yyerrlab1 -- common code for both syntax error and YYERROR. |
700 `-------------------------------------------------------------*/
702 errstatus_
= 3; /* Each real token shifted decrements this. */
707 if (n_
!= pact_ninf_
)
710 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
718 /* Pop the current state because it cannot handle the error token. */
719 if (state_stack_
.height () == 1)
722 error_range_
[0] = location_stack_
[0];
723 destruct_ ("Error: popping",
724 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
726 state_
= state_stack_
[0];
733 error_range_
[1] = location
;
734 // Using LOCATION is tempting, but would change the location of
735 // the look-ahead. YYLOC is available though.
736 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
737 semantic_stack_
.push (value
);
738 location_stack_
.push (yyloc
);
740 /* Shift the error token. */
741 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
742 &semantic_stack_
[0], &location_stack_
[0]);
753 /* Free the lookahead. */
754 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
760 yy::]b4_parser_class_name
[::lex_ ()
763 looka_
= yylex (&value
, &location
);
765 looka_
= yylex (&value
);
769 /** Generate an error message, and invoke yyerror. */
771 yy::]b4_parser_class_name
[::report_syntax_error_ ()
773 /* If not already recovering from an error, report this error. */
780 if (pact_ninf_
< n_
&& n_
< last_
)
782 message
= "syntax error, unexpected ";
783 message
+= name_
[ilooka_
];
786 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
787 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
792 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
793 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
795 message
+= (!count
++) ? ", expecting " : " or ";
803 message
= "syntax error";
809 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
811 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
812 const ]b4_int_type_for([b4_pact
])[
813 yy::]b4_parser_class_name
[::pact_
[] =
818 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
819 doesn't specify something else to do. Zero means the default is an
821 const ]b4_int_type_for([b4_defact
])[
822 yy::]b4_parser_class_name
[::defact_
[] =
827 /* YYPGOTO[NTERM-NUM]. */
828 const ]b4_int_type_for([b4_pgoto
])[
829 yy::]b4_parser_class_name
[::pgoto_
[] =
834 /* YYDEFGOTO[NTERM-NUM]. */
835 const ]b4_int_type_for([b4_defgoto
])[
836 yy::]b4_parser_class_name
[::defgoto_
[] =
841 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
842 positive, shift that token. If negative, reduce the rule which
843 number is the opposite. If zero, do what YYDEFACT says. */
844 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
845 const ]b4_int_type_for([b4_table
])[
846 yy::]b4_parser_class_name
[::table_
[] =
852 const ]b4_int_type_for([b4_check
])[
853 yy::]b4_parser_class_name
[::check_
[] =
858 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
859 symbol of state STATE-NUM. */
860 const ]b4_int_type_for([b4_stos
])[
861 yy::]b4_parser_class_name
[::stos_
[] =
867 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
869 const ]b4_int_type_for([b4_toknum
])[
870 yy::]b4_parser_class_name
[::token_number_
[] =
876 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
877 const ]b4_int_type_for([b4_r1
])[
878 yy::]b4_parser_class_name
[::r1_
[] =
883 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
884 const ]b4_int_type_for([b4_r2
])[
885 yy::]b4_parser_class_name
[::r2_
[] =
890 #if YYDEBUG || YYERROR_VERBOSE
891 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
892 First, the terminals, then, starting at NTOKENS_, nonterminals. */
894 const yy::]b4_parser_class_name
[::name_
[] =
901 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
902 const yy::]b4_parser_class_name
[::RhsNumberType
903 yy::]b4_parser_class_name
[::rhs_
[] =
908 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
910 const ]b4_int_type_for([b4_prhs
])[
911 yy::]b4_parser_class_name
[::prhs_
[] =
916 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
917 const ]b4_int_type_for([b4_rline
])[
918 yy::]b4_parser_class_name
[::rline_
[] =
923 /** Print the state stack from its BOTTOM up to its TOP (included). */
926 yy::]b4_parser_class_name
[::stack_print_ ()
928 *yycdebug_
<< "Stack now";
929 for (StateStack::const_iterator i
= state_stack_
.begin ();
930 i
!= state_stack_
.end (); ++i
)
931 *yycdebug_
<< ' ' << *i
;
932 *yycdebug_
<< std::endl
;
935 /** Report that the YYRULE is going to be reduced. */
938 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
940 unsigned int yylno
= rline_
[yyrule
];
941 /* Print the symbols being reduced, and their result. */
942 *yycdebug_
<< "Reducing stack by rule " << n_
- 1
943 << " (line " << yylno
<< "), ";
944 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
946 *yycdebug_
<< name_
[rhs_
[i
]] << ' ';
947 *yycdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
951 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
952 yy::]b4_parser_class_name
[::TokenNumberType
953 yy::]b4_parser_class_name
[::translate_ (int token
)
956 const TokenNumberType
961 if ((unsigned int) token
<= user_token_number_max_
)
962 return translate_table
[token
];
967 const int yy::]b4_parser_class_name
[::eof_
= 0;
968 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
969 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
970 const int yy::]b4_parser_class_name
[::empty_
= -2;
971 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
972 const int yy::]b4_parser_class_name
[::terror_
= 1;
973 const int yy::]b4_parser_class_name
[::errcode_
= 256;
974 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
976 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
977 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
982 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
984 #ifndef BISON_STACK_HH
985 # define BISON_STACK_HH
991 template <class T
, class S
= std::deque
<T
> >
996 // Hide our reversed order.
997 typedef typename
S::reverse_iterator iterator
;
998 typedef typename
S::const_reverse_iterator const_iterator
;
1004 Stack (unsigned int n
) : seq_ (n
)
1010 operator [] (unsigned int i
)
1017 operator [] (unsigned int i
) const
1026 seq_
.push_front (t
);
1031 pop (unsigned int n
= 1)
1041 return seq_
.size ();
1044 inline const_iterator
begin () const { return seq_
.rbegin (); }
1045 inline const_iterator
end () const { return seq_
.rend (); }
1052 template <class T
, class S
= Stack
<T
> >
1057 Slice (const S
& stack
,
1058 unsigned int range
) : stack_ (stack
),
1065 operator [] (unsigned int i
) const
1067 return stack_
[range_
- i
];
1073 unsigned int range_
;
1077 #endif // not BISON_STACK_HH]
1080 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1083 ** \file position.hh
1084 ** Define the Location class.
1087 #ifndef BISON_POSITION_HH
1088 # define BISON_POSITION_HH
1090 # include <iostream>
1095 /** \brief Abstract a Position. */
1099 /** \brief Initial column number. */
1100 static const unsigned int initial_column
= 0;
1101 /** \brief Initial line number. */
1102 static const unsigned int initial_line
= 1;
1104 /** \name Ctor & dtor.
1107 /** \brief Construct a Position. */
1110 line (initial_line
),
1111 column (initial_column
)
1117 /** \name Line and Column related manipulators
1120 /** \brief (line related) Advance to the COUNT next lines. */
1121 inline void lines (int count
= 1)
1123 column
= initial_column
;
1127 /** \brief (column related) Advance to the COUNT next columns. */
1128 inline void columns (int count
= 1)
1130 int leftmost
= initial_column
;
1131 int current
= column
;
1132 if (leftmost
<= current
+ count
)
1135 column
= initial_column
;
1140 /** \brief File name to which this position refers. */
1141 std::string filename
;
1142 /** \brief Current line number. */
1144 /** \brief Current column number. */
1145 unsigned int column
;
1148 /** \brief Add and assign a Position. */
1149 inline const Position
&
1150 operator+= (Position
& res
, const int width
)
1152 res
.columns (width
);
1156 /** \brief Add two Position objects. */
1157 inline const Position
1158 operator+ (const Position
& begin
, const int width
)
1160 Position res
= begin
;
1161 return res
+= width
;
1164 /** \brief Add and assign a Position. */
1165 inline const Position
&
1166 operator-= (Position
& res
, const int width
)
1168 return res
+= -width
;
1171 /** \brief Add two Position objects. */
1172 inline const Position
1173 operator- (const Position
& begin
, const int width
)
1175 return begin
+ -width
;
1178 /** \brief Intercept output stream redirection.
1179 ** \param ostr the destination output stream
1180 ** \param pos a reference to the Position to redirect
1182 inline std::ostream
&
1183 operator<< (std::ostream
& ostr
, const Position
& pos
)
1185 if (!pos
.filename
.empty ())
1186 ostr
<< pos
.filename
<< ':';
1187 return ostr
<< pos
.line
<< '.' << pos
.column
;
1191 #endif // not BISON_POSITION_HH]
1193 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1196 ** \file location.hh
1197 ** Define the Location class.
1200 #ifndef BISON_LOCATION_HH
1201 # define BISON_LOCATION_HH
1203 # include <iostream>
1205 # include "position.hh"
1210 /** \brief Abstract a Location. */
1213 /** \name Ctor & dtor.
1216 /** \brief Construct a Location. */
1225 /** \name Line and Column related manipulators
1228 /** \brief Reset initial location to final location. */
1229 inline void step (void)
1234 /** \brief Extend the current location to the COUNT next columns. */
1235 inline void columns (unsigned int count
= 1)
1240 /** \brief Extend the current location to the COUNT next lines. */
1241 inline void lines (unsigned int count
= 1)
1249 /** \brief Beginning of the located region. */
1251 /** \brief End of the located region. */
1255 /** \brief Join two Location objects to create a Location. */
1256 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1258 Location res
= begin
;
1263 /** \brief Add two Location objects */
1264 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1266 Location res
= begin
;
1267 res
.columns (width
);
1271 /** \brief Add and assign a Location */
1272 inline Location
& operator+= (Location
& res
, unsigned int width
)
1274 res
.columns (width
);
1278 /** \brief Intercept output stream redirection.
1279 ** \param ostr the destination output stream
1280 ** \param loc a reference to the Location to redirect
1282 ** Avoid duplicate information.
1284 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1286 Position last
= loc
.end
- 1;
1288 if (loc
.begin
.filename
!= last
.filename
)
1289 ostr
<< '-' << last
;
1290 else if (loc
.begin
.line
!= last
.line
)
1291 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1292 else if (loc
.begin
.column
!= last
.column
)
1293 ostr
<< '-' << last
.column
;
1299 #endif // not BISON_LOCATION_HH]