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].
185 If N is 0, then set CURRENT to the empty location which ends
186 the previous symbol: RHS[0] (always defined). */
188 #ifndef YYLLOC_DEFAULT
189 # define YYLLOC_DEFAULT(Current, Rhs, N) \
193 (Current).begin = (Rhs)[1].begin; \
194 (Current).end = (Rhs)[N].end; \
198 (Current).begin = (Current).end = (Rhs)[0].end; \
205 class ]b4_parser_class_name
[;
207 template <typename P
>
213 struct Traits
<]b4_parser_class_name
[>
215 typedef ]b4_int_type_for([b4_translate
])[ TokenNumberType
;
216 typedef ]b4_int_type_for([b4_rhs
])[ RhsNumberType
;
217 typedef int StateType
;
218 typedef yystype SemanticType
;
219 typedef ]b4_location_type
[ LocationType
;
225 class ]b4_parser_class_name b4_inherit
[
229 typedef Traits
<]b4_parser_class_name
[>::TokenNumberType TokenNumberType
;
230 typedef Traits
<]b4_parser_class_name
[>::RhsNumberType RhsNumberType
;
231 typedef Traits
<]b4_parser_class_name
[>::StateType StateType
;
232 typedef Traits
<]b4_parser_class_name
[>::SemanticType SemanticType
;
233 typedef Traits
<]b4_parser_class_name
[>::LocationType LocationType
;
235 typedef Stack
<StateType
> StateStack
;
236 typedef Stack
<SemanticType
> SemanticStack
;
237 typedef Stack
<LocationType
> LocationStack
;
239 ]b4_parser_class_name
[ (bool debug
][]b4_param
[]b4_parse_param_decl
[) :
240 ]b4_constructor
[][debug_ (debug
),
241 cdebug_ (std::cerr
)]b4_parse_param_cons
[
245 ]b4_parser_class_name
[ (bool debug
,
246 LocationType
][]b4_param
[]b4_parse_param_decl
[) :
247 ]b4_constructor
[][debug_ (debug
),
248 cdebug_ (std::cerr
)]b4_parse_param_cons
[
250 cdebug_
<< __FILE__
<< ':' << __LINE__
251 << ": this constructor is provided by backward compatibility"
252 << ", but will be removed in the near future."
256 virtual ~]b4_parser_class_name
[ ()
260 virtual int parse ();
264 virtual void lex_ ();
265 virtual void error_ ();
266 virtual void report_syntax_error_ ();
268 virtual void symprint_ (int yytype
,
269 const SemanticType
* yyvaluep
,
270 const LocationType
* yylocationp
);
271 #endif /* ! YYDEBUG */
275 StateStack state_stack_
;
276 SemanticStack semantic_stack_
;
277 LocationStack location_stack_
;
280 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
281 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
282 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
283 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
284 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
285 static const ]b4_int_type_for([b4_table
])[ table_
[];
286 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
287 static const ]b4_int_type_for([b4_check
])[ check_
[];
288 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
289 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
290 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
292 #if YYDEBUG || YYERROR_VERBOSE
293 static const char* const name_
[];
296 /* More tables, for debugging. */
298 static const RhsNumberType rhs_
[];
299 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
300 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
301 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
302 virtual void reduce_print_ (int yyrule
);
303 virtual void stack_print_ ();
306 /* Even more tables. */
307 inline TokenNumberType
translate_ (int token
);
308 inline void destruct_ (const char* yymsg
,
310 SemanticType
* yyvaluep
, LocationType
* yylocationp
);
312 /// Pop \a n symbols the three stacks.
313 inline void pop (unsigned int n
= 1);
316 static const int eof_
;
317 /* LAST_ -- Last index in TABLE_. */
318 static const int last_
;
319 static const int nnts_
;
320 static const int empty_
;
321 static const int final_
;
322 static const int terror_
;
323 static const int errcode_
;
324 static const int ntokens_
;
325 static const unsigned int user_token_number_max_
;
326 static const TokenNumberType undef_token_
;
333 /* Error handling. */
339 std::ostream
& cdebug_
;
341 /* Look-ahead and look-ahead in internal form. */
348 /// Semantic value of the look-ahead.
350 /// Location of the look-ahead.
351 LocationType location
;
352 /// The locations where the error started and ended.
353 Location error_range_
[2];
359 ]b4_parse_param_vars
[
363 #endif /* ! defined PARSER_HEADER_H */]
365 @output @output_parser_name@
366 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
369 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
371 /* Enable debugging if requested. */
378 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
382 cdebug_ << (Title) << ' '; \
383 symprint_ ((Type), (Value), (Location)); \
384 cdebug_ << std::endl; \
388 # define YY_REDUCE_PRINT(Rule) \
391 reduce_print_ (Rule); \
394 # define YY_STACK_PRINT() \
402 # define YYCDEBUG if (0) cdebug_
403 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
404 # define YY_REDUCE_PRINT(Rule)
405 # define YY_STACK_PRINT()
407 #endif /* !YYDEBUG */
409 #define YYACCEPT goto yyacceptlab
410 #define YYABORT goto yyabortlab
411 #define YYERROR goto yyerrorlab
414 /*--------------------------------.
415 | Print this symbol on YYOUTPUT. |
416 `--------------------------------*/
419 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
420 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
422 /* Pacify ``unused variable'' warnings. */
426 cdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
427 << ' ' << name_
[yytype
] << " ("
428 << *yylocationp
<< ": ";
431 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
437 #endif /* ! YYDEBUG */
440 yy::]b4_parser_class_name
[::destruct_ (const char* yymsg
,
441 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
443 /* Pacify ``unused variable'' warnings. */
447 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
451 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
458 yy::]b4_parser_class_name
[::pop (unsigned int n
)
460 state_stack_
.pop (n
);
461 semantic_stack_
.pop (n
);
462 location_stack_
.pop (n
);
466 yy::]b4_parser_class_name
[::parse ()
468 YYCDEBUG
<< "Starting parse" << std::endl
;
477 ]m4_ifdef([b4_initial_action
], [
478 m4_pushdef([b4_at_dollar
], [location
])dnl
479 m4_pushdef([b4_dollar_dollar
], [value
])dnl
480 /* User initialization code. */
482 m4_popdef([b4_dollar_dollar
])dnl
483 m4_popdef([b4_at_dollar
])dnl
484 /* Line __line__ of yacc.c. */
485 b4_syncline([@oline@
], [@ofile@
])])dnl
487 [ /* Initialize the stacks. The initial state will be pushed in
488 yynewstate, since the latter expects the semantical and the
489 location values to have been already stored, initialize these
490 stacks with a primary value. */
491 state_stack_
= StateStack (0);
492 semantic_stack_
= SemanticStack (0);
493 location_stack_
= LocationStack (0);
494 semantic_stack_
.push (value
);
495 location_stack_
.push (location
);
499 state_stack_
.push (state_
);
500 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
506 /* Try to take a decision without look-ahead. */
508 if (n_
== pact_ninf_
)
511 /* Read a look-ahead token. */
512 if (looka_
== empty_
)
514 YYCDEBUG
<< "Reading a token: ";
518 /* Convert token to internal form. */
521 looka_
= ilooka_
= eof_
;
522 YYCDEBUG
<< "Now at end of input." << std::endl
;
526 ilooka_
= translate_ (looka_
);
527 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
530 /* If the proper action on seeing token ILOOKA_ is to reduce or to
531 detect an error, take that action. */
533 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
536 /* Reduce or error. */
540 if (n_
== table_ninf_
)
555 /* Shift the look-ahead token. */
556 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
558 /* Discard the token being shifted unless it is eof. */
562 semantic_stack_
.push (value
);
563 location_stack_
.push (location
);
565 /* Count tokens shifted since error; after three, turn off error
573 /*-----------------------------------------------------------.
574 | yydefault -- do the default action for the current state. |
575 `-----------------------------------------------------------*/
577 n_
= defact_
[state_
];
582 /*-----------------------------.
583 | yyreduce -- Do a reduction. |
584 `-----------------------------*/
587 /* If LEN_ is nonzero, implement the default value of the action:
588 `$$ = $1'. Otherwise, use the top of the stack.
590 Otherwise, the following line sets YYVAL to garbage.
591 This behavior is undocumented and Bison
592 users should not rely upon it. */
594 yyval
= semantic_stack_
[len_
- 1];
596 yyval
= semantic_stack_
[0];
599 Slice
<LocationType
, LocationStack
> slice (location_stack_
, len_
);
600 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
602 YY_REDUCE_PRINT (n_
);
608 ]/* Line __line__ of lalr1.cc. */
609 b4_syncline([@oline@
], [@ofile@
])[
615 semantic_stack_
.push (yyval
);
616 location_stack_
.push (yyloc
);
618 /* Shift the result of the reduction. */
620 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
621 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
622 state_
= table_
[state_
];
624 state_
= defgoto_
[n_
- ntokens_
];
627 /*------------------------------------.
628 | yyerrlab -- here on detecting error |
629 `------------------------------------*/
631 /* If not already recovering from an error, report this error. */
632 report_syntax_error_ ();
634 error_range_
[0] = location
;
637 /* If just tried and failed to reuse look-ahead token after an
638 error, discard it. */
640 /* Return failure if at end of input. */
643 /* If at end of input, pop the error token,
644 then the rest of the stack, then return failure. */
648 error_range_
[0] = location_stack_
[0];
650 if (state_stack_
.height () == 1)
652 destruct_ ("Error: popping",
653 stos_
[state_stack_
[0]],
655 &location_stack_
[0]);
660 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
665 /* Else will try to reuse look-ahead token after shifting the error
670 /*---------------------------------------------------.
671 | yyerrorlab -- error raised explicitly by YYERROR. |
672 `---------------------------------------------------*/
676 /* Pacify GCC when the user code never invokes YYERROR and the label
677 yyerrorlab therefore never appears in user code. */
682 error_range_
[0] = location_stack_
[len_
- 1];
684 state_
= state_stack_
[0];
687 /*-------------------------------------------------------------.
688 | yyerrlab1 -- common code for both syntax error and YYERROR. |
689 `-------------------------------------------------------------*/
691 errstatus_
= 3; /* Each real token shifted decrements this. */
696 if (n_
!= pact_ninf_
)
699 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
707 /* Pop the current state because it cannot handle the error token. */
708 if (state_stack_
.height () == 1)
711 error_range_
[0] = location_stack_
[0];
712 destruct_ ("Error: popping",
713 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
715 state_
= state_stack_
[0];
722 error_range_
[1] = location
;
723 // Using LOCATION is tempting, but would change the location of
724 // the look-ahead. YYLOC is available though.
725 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
726 semantic_stack_
.push (value
);
727 location_stack_
.push (yyloc
);
729 /* Shift the error token. */
730 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
731 &semantic_stack_
[0], &location_stack_
[0]);
742 /* Free the lookahead. */
743 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
749 yy::]b4_parser_class_name
[::lex_ ()
752 looka_
= yylex (&value
, &location
);
754 looka_
= yylex (&value
);
758 /** Generate an error message, and invoke yyerror. */
760 yy::]b4_parser_class_name
[::report_syntax_error_ ()
762 /* If not already recovering from an error, report this error. */
769 if (pact_ninf_
< n_
&& n_
< last_
)
771 message
= "syntax error, unexpected ";
772 message
+= name_
[ilooka_
];
775 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
776 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
781 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
782 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
784 message
+= (!count
++) ? ", expecting " : " or ";
792 message
= "syntax error";
798 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
800 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
801 const ]b4_int_type_for([b4_pact
])[
802 yy::]b4_parser_class_name
[::pact_
[] =
807 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
808 doesn't specify something else to do. Zero means the default is an
810 const ]b4_int_type_for([b4_defact
])[
811 yy::]b4_parser_class_name
[::defact_
[] =
816 /* YYPGOTO[NTERM-NUM]. */
817 const ]b4_int_type_for([b4_pgoto
])[
818 yy::]b4_parser_class_name
[::pgoto_
[] =
823 /* YYDEFGOTO[NTERM-NUM]. */
824 const ]b4_int_type_for([b4_defgoto
])[
825 yy::]b4_parser_class_name
[::defgoto_
[] =
830 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
831 positive, shift that token. If negative, reduce the rule which
832 number is the opposite. If zero, do what YYDEFACT says. */
833 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
834 const ]b4_int_type_for([b4_table
])[
835 yy::]b4_parser_class_name
[::table_
[] =
841 const ]b4_int_type_for([b4_check
])[
842 yy::]b4_parser_class_name
[::check_
[] =
847 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
848 symbol of state STATE-NUM. */
849 const ]b4_int_type_for([b4_stos
])[
850 yy::]b4_parser_class_name
[::stos_
[] =
856 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
858 const ]b4_int_type_for([b4_toknum
])[
859 yy::]b4_parser_class_name
[::token_number_
[] =
865 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
866 const ]b4_int_type_for([b4_r1
])[
867 yy::]b4_parser_class_name
[::r1_
[] =
872 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
873 const ]b4_int_type_for([b4_r2
])[
874 yy::]b4_parser_class_name
[::r2_
[] =
879 #if YYDEBUG || YYERROR_VERBOSE
880 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
881 First, the terminals, then, starting at NTOKENS_, nonterminals. */
883 const yy::]b4_parser_class_name
[::name_
[] =
890 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
891 const yy::]b4_parser_class_name
[::RhsNumberType
892 yy::]b4_parser_class_name
[::rhs_
[] =
897 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
899 const ]b4_int_type_for([b4_prhs
])[
900 yy::]b4_parser_class_name
[::prhs_
[] =
905 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
906 const ]b4_int_type_for([b4_rline
])[
907 yy::]b4_parser_class_name
[::rline_
[] =
912 /** Print the state stack from its BOTTOM up to its TOP (included). */
915 yy::]b4_parser_class_name
[::stack_print_ ()
917 cdebug_
<< "Stack now";
918 for (StateStack::const_iterator i
= state_stack_
.begin ();
919 i
!= state_stack_
.end (); ++i
)
920 cdebug_
<< ' ' << *i
;
921 cdebug_
<< std::endl
;
924 /** Report that the YYRULE is going to be reduced. */
927 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
929 unsigned int yylno
= rline_
[yyrule
];
930 /* Print the symbols being reduced, and their result. */
931 cdebug_
<< "Reducing stack by rule " << n_
- 1
932 << " (line " << yylno
<< "), ";
933 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
935 cdebug_
<< name_
[rhs_
[i
]] << ' ';
936 cdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
940 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
941 yy::]b4_parser_class_name
[::TokenNumberType
942 yy::]b4_parser_class_name
[::translate_ (int token
)
945 const TokenNumberType
950 if ((unsigned int) token
<= user_token_number_max_
)
951 return translate_table
[token
];
956 const int yy::]b4_parser_class_name
[::eof_
= 0;
957 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
958 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
959 const int yy::]b4_parser_class_name
[::empty_
= -2;
960 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
961 const int yy::]b4_parser_class_name
[::terror_
= 1;
962 const int yy::]b4_parser_class_name
[::errcode_
= 256;
963 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
965 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
966 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
971 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
973 #ifndef BISON_STACK_HH
974 # define BISON_STACK_HH
980 template <class T
, class S
= std::deque
<T
> >
985 // Hide our reversed order.
986 typedef typename
S::reverse_iterator iterator
;
987 typedef typename
S::const_reverse_iterator const_iterator
;
993 Stack (unsigned int n
) : seq_ (n
)
999 operator [] (unsigned int i
)
1006 operator [] (unsigned int i
) const
1015 seq_
.push_front (t
);
1020 pop (unsigned int n
= 1)
1030 return seq_
.size ();
1033 inline const_iterator
begin () const { return seq_
.rbegin (); }
1034 inline const_iterator
end () const { return seq_
.rend (); }
1041 template <class T
, class S
= Stack
<T
> >
1046 Slice (const S
& stack
,
1047 unsigned int range
) : stack_ (stack
),
1054 operator [] (unsigned int i
) const
1056 return stack_
[range_
- i
];
1062 unsigned int range_
;
1066 #endif // not BISON_STACK_HH]
1069 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1072 ** \file position.hh
1073 ** Define the Location class.
1076 #ifndef BISON_POSITION_HH
1077 # define BISON_POSITION_HH
1079 # include <iostream>
1084 /** \brief Abstract a Position. */
1088 /** \brief Initial column number. */
1089 static const unsigned int initial_column
= 0;
1090 /** \brief Initial line number. */
1091 static const unsigned int initial_line
= 1;
1093 /** \name Ctor & dtor.
1096 /** \brief Construct a Position. */
1099 line (initial_line
),
1100 column (initial_column
)
1106 /** \name Line and Column related manipulators
1109 /** \brief (line related) Advance to the COUNT next lines. */
1110 inline void lines (int count
= 1)
1112 column
= initial_column
;
1116 /** \brief (column related) Advance to the COUNT next columns. */
1117 inline void columns (int count
= 1)
1119 int leftmost
= initial_column
;
1120 int current
= column
;
1121 if (leftmost
<= current
+ count
)
1124 column
= initial_column
;
1129 /** \brief File name to which this position refers. */
1130 std::string filename
;
1131 /** \brief Current line number. */
1133 /** \brief Current column number. */
1134 unsigned int column
;
1137 /** \brief Add and assign a Position. */
1138 inline const Position
&
1139 operator+= (Position
& res
, const int width
)
1141 res
.columns (width
);
1145 /** \brief Add two Position objects. */
1146 inline const Position
1147 operator+ (const Position
& begin
, const int width
)
1149 Position res
= begin
;
1150 return res
+= width
;
1153 /** \brief Add and assign a Position. */
1154 inline const Position
&
1155 operator-= (Position
& res
, const int width
)
1157 return res
+= -width
;
1160 /** \brief Add two Position objects. */
1161 inline const Position
1162 operator- (const Position
& begin
, const int width
)
1164 return begin
+ -width
;
1167 /** \brief Intercept output stream redirection.
1168 ** \param ostr the destination output stream
1169 ** \param pos a reference to the Position to redirect
1171 inline std::ostream
&
1172 operator<< (std::ostream
& ostr
, const Position
& pos
)
1174 if (!pos
.filename
.empty ())
1175 ostr
<< pos
.filename
<< ':';
1176 return ostr
<< pos
.line
<< '.' << pos
.column
;
1180 #endif // not BISON_POSITION_HH]
1182 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1185 ** \file location.hh
1186 ** Define the Location class.
1189 #ifndef BISON_LOCATION_HH
1190 # define BISON_LOCATION_HH
1192 # include <iostream>
1194 # include "position.hh"
1199 /** \brief Abstract a Location. */
1202 /** \name Ctor & dtor.
1205 /** \brief Construct a Location. */
1214 /** \name Line and Column related manipulators
1217 /** \brief Reset initial location to final location. */
1218 inline void step (void)
1223 /** \brief Extend the current location to the COUNT next columns. */
1224 inline void columns (unsigned int count
= 1)
1229 /** \brief Extend the current location to the COUNT next lines. */
1230 inline void lines (unsigned int count
= 1)
1238 /** \brief Beginning of the located region. */
1240 /** \brief End of the located region. */
1244 /** \brief Join two Location objects to create a Location. */
1245 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1247 Location res
= begin
;
1252 /** \brief Add two Location objects */
1253 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1255 Location res
= begin
;
1256 res
.columns (width
);
1260 /** \brief Add and assign a Location */
1261 inline Location
& operator+= (Location
& res
, unsigned int width
)
1263 res
.columns (width
);
1267 /** \brief Intercept output stream redirection.
1268 ** \param ostr the destination output stream
1269 ** \param loc a reference to the Location to redirect
1271 ** Avoid duplicate information.
1273 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1275 Position last
= loc
.end
- 1;
1277 if (loc
.begin
.filename
!= last
.filename
)
1278 ostr
<< '-' << last
;
1279 else if (loc
.begin
.line
!= last
.line
)
1280 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1281 else if (loc
.begin
.column
!= last
.column
)
1282 ostr
<< '-' << last
.column
;
1288 #endif // not BISON_LOCATION_HH]