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
[ (bool debug
]b4_parse_param_decl
[) :
222 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
226 ]b4_parser_class_name
[ (bool debug
,
227 LocationType
]b4_parse_param_decl
[) :
229 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
231 *yycdebug_
<< __FILE__
<< ':' << __LINE__
232 << ": this constructor is provided by backward compatibility"
233 << ", but will be removed in the near future."
237 virtual ~]b4_parser_class_name
[ ()
241 virtual int parse ();
243 /// Return the current debugging stream.
244 std::ostream
& debug_stream () const;
245 /// Set the current debugging stream.
246 void set_debug_stream (std::ostream
&);
250 virtual void lex_ ();
251 virtual void error_ ();
252 virtual void report_syntax_error_ ();
254 virtual void symprint_ (int yytype
,
255 const SemanticType
* yyvaluep
,
256 const LocationType
* yylocationp
);
257 #endif /* ! YYDEBUG */
261 StateStack state_stack_
;
262 SemanticStack semantic_stack_
;
263 LocationStack location_stack_
;
266 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
267 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
268 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
269 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
270 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
271 static const ]b4_int_type_for([b4_table
])[ table_
[];
272 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
273 static const ]b4_int_type_for([b4_check
])[ check_
[];
274 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
275 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
276 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
278 #if YYDEBUG || YYERROR_VERBOSE
279 static const char* const name_
[];
282 /* More tables, for debugging. */
284 static const RhsNumberType rhs_
[];
285 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
286 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
287 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
288 virtual void reduce_print_ (int yyrule
);
289 virtual void stack_print_ ();
292 /* Even more tables. */
293 inline TokenNumberType
translate_ (int token
);
294 inline void destruct_ (const char* yymsg
,
296 SemanticType
* yyvaluep
, LocationType
* yylocationp
);
298 /// Pop \a n symbols the three stacks.
299 inline void pop (unsigned int n
= 1);
302 static const int eof_
;
303 /* LAST_ -- Last index in TABLE_. */
304 static const int last_
;
305 static const int nnts_
;
306 static const int empty_
;
307 static const int final_
;
308 static const int terror_
;
309 static const int errcode_
;
310 static const int ntokens_
;
311 static const unsigned int user_token_number_max_
;
312 static const TokenNumberType undef_token_
;
319 /* Error handling. */
325 std::ostream
* yycdebug_
;
327 /* Look-ahead and look-ahead in internal form. */
334 /// Semantic value of the look-ahead.
336 /// Location of the look-ahead.
337 LocationType location
;
338 /// The locations where the error started and ended.
339 Location error_range_
[2];
345 ]b4_parse_param_vars
[
349 #endif /* ! defined PARSER_HEADER_H */]
351 @output @output_parser_name@
352 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
355 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
357 /* A pseudo ostream that takes debug_ into account. */
359 for (bool yydebugcond_ = debug_; yydebugcond_; yydebugcond_ = false) \
362 /* Enable debugging if requested. */
365 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
369 *yycdebug_ << (Title) << ' '; \
370 symprint_ ((Type), (Value), (Location)); \
371 *yycdebug_ << std::endl; \
375 # define YY_REDUCE_PRINT(Rule) \
378 reduce_print_ (Rule); \
381 # define YY_STACK_PRINT() \
389 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
390 # define YY_REDUCE_PRINT(Rule)
391 # define YY_STACK_PRINT()
393 #endif /* !YYDEBUG */
395 #define YYACCEPT goto yyacceptlab
396 #define YYABORT goto yyabortlab
397 #define YYERROR goto yyerrorlab
400 /*--------------------------------.
401 | Print this symbol on YYOUTPUT. |
402 `--------------------------------*/
405 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
406 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
408 /* Pacify ``unused variable'' warnings. */
411 /* Backward compatibility, but should be removed eventually. */
412 std::ostream
& cdebug_
= *yycdebug_
;
415 *yycdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
416 << ' ' << name_
[yytype
] << " ("
417 << *yylocationp
<< ": ";
420 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
426 #endif /* ! YYDEBUG */
429 yy::]b4_parser_class_name
[::destruct_ (const char* yymsg
,
430 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
432 /* Pacify ``unused variable'' warnings. */
436 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
440 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
447 yy::]b4_parser_class_name
[::pop (unsigned int n
)
449 state_stack_
.pop (n
);
450 semantic_stack_
.pop (n
);
451 location_stack_
.pop (n
);
455 yy::]b4_parser_class_name
[::debug_stream () const
461 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
468 yy::]b4_parser_class_name
[::parse ()
470 YYCDEBUG
<< "Starting parse" << std::endl
;
479 ]m4_ifdef([b4_initial_action
], [
480 m4_pushdef([b4_at_dollar
], [location
])dnl
481 m4_pushdef([b4_dollar_dollar
], [value
])dnl
482 /* User initialization code. */
484 m4_popdef([b4_dollar_dollar
])dnl
485 m4_popdef([b4_at_dollar
])dnl
486 /* Line __line__ of yacc.c. */
487 b4_syncline([@oline@
], [@ofile@
])])dnl
489 [ /* Initialize the stacks. The initial state will be pushed in
490 yynewstate, since the latter expects the semantical and the
491 location values to have been already stored, initialize these
492 stacks with a primary value. */
493 state_stack_
= StateStack (0);
494 semantic_stack_
= SemanticStack (0);
495 location_stack_
= LocationStack (0);
496 semantic_stack_
.push (value
);
497 location_stack_
.push (location
);
501 state_stack_
.push (state_
);
502 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
508 /* Try to take a decision without look-ahead. */
510 if (n_
== pact_ninf_
)
513 /* Read a look-ahead token. */
514 if (looka_
== empty_
)
516 YYCDEBUG
<< "Reading a token: ";
520 /* Convert token to internal form. */
523 looka_
= ilooka_
= eof_
;
524 YYCDEBUG
<< "Now at end of input." << std::endl
;
528 ilooka_
= translate_ (looka_
);
529 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
532 /* If the proper action on seeing token ILOOKA_ is to reduce or to
533 detect an error, take that action. */
535 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
538 /* Reduce or error. */
542 if (n_
== table_ninf_
)
557 /* Shift the look-ahead token. */
558 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
560 /* Discard the token being shifted unless it is eof. */
564 semantic_stack_
.push (value
);
565 location_stack_
.push (location
);
567 /* Count tokens shifted since error; after three, turn off error
575 /*-----------------------------------------------------------.
576 | yydefault -- do the default action for the current state. |
577 `-----------------------------------------------------------*/
579 n_
= defact_
[state_
];
584 /*-----------------------------.
585 | yyreduce -- Do a reduction. |
586 `-----------------------------*/
589 /* If LEN_ is nonzero, implement the default value of the action:
590 `$$ = $1'. Otherwise, use the top of the stack.
592 Otherwise, the following line sets YYVAL to garbage.
593 This behavior is undocumented and Bison
594 users should not rely upon it. */
596 yyval
= semantic_stack_
[len_
- 1];
598 yyval
= semantic_stack_
[0];
601 Slice
<LocationType
, LocationStack
> slice (location_stack_
, len_
);
602 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
604 YY_REDUCE_PRINT (n_
);
610 ]/* Line __line__ of lalr1.cc. */
611 b4_syncline([@oline@
], [@ofile@
])[
617 semantic_stack_
.push (yyval
);
618 location_stack_
.push (yyloc
);
620 /* Shift the result of the reduction. */
622 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
623 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
624 state_
= table_
[state_
];
626 state_
= defgoto_
[n_
- ntokens_
];
629 /*------------------------------------.
630 | yyerrlab -- here on detecting error |
631 `------------------------------------*/
633 /* If not already recovering from an error, report this error. */
634 report_syntax_error_ ();
636 error_range_
[0] = location
;
639 /* If just tried and failed to reuse look-ahead token after an
640 error, discard it. */
642 /* Return failure if at end of input. */
645 /* If at end of input, pop the error token,
646 then the rest of the stack, then return failure. */
650 error_range_
[0] = location_stack_
[0];
652 if (state_stack_
.height () == 1)
654 destruct_ ("Error: popping",
655 stos_
[state_stack_
[0]],
657 &location_stack_
[0]);
662 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
667 /* Else will try to reuse look-ahead token after shifting the error
672 /*---------------------------------------------------.
673 | yyerrorlab -- error raised explicitly by YYERROR. |
674 `---------------------------------------------------*/
678 /* Pacify GCC when the user code never invokes YYERROR and the label
679 yyerrorlab therefore never appears in user code. */
684 error_range_
[0] = location_stack_
[len_
- 1];
686 state_
= state_stack_
[0];
689 /*-------------------------------------------------------------.
690 | yyerrlab1 -- common code for both syntax error and YYERROR. |
691 `-------------------------------------------------------------*/
693 errstatus_
= 3; /* Each real token shifted decrements this. */
698 if (n_
!= pact_ninf_
)
701 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
709 /* Pop the current state because it cannot handle the error token. */
710 if (state_stack_
.height () == 1)
713 error_range_
[0] = location_stack_
[0];
714 destruct_ ("Error: popping",
715 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
717 state_
= state_stack_
[0];
724 error_range_
[1] = location
;
725 // Using LOCATION is tempting, but would change the location of
726 // the look-ahead. YYLOC is available though.
727 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
728 semantic_stack_
.push (value
);
729 location_stack_
.push (yyloc
);
731 /* Shift the error token. */
732 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
733 &semantic_stack_
[0], &location_stack_
[0]);
744 /* Free the lookahead. */
745 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
751 yy::]b4_parser_class_name
[::lex_ ()
754 looka_
= yylex (&value
, &location
);
756 looka_
= yylex (&value
);
760 /** Generate an error message, and invoke yyerror. */
762 yy::]b4_parser_class_name
[::report_syntax_error_ ()
764 /* If not already recovering from an error, report this error. */
771 if (pact_ninf_
< n_
&& n_
< last_
)
773 message
= "syntax error, unexpected ";
774 message
+= name_
[ilooka_
];
777 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
778 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
783 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
784 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
786 message
+= (!count
++) ? ", expecting " : " or ";
794 message
= "syntax error";
800 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
802 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
803 const ]b4_int_type_for([b4_pact
])[
804 yy::]b4_parser_class_name
[::pact_
[] =
809 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
810 doesn't specify something else to do. Zero means the default is an
812 const ]b4_int_type_for([b4_defact
])[
813 yy::]b4_parser_class_name
[::defact_
[] =
818 /* YYPGOTO[NTERM-NUM]. */
819 const ]b4_int_type_for([b4_pgoto
])[
820 yy::]b4_parser_class_name
[::pgoto_
[] =
825 /* YYDEFGOTO[NTERM-NUM]. */
826 const ]b4_int_type_for([b4_defgoto
])[
827 yy::]b4_parser_class_name
[::defgoto_
[] =
832 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
833 positive, shift that token. If negative, reduce the rule which
834 number is the opposite. If zero, do what YYDEFACT says. */
835 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
836 const ]b4_int_type_for([b4_table
])[
837 yy::]b4_parser_class_name
[::table_
[] =
843 const ]b4_int_type_for([b4_check
])[
844 yy::]b4_parser_class_name
[::check_
[] =
849 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
850 symbol of state STATE-NUM. */
851 const ]b4_int_type_for([b4_stos
])[
852 yy::]b4_parser_class_name
[::stos_
[] =
858 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
860 const ]b4_int_type_for([b4_toknum
])[
861 yy::]b4_parser_class_name
[::token_number_
[] =
867 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
868 const ]b4_int_type_for([b4_r1
])[
869 yy::]b4_parser_class_name
[::r1_
[] =
874 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
875 const ]b4_int_type_for([b4_r2
])[
876 yy::]b4_parser_class_name
[::r2_
[] =
881 #if YYDEBUG || YYERROR_VERBOSE
882 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
883 First, the terminals, then, starting at NTOKENS_, nonterminals. */
885 const yy::]b4_parser_class_name
[::name_
[] =
892 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
893 const yy::]b4_parser_class_name
[::RhsNumberType
894 yy::]b4_parser_class_name
[::rhs_
[] =
899 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
901 const ]b4_int_type_for([b4_prhs
])[
902 yy::]b4_parser_class_name
[::prhs_
[] =
907 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
908 const ]b4_int_type_for([b4_rline
])[
909 yy::]b4_parser_class_name
[::rline_
[] =
914 /** Print the state stack from its BOTTOM up to its TOP (included). */
917 yy::]b4_parser_class_name
[::stack_print_ ()
919 *yycdebug_
<< "Stack now";
920 for (StateStack::const_iterator i
= state_stack_
.begin ();
921 i
!= state_stack_
.end (); ++i
)
922 *yycdebug_
<< ' ' << *i
;
923 *yycdebug_
<< std::endl
;
926 /** Report that the YYRULE is going to be reduced. */
929 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
931 unsigned int yylno
= rline_
[yyrule
];
932 /* Print the symbols being reduced, and their result. */
933 *yycdebug_
<< "Reducing stack by rule " << n_
- 1
934 << " (line " << yylno
<< "), ";
935 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
937 *yycdebug_
<< name_
[rhs_
[i
]] << ' ';
938 *yycdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
942 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
943 yy::]b4_parser_class_name
[::TokenNumberType
944 yy::]b4_parser_class_name
[::translate_ (int token
)
947 const TokenNumberType
952 if ((unsigned int) token
<= user_token_number_max_
)
953 return translate_table
[token
];
958 const int yy::]b4_parser_class_name
[::eof_
= 0;
959 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
960 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
961 const int yy::]b4_parser_class_name
[::empty_
= -2;
962 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
963 const int yy::]b4_parser_class_name
[::terror_
= 1;
964 const int yy::]b4_parser_class_name
[::errcode_
= 256;
965 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
967 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
968 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
973 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
975 #ifndef BISON_STACK_HH
976 # define BISON_STACK_HH
982 template <class T
, class S
= std::deque
<T
> >
987 // Hide our reversed order.
988 typedef typename
S::reverse_iterator iterator
;
989 typedef typename
S::const_reverse_iterator const_iterator
;
995 Stack (unsigned int n
) : seq_ (n
)
1001 operator [] (unsigned int i
)
1008 operator [] (unsigned int i
) const
1017 seq_
.push_front (t
);
1022 pop (unsigned int n
= 1)
1032 return seq_
.size ();
1035 inline const_iterator
begin () const { return seq_
.rbegin (); }
1036 inline const_iterator
end () const { return seq_
.rend (); }
1043 template <class T
, class S
= Stack
<T
> >
1048 Slice (const S
& stack
,
1049 unsigned int range
) : stack_ (stack
),
1056 operator [] (unsigned int i
) const
1058 return stack_
[range_
- i
];
1064 unsigned int range_
;
1068 #endif // not BISON_STACK_HH]
1071 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1074 ** \file position.hh
1075 ** Define the Location class.
1078 #ifndef BISON_POSITION_HH
1079 # define BISON_POSITION_HH
1081 # include <iostream>
1086 /** \brief Abstract a Position. */
1090 /** \brief Initial column number. */
1091 static const unsigned int initial_column
= 0;
1092 /** \brief Initial line number. */
1093 static const unsigned int initial_line
= 1;
1095 /** \name Ctor & dtor.
1098 /** \brief Construct a Position. */
1101 line (initial_line
),
1102 column (initial_column
)
1108 /** \name Line and Column related manipulators
1111 /** \brief (line related) Advance to the COUNT next lines. */
1112 inline void lines (int count
= 1)
1114 column
= initial_column
;
1118 /** \brief (column related) Advance to the COUNT next columns. */
1119 inline void columns (int count
= 1)
1121 int leftmost
= initial_column
;
1122 int current
= column
;
1123 if (leftmost
<= current
+ count
)
1126 column
= initial_column
;
1131 /** \brief File name to which this position refers. */
1132 std::string filename
;
1133 /** \brief Current line number. */
1135 /** \brief Current column number. */
1136 unsigned int column
;
1139 /** \brief Add and assign a Position. */
1140 inline const Position
&
1141 operator+= (Position
& res
, const int width
)
1143 res
.columns (width
);
1147 /** \brief Add two Position objects. */
1148 inline const Position
1149 operator+ (const Position
& begin
, const int width
)
1151 Position res
= begin
;
1152 return res
+= width
;
1155 /** \brief Add and assign a Position. */
1156 inline const Position
&
1157 operator-= (Position
& res
, const int width
)
1159 return res
+= -width
;
1162 /** \brief Add two Position objects. */
1163 inline const Position
1164 operator- (const Position
& begin
, const int width
)
1166 return begin
+ -width
;
1169 /** \brief Intercept output stream redirection.
1170 ** \param ostr the destination output stream
1171 ** \param pos a reference to the Position to redirect
1173 inline std::ostream
&
1174 operator<< (std::ostream
& ostr
, const Position
& pos
)
1176 if (!pos
.filename
.empty ())
1177 ostr
<< pos
.filename
<< ':';
1178 return ostr
<< pos
.line
<< '.' << pos
.column
;
1182 #endif // not BISON_POSITION_HH]
1184 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1187 ** \file location.hh
1188 ** Define the Location class.
1191 #ifndef BISON_LOCATION_HH
1192 # define BISON_LOCATION_HH
1194 # include <iostream>
1196 # include "position.hh"
1201 /** \brief Abstract a Location. */
1204 /** \name Ctor & dtor.
1207 /** \brief Construct a Location. */
1216 /** \name Line and Column related manipulators
1219 /** \brief Reset initial location to final location. */
1220 inline void step (void)
1225 /** \brief Extend the current location to the COUNT next columns. */
1226 inline void columns (unsigned int count
= 1)
1231 /** \brief Extend the current location to the COUNT next lines. */
1232 inline void lines (unsigned int count
= 1)
1240 /** \brief Beginning of the located region. */
1242 /** \brief End of the located region. */
1246 /** \brief Join two Location objects to create a Location. */
1247 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1249 Location res
= begin
;
1254 /** \brief Add two Location objects */
1255 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1257 Location res
= begin
;
1258 res
.columns (width
);
1262 /** \brief Add and assign a Location */
1263 inline Location
& operator+= (Location
& res
, unsigned int width
)
1265 res
.columns (width
);
1269 /** \brief Intercept output stream redirection.
1270 ** \param ostr the destination output stream
1271 ** \param loc a reference to the Location to redirect
1273 ** Avoid duplicate information.
1275 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1277 Position last
= loc
.end
- 1;
1279 if (loc
.begin
.filename
!= last
.filename
)
1280 ostr
<< '-' << last
;
1281 else if (loc
.begin
.line
!= last
.line
)
1282 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1283 else if (loc
.begin
.column
!= last
.column
)
1284 ostr
<< '-' << last
.column
;
1290 #endif // not BISON_LOCATION_HH]