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 ]b4_parser_class_name
[ (bool debug
,
237 LocationType
][]b4_param
[]b4_parse_param_decl
[) :
238 ]b4_constructor
[][debug_ (debug
),
239 cdebug_ (std::cerr
)]b4_parse_param_cons
[
241 cdebug_
<< __FILE__
<< ':' << __LINE__
242 << ": this constructor is provided by backward compatibility"
243 << ", but will be removed in the near future."
247 virtual ~]b4_parser_class_name
[ ()
251 virtual int parse ();
255 virtual void lex_ ();
256 virtual void error_ ();
257 virtual void print_ ();
258 virtual void report_syntax_error_ ();
260 virtual void symprint_ (int yytype
,
261 const SemanticType
* yyvaluep
,
262 const LocationType
* yylocationp
);
263 #endif /* ! YYDEBUG */
267 StateStack state_stack_
;
268 SemanticStack semantic_stack_
;
269 LocationStack location_stack_
;
272 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
273 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
274 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
275 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
276 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
277 static const ]b4_int_type_for([b4_table
])[ table_
[];
278 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
279 static const ]b4_int_type_for([b4_check
])[ check_
[];
280 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
281 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
282 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
284 #if YYDEBUG || YYERROR_VERBOSE
285 static const char* const name_
[];
288 /* More tables, for debugging. */
290 static const RhsNumberType rhs_
[];
291 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
292 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
293 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
294 virtual void reduce_print_ (int yyrule
);
295 virtual void stack_print_ ();
298 /* Even more tables. */
299 inline TokenNumberType
translate_ (int token
);
300 inline void destruct_ (const char* yymsg
,
302 SemanticType
* yyvaluep
, LocationType
* yylocationp
);
304 /// Pop \a n symbols the three stacks.
305 inline void pop (unsigned int n
= 1);
308 static const int eof_
;
309 /* LAST_ -- Last index in TABLE_. */
310 static const int last_
;
311 static const int nnts_
;
312 static const int empty_
;
313 static const int final_
;
314 static const int terror_
;
315 static const int errcode_
;
316 static const int ntokens_
;
317 static const unsigned int user_token_number_max_
;
318 static const TokenNumberType undef_token_
;
325 /* Error handling. */
331 std::ostream
& cdebug_
;
333 /* Look-ahead and look-ahead in internal form. */
340 /// Semantic value of the look-ahead.
342 /// Location of the look-ahead.
343 LocationType location
;
344 /// The locations where the error started and ended.
345 Location error_range_
[2];
351 ]b4_parse_param_vars
[
355 #endif /* ! defined PARSER_HEADER_H */]
357 @output @output_parser_name@
358 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
361 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
363 /* Enable debugging if requested. */
370 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
374 cdebug_ << (Title) << ' '; \
375 symprint_ ((Type), (Value), (Location)); \
376 cdebug_ << std::endl; \
380 # define YY_REDUCE_PRINT(Rule) \
383 reduce_print_ (Rule); \
386 # define YY_STACK_PRINT() \
394 # define YYCDEBUG if (0) cdebug_
395 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
396 # define YY_REDUCE_PRINT(Rule)
397 # define YY_STACK_PRINT()
399 #endif /* !YYDEBUG */
401 #define YYACCEPT goto yyacceptlab
402 #define YYABORT goto yyabortlab
403 #define YYERROR goto yyerrorlab
406 /*--------------------------------.
407 | Print this symbol on YYOUTPUT. |
408 `--------------------------------*/
411 yy::]b4_parser_class_name
[::symprint_ (int yytype
,
412 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
414 /* Pacify ``unused variable'' warnings. */
418 cdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
419 << ' ' << name_
[yytype
] << " ("
420 << *yylocationp
<< ": ";
423 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
429 #endif /* ! YYDEBUG */
432 yy::]b4_parser_class_name
[::destruct_ (const char* yymsg
,
433 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
435 /* Pacify ``unused variable'' warnings. */
439 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
443 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
450 yy::]b4_parser_class_name
[::pop (unsigned int n
)
452 state_stack_
.pop (n
);
453 semantic_stack_
.pop (n
);
454 location_stack_
.pop (n
);
458 yy::]b4_parser_class_name
[::parse ()
460 YYCDEBUG
<< "Starting parse" << std::endl
;
469 ]m4_ifdef([b4_initial_action
], [
470 m4_pushdef([b4_at_dollar
], [location
])dnl
471 m4_pushdef([b4_dollar_dollar
], [value
])dnl
472 /* User initialization code. */
474 m4_popdef([b4_dollar_dollar
])dnl
475 m4_popdef([b4_at_dollar
])dnl
476 /* Line __line__ of yacc.c. */
477 b4_syncline([@oline@
], [@ofile@
])])dnl
479 [ /* Initialize the stacks. The initial state will be pushed in
480 yynewstate, since the latter expects the semantical and the
481 location values to have been already stored, initialize these
482 stacks with a primary value. */
483 state_stack_
= StateStack (0);
484 semantic_stack_
= SemanticStack (0);
485 location_stack_
= LocationStack (0);
486 semantic_stack_
.push (value
);
487 location_stack_
.push (location
);
491 state_stack_
.push (state_
);
492 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
498 /* Try to take a decision without look-ahead. */
500 if (n_
== pact_ninf_
)
503 /* Read a look-ahead token. */
504 if (looka_
== empty_
)
506 YYCDEBUG
<< "Reading a token: ";
510 /* Convert token to internal form. */
513 looka_
= ilooka_
= eof_
;
514 YYCDEBUG
<< "Now at end of input." << std::endl
;
518 ilooka_
= translate_ (looka_
);
519 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
522 /* If the proper action on seeing token ILOOKA_ is to reduce or to
523 detect an error, take that action. */
525 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
528 /* Reduce or error. */
532 if (n_
== table_ninf_
)
547 /* Shift the look-ahead token. */
548 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
550 /* Discard the token being shifted unless it is eof. */
554 semantic_stack_
.push (value
);
555 location_stack_
.push (location
);
557 /* Count tokens shifted since error; after three, turn off error
565 /*-----------------------------------------------------------.
566 | yydefault -- do the default action for the current state. |
567 `-----------------------------------------------------------*/
569 n_
= defact_
[state_
];
574 /*-----------------------------.
575 | yyreduce -- Do a reduction. |
576 `-----------------------------*/
579 /* If LEN_ is nonzero, implement the default value of the action:
580 `$$ = $1'. Otherwise, use the top of the stack.
582 Otherwise, the following line sets YYVAL to garbage.
583 This behavior is undocumented and Bison
584 users should not rely upon it. */
587 yyval
= semantic_stack_
[len_
- 1];
588 yyloc
= location_stack_
[len_
- 1];
592 yyval
= semantic_stack_
[0];
593 yyloc
= location_stack_
[0];
598 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
599 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
601 YY_REDUCE_PRINT (n_
);
607 ]/* Line __line__ of lalr1.cc. */
608 b4_syncline([@oline@
], [@ofile@
])[
614 semantic_stack_
.push (yyval
);
615 location_stack_
.push (yyloc
);
617 /* Shift the result of the reduction. */
619 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
620 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
621 state_
= table_
[state_
];
623 state_
= defgoto_
[n_
- ntokens_
];
626 /*------------------------------------.
627 | yyerrlab -- here on detecting error |
628 `------------------------------------*/
630 /* If not already recovering from an error, report this error. */
631 report_syntax_error_ ();
633 error_range_
[0] = location
;
636 /* If just tried and failed to reuse look-ahead token after an
637 error, discard it. */
639 /* Return failure if at end of input. */
642 /* If at end of input, pop the error token,
643 then the rest of the stack, then return failure. */
647 error_range_
[0] = location_stack_
[0];
649 if (state_stack_
.height () == 1)
651 destruct_ ("Error: popping",
652 stos_
[state_stack_
[0]],
654 &location_stack_
[0]);
659 destruct_ ("Error: discarding", ilooka_
, &value
, &location
);
664 /* Else will try to reuse look-ahead token after shifting the error
669 /*---------------------------------------------------.
670 | yyerrorlab -- error raised explicitly by YYERROR. |
671 `---------------------------------------------------*/
675 /* Pacify GCC when the user code never invokes YYERROR and the label
676 yyerrorlab therefore never appears in user code. */
681 error_range_
[0] = location_stack_
[len_
- 1];
683 state_
= state_stack_
[0];
686 /*-------------------------------------------------------------.
687 | yyerrlab1 -- common code for both syntax error and YYERROR. |
688 `-------------------------------------------------------------*/
690 errstatus_
= 3; /* Each real token shifted decrements this. */
695 if (n_
!= pact_ninf_
)
698 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
706 /* Pop the current state because it cannot handle the error token. */
707 if (state_stack_
.height () == 1)
710 error_range_
[0] = location_stack_
[0];
711 destruct_ ("Error: popping",
712 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
714 state_
= state_stack_
[0];
721 error_range_
[1] = location
;
722 // Using LOCATION is tempting, but would change the location of
723 // the look-ahead. YYLOC is available though.
724 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
725 semantic_stack_
.push (value
);
726 location_stack_
.push (yyloc
);
728 /* Shift the error token. */
729 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
730 &semantic_stack_
[0], &location_stack_
[0]);
741 /* Free the lookahead. */
742 destruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
748 yy::]b4_parser_class_name
[::lex_ ()
751 looka_
= yylex (&value
, &location
);
753 looka_
= yylex (&value
);
757 /** Generate an error message, and invoke yyerror. */
759 yy::]b4_parser_class_name
[::report_syntax_error_ ()
761 /* If not already recovering from an error, report this error. */
768 if (pact_ninf_
< n_
&& n_
< last_
)
770 message
= "syntax error, unexpected ";
771 message
+= name_
[ilooka_
];
774 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
775 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
780 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
781 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
783 message
+= (!count
++) ? ", expecting " : " or ";
791 message
= "syntax error";
797 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
799 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
800 const ]b4_int_type_for([b4_pact
])[
801 yy::]b4_parser_class_name
[::pact_
[] =
806 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
807 doesn't specify something else to do. Zero means the default is an
809 const ]b4_int_type_for([b4_defact
])[
810 yy::]b4_parser_class_name
[::defact_
[] =
815 /* YYPGOTO[NTERM-NUM]. */
816 const ]b4_int_type_for([b4_pgoto
])[
817 yy::]b4_parser_class_name
[::pgoto_
[] =
822 /* YYDEFGOTO[NTERM-NUM]. */
823 const ]b4_int_type_for([b4_defgoto
])[
824 yy::]b4_parser_class_name
[::defgoto_
[] =
829 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
830 positive, shift that token. If negative, reduce the rule which
831 number is the opposite. If zero, do what YYDEFACT says. */
832 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
833 const ]b4_int_type_for([b4_table
])[
834 yy::]b4_parser_class_name
[::table_
[] =
840 const ]b4_int_type_for([b4_check
])[
841 yy::]b4_parser_class_name
[::check_
[] =
846 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
847 symbol of state STATE-NUM. */
848 const ]b4_int_type_for([b4_stos
])[
849 yy::]b4_parser_class_name
[::stos_
[] =
855 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
857 const ]b4_int_type_for([b4_toknum
])[
858 yy::]b4_parser_class_name
[::token_number_
[] =
864 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
865 const ]b4_int_type_for([b4_r1
])[
866 yy::]b4_parser_class_name
[::r1_
[] =
871 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
872 const ]b4_int_type_for([b4_r2
])[
873 yy::]b4_parser_class_name
[::r2_
[] =
878 #if YYDEBUG || YYERROR_VERBOSE
879 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
880 First, the terminals, then, starting at NTOKENS_, nonterminals. */
882 const yy::]b4_parser_class_name
[::name_
[] =
889 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
890 const yy::]b4_parser_class_name
[::RhsNumberType
891 yy::]b4_parser_class_name
[::rhs_
[] =
896 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
898 const ]b4_int_type_for([b4_prhs
])[
899 yy::]b4_parser_class_name
[::prhs_
[] =
904 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
905 const ]b4_int_type_for([b4_rline
])[
906 yy::]b4_parser_class_name
[::rline_
[] =
911 /** Print the state stack from its BOTTOM up to its TOP (included). */
914 yy::]b4_parser_class_name
[::stack_print_ ()
916 cdebug_
<< "Stack now";
917 for (StateStack::const_iterator i
= state_stack_
.begin ();
918 i
!= state_stack_
.end (); ++i
)
919 cdebug_
<< ' ' << *i
;
920 cdebug_
<< std::endl
;
923 /** Report that the YYRULE is going to be reduced. */
926 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
928 unsigned int yylno
= rline_
[yyrule
];
929 /* Print the symbols being reduced, and their result. */
930 cdebug_
<< "Reducing stack by rule " << n_
- 1 << " (line " << yylno
<< "), ";
931 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
933 cdebug_
<< name_
[rhs_
[i
]] << ' ';
934 cdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
938 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
939 yy::]b4_parser_class_name
[::TokenNumberType
940 yy::]b4_parser_class_name
[::translate_ (int token
)
943 const TokenNumberType
948 if ((unsigned int) token
<= user_token_number_max_
)
949 return translate_table
[token
];
954 const int yy::]b4_parser_class_name
[::eof_
= 0;
955 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
956 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
957 const int yy::]b4_parser_class_name
[::empty_
= -2;
958 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
959 const int yy::]b4_parser_class_name
[::terror_
= 1;
960 const int yy::]b4_parser_class_name
[::errcode_
= 256;
961 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
963 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
964 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
969 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
971 #ifndef BISON_STACK_HH
972 # define BISON_STACK_HH
978 template < class T
, class S
= std::deque
< T
> >
983 // Hide our reversed order.
984 typedef typename
S::reverse_iterator iterator
;
985 typedef typename
S::const_reverse_iterator const_iterator
;
991 Stack (unsigned int n
) : seq_ (n
)
997 operator [] (unsigned int i
)
1004 operator [] (unsigned int i
) const
1013 seq_
.push_front (t
);
1018 pop (unsigned int n
= 1)
1028 return seq_
.size ();
1031 inline const_iterator
begin () const { return seq_
.rbegin (); }
1032 inline const_iterator
end () const { return seq_
.rend (); }
1039 template < class T
, class S
= Stack
< T
> >
1044 Slice (const S
& stack
,
1045 unsigned int range
) : stack_ (stack
),
1052 operator [] (unsigned int i
) const
1054 return stack_
[range_
- i
];
1060 unsigned int range_
;
1064 #endif // not BISON_STACK_HH]
1067 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1070 ** \file position.hh
1071 ** Define the Location class.
1074 #ifndef BISON_POSITION_HH
1075 # define BISON_POSITION_HH
1077 # include <iostream>
1082 /** \brief Abstract a Position. */
1086 /** \brief Initial column number. */
1087 static const unsigned int initial_column
= 0;
1088 /** \brief Initial line number. */
1089 static const unsigned int initial_line
= 1;
1091 /** \name Ctor & dtor.
1094 /** \brief Construct a Position. */
1097 line (initial_line
),
1098 column (initial_column
)
1104 /** \name Line and Column related manipulators
1107 /** \brief (line related) Advance to the COUNT next lines. */
1108 inline void lines (int count
= 1)
1110 column
= initial_column
;
1114 /** \brief (column related) Advance to the COUNT next columns. */
1115 inline void columns (int count
= 1)
1117 int leftmost
= initial_column
;
1118 int current
= column
;
1119 if (leftmost
<= current
+ count
)
1122 column
= initial_column
;
1127 /** \brief File name to which this position refers. */
1128 std::string filename
;
1129 /** \brief Current line number. */
1131 /** \brief Current column number. */
1132 unsigned int column
;
1135 /** \brief Add and assign a Position. */
1136 inline const Position
&
1137 operator+= (Position
& res
, const int width
)
1139 res
.columns (width
);
1143 /** \brief Add two Position objects. */
1144 inline const Position
1145 operator+ (const Position
& begin
, const int width
)
1147 Position res
= begin
;
1148 return res
+= width
;
1151 /** \brief Add and assign a Position. */
1152 inline const Position
&
1153 operator-= (Position
& res
, const int width
)
1155 return res
+= -width
;
1158 /** \brief Add two Position objects. */
1159 inline const Position
1160 operator- (const Position
& begin
, const int width
)
1162 return begin
+ -width
;
1165 /** \brief Intercept output stream redirection.
1166 ** \param ostr the destination output stream
1167 ** \param pos a reference to the Position to redirect
1169 inline std::ostream
&
1170 operator<< (std::ostream
& ostr
, const Position
& pos
)
1172 if (!pos
.filename
.empty ())
1173 ostr
<< pos
.filename
<< ':';
1174 return ostr
<< pos
.line
<< '.' << pos
.column
;
1178 #endif // not BISON_POSITION_HH]
1180 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1183 ** \file location.hh
1184 ** Define the Location class.
1187 #ifndef BISON_LOCATION_HH
1188 # define BISON_LOCATION_HH
1190 # include <iostream>
1192 # include "position.hh"
1197 /** \brief Abstract a Location. */
1200 /** \name Ctor & dtor.
1203 /** \brief Construct a Location. */
1212 /** \name Line and Column related manipulators
1215 /** \brief Reset initial location to final location. */
1216 inline void step (void)
1221 /** \brief Extend the current location to the COUNT next columns. */
1222 inline void columns (unsigned int count
= 1)
1227 /** \brief Extend the current location to the COUNT next lines. */
1228 inline void lines (unsigned int count
= 1)
1236 /** \brief Beginning of the located region. */
1238 /** \brief End of the located region. */
1242 /** \brief Join two Location objects to create a Location. */
1243 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1245 Location res
= begin
;
1250 /** \brief Add two Location objects */
1251 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1253 Location res
= begin
;
1254 res
.columns (width
);
1258 /** \brief Add and assign a Location */
1259 inline Location
& operator+= (Location
& res
, unsigned int width
)
1261 res
.columns (width
);
1265 /** \brief Intercept output stream redirection.
1266 ** \param ostr the destination output stream
1267 ** \param loc a reference to the Location to redirect
1269 ** Avoid duplicate information.
1271 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1273 Position last
= loc
.end
- 1;
1275 if (loc
.begin
.filename
!= last
.filename
)
1276 ostr
<< '-' << last
;
1277 else if (loc
.begin
.line
!= last
.line
)
1278 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1279 else if (loc
.begin
.column
!= last
.column
)
1280 ostr
<< '-' << last
.column
;
1286 #endif // not BISON_LOCATION_HH]