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])@
}])
65 m4_define([b4_inherit
],
77 m4_define([b4_constructor
],
86 # Extra formal arguments of the constructor.
87 # Change the parameter names from "foo" into "foo_yyarg", so that
88 # there is no collision bw the user chosen attribute name, and the
89 # argument name in the constructor.
90 m4_define([b4_parse_param_decl
],
91 [m4_ifset([b4_parse_param
],
92 [, m4_map_sep([b4_parse_param_decl_1
], [, ], [b4_parse_param
])])])
94 m4_define([b4_parse_param_decl_1
],
100 # -------------------
101 # Extra initialisations of the constructor.
102 m4_define([b4_parse_param_cons
],
103 [m4_ifset([b4_parse_param
],
105 b4_cc_constructor_calls(b4_parse_param
)])])
106 m4_define([b4_cc_constructor_calls
],
107 [m4_map_sep([b4_cc_constructor_call
], [,
109 m4_define([b4_cc_constructor_call
],
112 # b4_parse_param_vars
113 # -------------------
114 # Extra instance variables.
115 m4_define([b4_parse_param_vars
],
116 [m4_ifset([b4_parse_param
],
118 /* User arguments. */
119 b4_cc_var_decls(b4_parse_param
)])])
120 m4_define([b4_cc_var_decls
],
121 [m4_map_sep([b4_cc_var_decl
], [
123 m4_define([b4_cc_var_decl
],
128 # We do want M4 expansion after # for CPP macros.
131 m4_if(b4_defines_flag
, 0, [],
132 [@output @output_header_name@
133 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
135 /* FIXME: This is wrong, we want computed header guards.
136 I don't know why the macros are missing now. :( */
137 #ifndef PARSER_HEADER_H
138 # define PARSER_HEADER_H
141 #include "location.hh"
146 /* Using locations. */
147 #define YYLSP_NEEDED ]b4_locations_flag[
149 ]b4_token_defines(b4_tokens
)[
151 /* Copy the first part of user declarations. */
154 ]/* Line __line__ of lalr1.cc. */
155 b4_syncline([@oline@
], [@ofile@
])[
157 /* Enabling traces. */
159 # define YYDEBUG ]b4_debug[
162 /* Enabling verbose error message. */
163 #ifndef YYERROR_VERBOSE
164 # define YYERROR_VERBOSE ]b4_error_verbose[
168 typedef YYSTYPE yystype
;
170 ]m4_ifdef([b4_stype
],
171 [b4_syncline([b4_stype_line
], [b4_filename
])
172 typedef union b4_stype yystype
;
173 /* Line __line__ of lalr1.cc. */
174 b4_syncline([@oline@
], [@ofile@
])],
175 [typedef int yystype
;])[
176 # define YYSTYPE yystype
179 /* Copy the second part of user declarations. */
182 ]/* Line __line__ of lalr1.cc. */
183 b4_syncline([@oline@
], [@ofile@
])[
184 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
186 #ifndef YYLLOC_DEFAULT
187 # define YYLLOC_DEFAULT(Current, Rhs, N) \
189 ((Current).begin = (Rhs)[1].begin); \
190 ((Current).end = (Rhs)[N].end); \
196 class ]b4_parser_class_name
[;
198 template < typename P
>
204 struct Traits
< ]b4_parser_class_name
[ >
206 typedef ]b4_int_type_for([b4_translate
])[ TokenNumberType
;
207 typedef ]b4_int_type_for([b4_rhs
])[ RhsNumberType
;
208 typedef int StateType
;
209 typedef yystype SemanticType
;
210 typedef ]b4_location_type
[ LocationType
;
216 class ]b4_parser_class_name b4_inherit
[
220 typedef Traits
< ]b4_parser_class_name
[ >::TokenNumberType TokenNumberType
;
221 typedef Traits
< ]b4_parser_class_name
[ >::RhsNumberType RhsNumberType
;
222 typedef Traits
< ]b4_parser_class_name
[ >::StateType StateType
;
223 typedef Traits
< ]b4_parser_class_name
[ >::SemanticType SemanticType
;
224 typedef Traits
< ]b4_parser_class_name
[ >::LocationType LocationType
;
226 typedef Stack
< StateType
> StateStack
;
227 typedef Stack
< SemanticType
> SemanticStack
;
228 typedef Stack
< LocationType
> LocationStack
;
230 ]b4_parser_class_name
[ (bool debug
][]b4_param
[]b4_parse_param_decl
[) :
231 ]b4_constructor
[][debug_ (debug
),
232 cdebug_ (std::cerr
)]b4_parse_param_cons
[
236 virtual ~]b4_parser_class_name
[ ()
240 virtual int parse ();
244 virtual void lex_ ();
245 virtual void error_ ();
246 virtual void print_ ();
247 virtual void report_syntax_error_ ();
249 virtual void symprint_ (int yytype
,
250 const SemanticType
*yyvaluep
,
251 const LocationType
*yylocationp
);
252 #endif /* ! YYDEBUG */
256 StateStack state_stack_
;
257 SemanticStack semantic_stack_
;
258 LocationStack location_stack_
;
261 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
262 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
263 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
264 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
265 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
266 static const ]b4_int_type_for([b4_table
])[ table_
[];
267 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
268 static const ]b4_int_type_for([b4_check
])[ check_
[];
269 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
270 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
271 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
273 #if YYDEBUG || YYERROR_VERBOSE
274 static const char* const name_
[];
277 /* More tables, for debugging. */
279 static const RhsNumberType rhs_
[];
280 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
281 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
282 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
283 virtual void reduce_print_ (int yyrule
);
284 virtual void stack_print_ ();
287 /* Even more tables. */
288 inline TokenNumberType
translate_ (int token
);
289 inline void destruct_ (const char *yymsg
,
291 SemanticType
*yyvaluep
, LocationType
*yylocationp
);
293 /// Pop \a n symbols the three stacks.
294 inline void pop (unsigned int n
= 1);
297 static const int eof_
;
298 /* LAST_ -- Last index in TABLE_. */
299 static const int last_
;
300 static const int nnts_
;
301 static const int empty_
;
302 static const int final_
;
303 static const int terror_
;
304 static const int errcode_
;
305 static const int ntokens_
;
306 static const unsigned int user_token_number_max_
;
307 static const TokenNumberType undef_token_
;
314 /* Error handling. */
320 std::ostream
&cdebug_
;
322 /* Look-ahead and look-ahead in internal form. */
329 /// Semantic value of the look-ahead.
331 /// Location of the look-ahead.
332 LocationType location
;
333 /// The locations where the error started and ended.
334 Location error_range_
[2];
340 ]b4_parse_param_vars
[
344 #endif /* ! defined PARSER_HEADER_H */]
346 @output @output_parser_name@
347 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
350 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
352 /* Enable debugging if requested. */
359 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
363 cdebug_ << (Title) << ' '; \
364 symprint_ ((Type), (Value), (Location)); \
365 cdebug_ << std::endl; \
369 # define YY_REDUCE_PRINT(Rule) \
372 reduce_print_ (Rule); \
375 # define YY_STACK_PRINT() \
383 # define YYCDEBUG if (0) cdebug_
384 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
385 # define YY_REDUCE_PRINT(Rule)
386 # define YY_STACK_PRINT()
388 #endif /* !YYDEBUG */
390 #define YYACCEPT goto yyacceptlab
391 #define YYABORT goto yyabortlab
392 #define YYERROR goto yyerrorlab
395 /*--------------------------------.
396 | Print this symbol on YYOUTPUT. |
397 `--------------------------------*/
400 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
401 const SemanticType
*yyvaluep
, const LocationType
*yylocationp
)
403 /* Pacify ``unused variable'' warnings. */
407 cdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
408 << ' ' << name_
[yytype
] << " ("
409 << *yylocationp
<< ": ";
412 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
418 #endif /* ! YYDEBUG */
421 yy::]b4_parser_class_name
[::destruct_ (const char *yymsg
,
422 int yytype
, SemanticType
*yyvaluep
, LocationType
*yylocationp
)
424 /* Pacify ``unused variable'' warnings. */
428 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
432 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
439 yy::]b4_parser_class_name
[::pop (unsigned int n
)
441 state_stack_
.pop (n
);
442 semantic_stack_
.pop (n
);
443 location_stack_
.pop (n
);
447 yy::]b4_parser_class_name
[::parse ()
449 YYCDEBUG
<< "Starting parse" << std::endl
;
458 ]m4_ifdef([b4_initial_action
], [
459 m4_pushdef([b4_at_dollar
], [location
])dnl
460 m4_pushdef([b4_dollar_dollar
], [value
])dnl
461 /* User initialization code. */
463 m4_popdef([b4_dollar_dollar
])dnl
464 m4_popdef([b4_at_dollar
])dnl
465 /* Line __line__ of yacc.c. */
466 b4_syncline([@oline@
], [@ofile@
])])dnl
468 [ /* Initialize the stacks. The initial state will be pushed in
469 yynewstate, since the latter expects the semantical and the
470 location values to have been already stored, initialize these
471 stacks with a primary value. */
472 state_stack_
= StateStack (0);
473 semantic_stack_
= SemanticStack (0);
474 location_stack_
= LocationStack (0);
475 semantic_stack_
.push (value
);
476 location_stack_
.push (location
);
480 state_stack_
.push (state_
);
481 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
487 /* Try to take a decision without look-ahead. */
489 if (n_
== pact_ninf_
)
492 /* Read a look-ahead token. */
493 if (looka_
== empty_
)
495 YYCDEBUG
<< "Reading a token: ";
499 /* Convert token to internal form. */
502 looka_
= ilooka_
= eof_
;
503 YYCDEBUG
<< "Now at end of input." << std::endl
;
507 ilooka_
= translate_ (looka_
);
508 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
511 /* If the proper action on seeing token ILOOKA_ is to reduce or to
512 detect an error, take that action. */
514 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
517 /* Reduce or error. */
521 if (n_
== table_ninf_
)
536 /* Shift the look-ahead token. */
537 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
539 /* Discard the token being shifted unless it is eof. */
543 semantic_stack_
.push (value
);
544 location_stack_
.push (location
);
546 /* Count tokens shifted since error; after three, turn off error
554 /*-----------------------------------------------------------.
555 | yydefault -- do the default action for the current state. |
556 `-----------------------------------------------------------*/
558 n_
= defact_
[state_
];
563 /*-----------------------------.
564 | yyreduce -- Do a reduction. |
565 `-----------------------------*/
568 /* If LEN_ is nonzero, implement the default value of the action:
569 `$$ = $1'. Otherwise, use the top of the stack.
571 Otherwise, the following line sets YYVAL to garbage.
572 This behavior is undocumented and Bison
573 users should not rely upon it. */
576 yyval
= semantic_stack_
[len_
- 1];
577 yyloc
= location_stack_
[len_
- 1];
581 yyval
= semantic_stack_
[0];
582 yyloc
= location_stack_
[0];
587 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
588 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
590 YY_REDUCE_PRINT (n_
);
596 ]/* Line __line__ of lalr1.cc. */
597 b4_syncline([@oline@
], [@ofile@
])[
603 semantic_stack_
.push (yyval
);
604 location_stack_
.push (yyloc
);
606 /* Shift the result of the reduction. */
608 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
609 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
610 state_
= table_
[state_
];
612 state_
= defgoto_
[n_
- ntokens_
];
615 /*------------------------------------.
616 | yyerrlab -- here on detecting error |
617 `------------------------------------*/
619 /* If not already recovering from an error, report this error. */
620 report_syntax_error_ ();
622 error_range_
[0] = location
;
625 /* If just tried and failed to reuse look-ahead token after an
626 error, discard it. */
628 /* Return failure if at end of input. */
631 /* If at end of input, pop the error token,
632 then the rest of the stack, then return failure. */
636 error_range_
[0] = location_stack_
[0];
638 if (state_stack_
.height () == 1)
640 destruct_ ("Error: popping",
641 stos_
[state_stack_
[0]],
643 &location_stack_
[0]);
648 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
653 /* Else will try to reuse look-ahead token after shifting the error
658 /*---------------------------------------------------.
659 | yyerrorlab -- error raised explicitly by YYERROR. |
660 `---------------------------------------------------*/
664 /* Pacify GCC when the user code never invokes YYERROR and the label
665 yyerrorlab therefore never appears in user code. */
670 error_range_
[0] = location_stack_
[len_
- 1];
672 state_
= state_stack_
[0];
675 /*-------------------------------------------------------------.
676 | yyerrlab1 -- common code for both syntax error and YYERROR. |
677 `-------------------------------------------------------------*/
679 errstatus_
= 3; /* Each real token shifted decrements this. */
684 if (n_
!= pact_ninf_
)
687 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
695 /* Pop the current state because it cannot handle the error token. */
696 if (state_stack_
.height () == 1)
699 error_range_
[0] = location_stack_
[0];
700 destruct_ ("Error: popping",
701 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
703 state_
= state_stack_
[0];
710 error_range_
[1] = location
;
711 // Using LOCATION is tempting, but would change the location of
712 // the look-ahead. YYLOC is available though.
713 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
714 semantic_stack_
.push (value
);
715 location_stack_
.push (yyloc
);
717 /* Shift the error token. */
718 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
719 &semantic_stack_
[0], &location_stack_
[0]);
730 /* Free the lookahead. */
731 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
737 yy::]b4_parser_class_name
[::lex_ ()
740 looka_
= yylex (&value
, &location
);
742 looka_
= yylex (&value
);
746 /** Generate an error message, and invoke yyerror. */
748 yy::]b4_parser_class_name
[::report_syntax_error_ ()
750 /* If not already recovering from an error, report this error. */
757 if (pact_ninf_
< n_
&& n_
< last_
)
759 message
= "syntax error, unexpected ";
760 message
+= name_
[ilooka_
];
763 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
764 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
769 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
770 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
772 message
+= (!count
++) ? ", expecting " : " or ";
780 message
= "syntax error";
786 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
788 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
789 const ]b4_int_type_for([b4_pact
])[
790 yy::]b4_parser_class_name
[::pact_
[] =
795 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
796 doesn't specify something else to do. Zero means the default is an
798 const ]b4_int_type_for([b4_defact
])[
799 yy::]b4_parser_class_name
[::defact_
[] =
804 /* YYPGOTO[NTERM-NUM]. */
805 const ]b4_int_type_for([b4_pgoto
])[
806 yy::]b4_parser_class_name
[::pgoto_
[] =
811 /* YYDEFGOTO[NTERM-NUM]. */
812 const ]b4_int_type_for([b4_defgoto
])[
813 yy::]b4_parser_class_name
[::defgoto_
[] =
818 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
819 positive, shift that token. If negative, reduce the rule which
820 number is the opposite. If zero, do what YYDEFACT says. */
821 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
822 const ]b4_int_type_for([b4_table
])[
823 yy::]b4_parser_class_name
[::table_
[] =
829 const ]b4_int_type_for([b4_check
])[
830 yy::]b4_parser_class_name
[::check_
[] =
835 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
836 symbol of state STATE-NUM. */
837 const ]b4_int_type_for([b4_stos
])[
838 yy::]b4_parser_class_name
[::stos_
[] =
844 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
846 const ]b4_int_type_for([b4_toknum
])[
847 yy::]b4_parser_class_name
[::token_number_
[] =
853 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
854 const ]b4_int_type_for([b4_r1
])[
855 yy::]b4_parser_class_name
[::r1_
[] =
860 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
861 const ]b4_int_type_for([b4_r2
])[
862 yy::]b4_parser_class_name
[::r2_
[] =
867 #if YYDEBUG || YYERROR_VERBOSE
868 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
869 First, the terminals, then, starting at NTOKENS_, nonterminals. */
871 const yy::]b4_parser_class_name
[::name_
[] =
878 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
879 const yy::]b4_parser_class_name
[::RhsNumberType
880 yy::]b4_parser_class_name
[::rhs_
[] =
885 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
887 const ]b4_int_type_for([b4_prhs
])[
888 yy::]b4_parser_class_name
[::prhs_
[] =
893 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
894 const ]b4_int_type_for([b4_rline
])[
895 yy::]b4_parser_class_name
[::rline_
[] =
900 /** Print the state stack from its BOTTOM up to its TOP (included). */
903 yy::]b4_parser_class_name
[::stack_print_ ()
905 cdebug_
<< "Stack now";
906 for (StateStack::const_iterator i
= state_stack_
.begin ();
907 i
!= state_stack_
.end (); ++i
)
908 cdebug_
<< ' ' << *i
;
909 cdebug_
<< std::endl
;
912 /** Report that the YYRULE is going to be reduced. */
915 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
917 unsigned int yylno
= rline_
[yyrule
];
918 /* Print the symbols being reduced, and their result. */
919 cdebug_
<< "Reducing stack by rule " << n_
- 1 << " (line " << yylno
<< "), ";
920 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
922 cdebug_
<< name_
[rhs_
[i
]] << ' ';
923 cdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
927 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
928 yy::]b4_parser_class_name
[::TokenNumberType
929 yy::]b4_parser_class_name
[::translate_ (int token
)
932 const TokenNumberType
937 if ((unsigned int) token
<= user_token_number_max_
)
938 return translate_table
[token
];
943 const int yy::]b4_parser_class_name
[::eof_
= 0;
944 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
945 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
946 const int yy::]b4_parser_class_name
[::empty_
= -2;
947 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
948 const int yy::]b4_parser_class_name
[::terror_
= 1;
949 const int yy::]b4_parser_class_name
[::errcode_
= 256;
950 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
952 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
953 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
958 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
960 #ifndef BISON_STACK_HH
961 # define BISON_STACK_HH
967 template < class T
, class S
= std::deque
< T
> >
972 // Hide our reversed order.
973 typedef typename
S::reverse_iterator iterator
;
974 typedef typename
S::const_reverse_iterator const_iterator
;
980 Stack (unsigned int n
) : seq_ (n
)
986 operator [] (unsigned int i
)
993 operator [] (unsigned int i
) const
1002 seq_
.push_front (t
);
1007 pop (unsigned int n
= 1)
1017 return seq_
.size ();
1020 inline const_iterator
begin () const { return seq_
.rbegin (); }
1021 inline const_iterator
end () const { return seq_
.rend (); }
1028 template < class T
, class S
= Stack
< T
> >
1033 Slice (const S
& stack
,
1034 unsigned int range
) : stack_ (stack
),
1041 operator [] (unsigned int i
) const
1043 return stack_
[range_
- i
];
1049 unsigned int range_
;
1053 #endif // not BISON_STACK_HH]
1056 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1059 ** \file position.hh
1060 ** Define the Location class.
1063 #ifndef BISON_POSITION_HH
1064 # define BISON_POSITION_HH
1066 # include <iostream>
1071 /** \brief Abstract a Position. */
1075 /** \brief Initial column number. */
1076 static const unsigned int initial_column
= 0;
1077 /** \brief Initial line number. */
1078 static const unsigned int initial_line
= 1;
1080 /** \name Ctor & dtor.
1083 /** \brief Construct a Position. */
1086 line (initial_line
),
1087 column (initial_column
)
1093 /** \name Line and Column related manipulators
1096 /** \brief (line related) Advance to the COUNT next lines. */
1097 inline void lines (int count
= 1)
1099 column
= initial_column
;
1103 /** \brief (column related) Advance to the COUNT next columns. */
1104 inline void columns (int count
= 1)
1106 int leftmost
= initial_column
;
1107 int current
= column
;
1108 if (leftmost
<= current
+ count
)
1111 column
= initial_column
;
1116 /** \brief File name to which this position refers. */
1117 std::string filename
;
1118 /** \brief Current line number. */
1120 /** \brief Current column number. */
1121 unsigned int column
;
1124 /** \brief Add and assign a Position. */
1125 inline const Position
&
1126 operator+= (Position
& res
, const int width
)
1128 res
.columns (width
);
1132 /** \brief Add two Position objects. */
1133 inline const Position
1134 operator+ (const Position
& begin
, const int width
)
1136 Position res
= begin
;
1137 return res
+= width
;
1140 /** \brief Add and assign a Position. */
1141 inline const Position
&
1142 operator-= (Position
& res
, const int width
)
1144 return res
+= -width
;
1147 /** \brief Add two Position objects. */
1148 inline const Position
1149 operator- (const Position
& begin
, const int width
)
1151 return begin
+ -width
;
1154 /** \brief Intercept output stream redirection.
1155 ** \param ostr the destination output stream
1156 ** \param pos a reference to the Position to redirect
1158 inline std::ostream
&
1159 operator<< (std::ostream
& ostr
, const Position
& pos
)
1161 if (!pos
.filename
.empty ())
1162 ostr
<< pos
.filename
<< ':';
1163 return ostr
<< pos
.line
<< '.' << pos
.column
;
1167 #endif // not BISON_POSITION_HH]
1169 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1172 ** \file location.hh
1173 ** Define the Location class.
1176 #ifndef BISON_LOCATION_HH
1177 # define BISON_LOCATION_HH
1179 # include <iostream>
1181 # include "position.hh"
1186 /** \brief Abstract a Location. */
1189 /** \name Ctor & dtor.
1192 /** \brief Construct a Location. */
1201 /** \name Line and Column related manipulators
1204 /** \brief Reset initial location to final location. */
1205 inline void step (void)
1210 /** \brief Extend the current location to the COUNT next columns. */
1211 inline void columns (unsigned int count
= 1)
1216 /** \brief Extend the current location to the COUNT next lines. */
1217 inline void lines (unsigned int count
= 1)
1225 /** \brief Beginning of the located region. */
1227 /** \brief End of the located region. */
1231 /** \brief Join two Location objects to create a Location. */
1232 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1234 Location res
= begin
;
1239 /** \brief Add two Location objects */
1240 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1242 Location res
= begin
;
1243 res
.columns (width
);
1247 /** \brief Add and assign a Location */
1248 inline Location
&operator+= (Location
& res
, unsigned int width
)
1250 res
.columns (width
);
1254 /** \brief Intercept output stream redirection.
1255 ** \param ostr the destination output stream
1256 ** \param loc a reference to the Location to redirect
1258 ** Avoid duplicate information.
1260 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1262 Position last
= loc
.end
- 1;
1264 if (loc
.begin
.filename
!= last
.filename
)
1265 ostr
<< '-' << last
;
1266 else if (loc
.begin
.line
!= last
.line
)
1267 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1268 else if (loc
.begin
.column
!= last
.column
)
1269 ostr
<< '-' << last
.column
;
1275 #endif // not BISON_LOCATION_HH]