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 print_ ();
267 virtual void report_syntax_error_ ();
269 virtual void symprint_ (int yytype
,
270 const SemanticType
* yyvaluep
,
271 const LocationType
* yylocationp
);
272 #endif /* ! YYDEBUG */
276 StateStack state_stack_
;
277 SemanticStack semantic_stack_
;
278 LocationStack location_stack_
;
281 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
282 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
283 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
284 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
285 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
286 static const ]b4_int_type_for([b4_table
])[ table_
[];
287 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
288 static const ]b4_int_type_for([b4_check
])[ check_
[];
289 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
290 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
291 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
293 #if YYDEBUG || YYERROR_VERBOSE
294 static const char* const name_
[];
297 /* More tables, for debugging. */
299 static const RhsNumberType rhs_
[];
300 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
301 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
302 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
303 virtual void reduce_print_ (int yyrule
);
304 virtual void stack_print_ ();
307 /* Even more tables. */
308 inline TokenNumberType
translate_ (int token
);
309 inline void destruct_ (const char* yymsg
,
311 SemanticType
* yyvaluep
, LocationType
* yylocationp
);
313 /// Pop \a n symbols the three stacks.
314 inline void pop (unsigned int n
= 1);
317 static const int eof_
;
318 /* LAST_ -- Last index in TABLE_. */
319 static const int last_
;
320 static const int nnts_
;
321 static const int empty_
;
322 static const int final_
;
323 static const int terror_
;
324 static const int errcode_
;
325 static const int ntokens_
;
326 static const unsigned int user_token_number_max_
;
327 static const TokenNumberType undef_token_
;
334 /* Error handling. */
340 std::ostream
& cdebug_
;
342 /* Look-ahead and look-ahead in internal form. */
349 /// Semantic value of the look-ahead.
351 /// Location of the look-ahead.
352 LocationType location
;
353 /// The locations where the error started and ended.
354 Location error_range_
[2];
360 ]b4_parse_param_vars
[
364 #endif /* ! defined PARSER_HEADER_H */]
366 @output @output_parser_name@
367 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
370 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
372 /* Enable debugging if requested. */
379 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
383 cdebug_ << (Title) << ' '; \
384 symprint_ ((Type), (Value), (Location)); \
385 cdebug_ << std::endl; \
389 # define YY_REDUCE_PRINT(Rule) \
392 reduce_print_ (Rule); \
395 # define YY_STACK_PRINT() \
403 # define YYCDEBUG if (0) cdebug_
404 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
405 # define YY_REDUCE_PRINT(Rule)
406 # define YY_STACK_PRINT()
408 #endif /* !YYDEBUG */
410 #define YYACCEPT goto yyacceptlab
411 #define YYABORT goto yyabortlab
412 #define YYERROR goto yyerrorlab
415 /*--------------------------------.
416 | Print this symbol on YYOUTPUT. |
417 `--------------------------------*/
420 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
421 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
423 /* Pacify ``unused variable'' warnings. */
427 cdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
428 << ' ' << name_
[yytype
] << " ("
429 << *yylocationp
<< ": ";
432 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
438 #endif /* ! YYDEBUG */
441 yy::]b4_parser_class_name
[::destruct_ (const char* yymsg
,
442 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
444 /* Pacify ``unused variable'' warnings. */
448 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
452 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
459 yy::]b4_parser_class_name
[::pop (unsigned int n
)
461 state_stack_
.pop (n
);
462 semantic_stack_
.pop (n
);
463 location_stack_
.pop (n
);
467 yy::]b4_parser_class_name
[::parse ()
469 YYCDEBUG
<< "Starting parse" << std::endl
;
478 ]m4_ifdef([b4_initial_action
], [
479 m4_pushdef([b4_at_dollar
], [location
])dnl
480 m4_pushdef([b4_dollar_dollar
], [value
])dnl
481 /* User initialization code. */
483 m4_popdef([b4_dollar_dollar
])dnl
484 m4_popdef([b4_at_dollar
])dnl
485 /* Line __line__ of yacc.c. */
486 b4_syncline([@oline@
], [@ofile@
])])dnl
488 [ /* Initialize the stacks. The initial state will be pushed in
489 yynewstate, since the latter expects the semantical and the
490 location values to have been already stored, initialize these
491 stacks with a primary value. */
492 state_stack_
= StateStack (0);
493 semantic_stack_
= SemanticStack (0);
494 location_stack_
= LocationStack (0);
495 semantic_stack_
.push (value
);
496 location_stack_
.push (location
);
500 state_stack_
.push (state_
);
501 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
507 /* Try to take a decision without look-ahead. */
509 if (n_
== pact_ninf_
)
512 /* Read a look-ahead token. */
513 if (looka_
== empty_
)
515 YYCDEBUG
<< "Reading a token: ";
519 /* Convert token to internal form. */
522 looka_
= ilooka_
= eof_
;
523 YYCDEBUG
<< "Now at end of input." << std::endl
;
527 ilooka_
= translate_ (looka_
);
528 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
531 /* If the proper action on seeing token ILOOKA_ is to reduce or to
532 detect an error, take that action. */
534 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
537 /* Reduce or error. */
541 if (n_
== table_ninf_
)
556 /* Shift the look-ahead token. */
557 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
559 /* Discard the token being shifted unless it is eof. */
563 semantic_stack_
.push (value
);
564 location_stack_
.push (location
);
566 /* Count tokens shifted since error; after three, turn off error
574 /*-----------------------------------------------------------.
575 | yydefault -- do the default action for the current state. |
576 `-----------------------------------------------------------*/
578 n_
= defact_
[state_
];
583 /*-----------------------------.
584 | yyreduce -- Do a reduction. |
585 `-----------------------------*/
588 /* If LEN_ is nonzero, implement the default value of the action:
589 `$$ = $1'. Otherwise, use the top of the stack.
591 Otherwise, the following line sets YYVAL to garbage.
592 This behavior is undocumented and Bison
593 users should not rely upon it. */
595 yyval
= semantic_stack_
[len_
- 1];
597 yyval
= semantic_stack_
[0];
600 Slice
<LocationType
, LocationStack
> slice (location_stack_
, len_
);
601 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
603 YY_REDUCE_PRINT (n_
);
609 ]/* Line __line__ of lalr1.cc. */
610 b4_syncline([@oline@
], [@ofile@
])[
616 semantic_stack_
.push (yyval
);
617 location_stack_
.push (yyloc
);
619 /* Shift the result of the reduction. */
621 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
622 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
623 state_
= table_
[state_
];
625 state_
= defgoto_
[n_
- ntokens_
];
628 /*------------------------------------.
629 | yyerrlab -- here on detecting error |
630 `------------------------------------*/
632 /* If not already recovering from an error, report this error. */
633 report_syntax_error_ ();
635 error_range_
[0] = location
;
638 /* If just tried and failed to reuse look-ahead token after an
639 error, discard it. */
641 /* Return failure if at end of input. */
644 /* If at end of input, pop the error token,
645 then the rest of the stack, then return failure. */
649 error_range_
[0] = location_stack_
[0];
651 if (state_stack_
.height () == 1)
653 destruct_ ("Error: popping",
654 stos_
[state_stack_
[0]],
656 &location_stack_
[0]);
661 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
666 /* Else will try to reuse look-ahead token after shifting the error
671 /*---------------------------------------------------.
672 | yyerrorlab -- error raised explicitly by YYERROR. |
673 `---------------------------------------------------*/
677 /* Pacify GCC when the user code never invokes YYERROR and the label
678 yyerrorlab therefore never appears in user code. */
683 error_range_
[0] = location_stack_
[len_
- 1];
685 state_
= state_stack_
[0];
688 /*-------------------------------------------------------------.
689 | yyerrlab1 -- common code for both syntax error and YYERROR. |
690 `-------------------------------------------------------------*/
692 errstatus_
= 3; /* Each real token shifted decrements this. */
697 if (n_
!= pact_ninf_
)
700 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
708 /* Pop the current state because it cannot handle the error token. */
709 if (state_stack_
.height () == 1)
712 error_range_
[0] = location_stack_
[0];
713 destruct_ ("Error: popping",
714 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
716 state_
= state_stack_
[0];
723 error_range_
[1] = location
;
724 // Using LOCATION is tempting, but would change the location of
725 // the look-ahead. YYLOC is available though.
726 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
727 semantic_stack_
.push (value
);
728 location_stack_
.push (yyloc
);
730 /* Shift the error token. */
731 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
732 &semantic_stack_
[0], &location_stack_
[0]);
743 /* Free the lookahead. */
744 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
750 yy::]b4_parser_class_name
[::lex_ ()
753 looka_
= yylex (&value
, &location
);
755 looka_
= yylex (&value
);
759 /** Generate an error message, and invoke yyerror. */
761 yy::]b4_parser_class_name
[::report_syntax_error_ ()
763 /* If not already recovering from an error, report this error. */
770 if (pact_ninf_
< n_
&& n_
< last_
)
772 message
= "syntax error, unexpected ";
773 message
+= name_
[ilooka_
];
776 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
777 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
782 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
783 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
785 message
+= (!count
++) ? ", expecting " : " or ";
793 message
= "syntax error";
799 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
801 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
802 const ]b4_int_type_for([b4_pact
])[
803 yy::]b4_parser_class_name
[::pact_
[] =
808 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
809 doesn't specify something else to do. Zero means the default is an
811 const ]b4_int_type_for([b4_defact
])[
812 yy::]b4_parser_class_name
[::defact_
[] =
817 /* YYPGOTO[NTERM-NUM]. */
818 const ]b4_int_type_for([b4_pgoto
])[
819 yy::]b4_parser_class_name
[::pgoto_
[] =
824 /* YYDEFGOTO[NTERM-NUM]. */
825 const ]b4_int_type_for([b4_defgoto
])[
826 yy::]b4_parser_class_name
[::defgoto_
[] =
831 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
832 positive, shift that token. If negative, reduce the rule which
833 number is the opposite. If zero, do what YYDEFACT says. */
834 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
835 const ]b4_int_type_for([b4_table
])[
836 yy::]b4_parser_class_name
[::table_
[] =
842 const ]b4_int_type_for([b4_check
])[
843 yy::]b4_parser_class_name
[::check_
[] =
848 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
849 symbol of state STATE-NUM. */
850 const ]b4_int_type_for([b4_stos
])[
851 yy::]b4_parser_class_name
[::stos_
[] =
857 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
859 const ]b4_int_type_for([b4_toknum
])[
860 yy::]b4_parser_class_name
[::token_number_
[] =
866 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
867 const ]b4_int_type_for([b4_r1
])[
868 yy::]b4_parser_class_name
[::r1_
[] =
873 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
874 const ]b4_int_type_for([b4_r2
])[
875 yy::]b4_parser_class_name
[::r2_
[] =
880 #if YYDEBUG || YYERROR_VERBOSE
881 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
882 First, the terminals, then, starting at NTOKENS_, nonterminals. */
884 const yy::]b4_parser_class_name
[::name_
[] =
891 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
892 const yy::]b4_parser_class_name
[::RhsNumberType
893 yy::]b4_parser_class_name
[::rhs_
[] =
898 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
900 const ]b4_int_type_for([b4_prhs
])[
901 yy::]b4_parser_class_name
[::prhs_
[] =
906 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
907 const ]b4_int_type_for([b4_rline
])[
908 yy::]b4_parser_class_name
[::rline_
[] =
913 /** Print the state stack from its BOTTOM up to its TOP (included). */
916 yy::]b4_parser_class_name
[::stack_print_ ()
918 cdebug_
<< "Stack now";
919 for (StateStack::const_iterator i
= state_stack_
.begin ();
920 i
!= state_stack_
.end (); ++i
)
921 cdebug_
<< ' ' << *i
;
922 cdebug_
<< std::endl
;
925 /** Report that the YYRULE is going to be reduced. */
928 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
930 unsigned int yylno
= rline_
[yyrule
];
931 /* Print the symbols being reduced, and their result. */
932 cdebug_
<< "Reducing stack by rule " << n_
- 1
933 << " (line " << yylno
<< "), ";
934 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
936 cdebug_
<< name_
[rhs_
[i
]] << ' ';
937 cdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
941 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
942 yy::]b4_parser_class_name
[::TokenNumberType
943 yy::]b4_parser_class_name
[::translate_ (int token
)
946 const TokenNumberType
951 if ((unsigned int) token
<= user_token_number_max_
)
952 return translate_table
[token
];
957 const int yy::]b4_parser_class_name
[::eof_
= 0;
958 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
959 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
960 const int yy::]b4_parser_class_name
[::empty_
= -2;
961 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
962 const int yy::]b4_parser_class_name
[::terror_
= 1;
963 const int yy::]b4_parser_class_name
[::errcode_
= 256;
964 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
966 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
967 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
972 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
974 #ifndef BISON_STACK_HH
975 # define BISON_STACK_HH
981 template <class T
, class S
= std::deque
<T
> >
986 // Hide our reversed order.
987 typedef typename
S::reverse_iterator iterator
;
988 typedef typename
S::const_reverse_iterator const_iterator
;
994 Stack (unsigned int n
) : seq_ (n
)
1000 operator [] (unsigned int i
)
1007 operator [] (unsigned int i
) const
1016 seq_
.push_front (t
);
1021 pop (unsigned int n
= 1)
1031 return seq_
.size ();
1034 inline const_iterator
begin () const { return seq_
.rbegin (); }
1035 inline const_iterator
end () const { return seq_
.rend (); }
1042 template <class T
, class S
= Stack
<T
> >
1047 Slice (const S
& stack
,
1048 unsigned int range
) : stack_ (stack
),
1055 operator [] (unsigned int i
) const
1057 return stack_
[range_
- i
];
1063 unsigned int range_
;
1067 #endif // not BISON_STACK_HH]
1070 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1073 ** \file position.hh
1074 ** Define the Location class.
1077 #ifndef BISON_POSITION_HH
1078 # define BISON_POSITION_HH
1080 # include <iostream>
1085 /** \brief Abstract a Position. */
1089 /** \brief Initial column number. */
1090 static const unsigned int initial_column
= 0;
1091 /** \brief Initial line number. */
1092 static const unsigned int initial_line
= 1;
1094 /** \name Ctor & dtor.
1097 /** \brief Construct a Position. */
1100 line (initial_line
),
1101 column (initial_column
)
1107 /** \name Line and Column related manipulators
1110 /** \brief (line related) Advance to the COUNT next lines. */
1111 inline void lines (int count
= 1)
1113 column
= initial_column
;
1117 /** \brief (column related) Advance to the COUNT next columns. */
1118 inline void columns (int count
= 1)
1120 int leftmost
= initial_column
;
1121 int current
= column
;
1122 if (leftmost
<= current
+ count
)
1125 column
= initial_column
;
1130 /** \brief File name to which this position refers. */
1131 std::string filename
;
1132 /** \brief Current line number. */
1134 /** \brief Current column number. */
1135 unsigned int column
;
1138 /** \brief Add and assign a Position. */
1139 inline const Position
&
1140 operator+= (Position
& res
, const int width
)
1142 res
.columns (width
);
1146 /** \brief Add two Position objects. */
1147 inline const Position
1148 operator+ (const Position
& begin
, const int width
)
1150 Position res
= begin
;
1151 return res
+= width
;
1154 /** \brief Add and assign a Position. */
1155 inline const Position
&
1156 operator-= (Position
& res
, const int width
)
1158 return res
+= -width
;
1161 /** \brief Add two Position objects. */
1162 inline const Position
1163 operator- (const Position
& begin
, const int width
)
1165 return begin
+ -width
;
1168 /** \brief Intercept output stream redirection.
1169 ** \param ostr the destination output stream
1170 ** \param pos a reference to the Position to redirect
1172 inline std::ostream
&
1173 operator<< (std::ostream
& ostr
, const Position
& pos
)
1175 if (!pos
.filename
.empty ())
1176 ostr
<< pos
.filename
<< ':';
1177 return ostr
<< pos
.line
<< '.' << pos
.column
;
1181 #endif // not BISON_POSITION_HH]
1183 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1186 ** \file location.hh
1187 ** Define the Location class.
1190 #ifndef BISON_LOCATION_HH
1191 # define BISON_LOCATION_HH
1193 # include <iostream>
1195 # include "position.hh"
1200 /** \brief Abstract a Location. */
1203 /** \name Ctor & dtor.
1206 /** \brief Construct a Location. */
1215 /** \name Line and Column related manipulators
1218 /** \brief Reset initial location to final location. */
1219 inline void step (void)
1224 /** \brief Extend the current location to the COUNT next columns. */
1225 inline void columns (unsigned int count
= 1)
1230 /** \brief Extend the current location to the COUNT next lines. */
1231 inline void lines (unsigned int count
= 1)
1239 /** \brief Beginning of the located region. */
1241 /** \brief End of the located region. */
1245 /** \brief Join two Location objects to create a Location. */
1246 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1248 Location res
= begin
;
1253 /** \brief Add two Location objects */
1254 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1256 Location res
= begin
;
1257 res
.columns (width
);
1261 /** \brief Add and assign a Location */
1262 inline Location
& operator+= (Location
& res
, unsigned int width
)
1264 res
.columns (width
);
1268 /** \brief Intercept output stream redirection.
1269 ** \param ostr the destination output stream
1270 ** \param loc a reference to the Location to redirect
1272 ** Avoid duplicate information.
1274 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1276 Position last
= loc
.end
- 1;
1278 if (loc
.begin
.filename
!= last
.filename
)
1279 ostr
<< '-' << last
;
1280 else if (loc
.begin
.line
!= last
.line
)
1281 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1282 else if (loc
.begin
.column
!= last
.column
)
1283 ostr
<< '-' << last
.column
;
1289 #endif // not BISON_LOCATION_HH]