3 # C++ skeleton for Bison
4 # Copyright (C) 2002 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 # Return the smallest signed int type able to handle the number MAX.
25 m4_define([b4_sint_type
],
26 [m4_if(m4_eval([$
1 <= 127]), [1], [signed char],
27 m4_eval([$
1 <= 32767]), [1], [signed short],
33 # Return the smallest unsigned int type able to handle the number MAX.
34 m4_define([b4_uint_type
],
35 [m4_if(m4_eval([$
1 <= 255]), [1], [unsigned char],
36 m4_eval([$
1 <= 65535]), [1], [unsigned short],
40 # b4_lhs_value([TYPE])
41 # --------------------
42 # Expansion of $<TYPE>$.
43 m4_define([b4_lhs_value
],
44 [yyval
[]m4_ifval([$
1], [.$
1])])
47 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
48 # --------------------------------------
49 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
51 m4_define([b4_rhs_value
],
52 [semantic_stack_@
<:@
m4_eval([$
1 - $
2])@
:>@
m4_ifval([$
3], [.$
3])])
58 m4_define([b4_lhs_location
],
62 # b4_rhs_location(RULE-LENGTH, NUM)
63 # ---------------------------------
64 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
66 m4_define([b4_rhs_location
],
67 [location_stack_@
<:@
m4_eval([$
1 - $
2])@
:>@
])
70 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
71 # -----------------------------------------
72 # Output the definition of this token as #define.
73 m4_define([b4_token_define
],
78 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
79 # -------------------------------------------------------
80 # Output the definition of the tokens as #define.
81 m4_define([b4_token_defines
],
82 [m4_map([b4_token_define
], [$@
])])
84 m4_define_default([b4_input_suffix
], [.y
])
86 m4_define_default([b4_output_parser_suffix
],
87 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
89 m4_define_default([b4_output_parser_name
],
90 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
93 m4_define_default([b4_output_header_suffix
],
94 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
96 m4_define_default([b4_output_header_name
],
97 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
99 m4_define_default([b4_header_guard
],
100 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
101 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
103 m4_define([b4_inherit
],
109 m4_define([b4_param
],
115 m4_define([b4_constructor
],
121 m4_define([b4_copyright
],
123 /* A Bison parser, made from b4_filename,
124 by GNU bison b4_version. */
126 /* Skeleton output parser for bison,
127 Copyright 2002 Free Software Foundation, Inc.
129 This program is free software; you can redistribute it and/or modify
130 it under the terms of the GNU General Public License as published by
131 the Free Software Foundation; either version 2, or (at your option)
134 This program is distributed in the hope that it will be useful,
135 but WITHOUT ANY WARRANTY; without even the implied warranty of
136 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137 GNU General Public License for more details.
139 You should have received a copy of the GNU General Public License
140 along with this program; if not, write to the Free Software
141 Foundation, Inc., 59 Temple Place - Suite 330,
142 Boston, MA 02111-1307, USA. */
144 /* As a special exception, when this file is copied by Bison into a
145 Bison output file, you may use that output file without restriction.
146 This special exception was added by the Free Software Foundation
147 in version 1.24 of Bison. */])
150 #output "b4_output_header_name"
152 #ifndef b4_header_guard
153 # define b4_header_guard
156 #include "location.hh"
161 /* Using locations. */
162 #define YYLSP_NEEDED b4_locations_flag
164 /* Copy the first part of user declarations. */
167 /* Line __line__ of __file__. */
168 #line __oline__ "__ofile__"
171 b4_token_defines(b4_tokens
)
173 /* Enabling traces. */
175 # define YYDEBUG b4_debug
178 /* Enabling verbose error message. */
179 #ifndef YYERROR_VERBOSE
180 # define YYERROR_VERBOSE b4_error_verbose
185 [#line b4_stype_line "b4_filename"
186 typedef union b4_stype yystype
;
187 /* Line __line__ of __file__. */
188 #line __oline__ "__ofile__"],
189 [typedef int yystype
;])
190 # define YYSTYPE yystype
193 /* Copy the second part of user declarations. */
196 /* Line __line__ of __file__. */
197 #line __oline__ "__ofile__"
198 #ifndef YYLLOC_DEFAULT
199 # define YYLLOC_DEFAULT(Current, Rhs, N) \
200 Current.last_line = Rhs[[N]].last_line; \
201 Current.last_column = Rhs[[N]].last_column;
204 m4_if(b4_locations_flag
, [0], [],
206 typedef struct yyltype
213 # define YYLTYPE yyltype
220 template < typename P
>
226 struct Traits
< b4_name
>
228 typedef b4_uint_type(b4_translate_max
) TokenNumberType
;
229 typedef b4_sint_type(b4_rhs_max
) RhsNumberType
;
230 typedef int StateType
;
231 typedef yystype SemanticType
;
232 typedef b4_ltype LocationType
;
238 class b4_name b4_inherit
242 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
243 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
244 typedef Traits
< b4_name
>::StateType StateType
;
245 typedef Traits
< b4_name
>::SemanticType SemanticType
;
246 typedef Traits
< b4_name
>::LocationType LocationType
;
248 typedef Stack
< StateType
> StateStack
;
249 typedef Stack
< SemanticType
> SemanticStack
;
250 typedef Stack
< LocationType
> LocationStack
;
254 LocationType initlocation
[]b4_param
) :
255 b4_constructor
[]debug_ (debug
),
257 initlocation_ (initlocation
)
259 b4_name (bool debug
[]b4_param
) :
260 b4_constructor
[]debug_ (debug
),
270 virtual int parse ();
274 virtual void lex_ ();
275 virtual void error_ ();
276 virtual void print_ ();
279 StateStack state_stack_
;
280 SemanticStack semantic_stack_
;
281 LocationStack location_stack_
;
284 static const short pact_
[[]];
285 static const short defact_
[[]];
286 static const short pgoto_
[[]];
287 static const short defgoto_
[[]];
288 static const short table_
[[]];
289 static const short check_
[[]];
290 static const b4_uint_type(b4_r1_max
) r1_
[[]];
291 static const b4_uint_type(b4_r2_max
) 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_uint_type(b4_prhs_max
) prhs_
[[]];
301 static const b4_uint_type(b4_rline_max
) rline_
[[]];
302 static const b4_uint_type(b4_stos_max
) stos_
[[]];
303 static const short token_number_
[[]];
306 /* Even more tables. */
307 static inline TokenNumberType
translate_ (int token
);
310 static const int eof_
;
311 static const int last_
;
312 static const int flag_
;
313 static const int nnts_
;
314 static const int nsym_
;
315 static const int empty_
;
316 static const int final_
;
317 static const int terror_
;
318 static const int errcode_
;
319 static const int ntokens_
;
320 static const int initdepth_
;
321 static const unsigned user_token_number_max_
;
322 static const TokenNumberType undef_token_
;
331 std::ostream
&cdebug_
;
333 /* Lookahead and lookahead in internal form. */
340 /* Semantic value and location of lookahead token. */
342 LocationType location
;
348 /* Initial location. */
349 LocationType initlocation_
;
353 #endif /* not b4_header_guard */
355 #output "b4_output_prefix[]b4_output_infix[].cc"
358 #include "b4_output_header_name"
360 /* Enable debugging if requested. */
362 # define YYCDEBUG if (debug_) cdebug_
364 # define YYCDEBUG if (0) cdebug_
365 #endif /* !YYDEBUG */
368 yy::b4_name::parse ()
373 /* Initialize stack. */
374 state_stack_
= StateStack (0);
375 semantic_stack_
= SemanticStack (1);
376 location_stack_
= LocationStack (1);
382 location
= initlocation_
;
384 YYCDEBUG
<< "Starting parse" << std::endl
;
388 state_stack_
.push (state_
);
389 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
395 /* Try to take a decision without lookahead. */
396 n_
= pact_
[[state_]];
400 /* Read a lookahead token. */
401 if (looka_
== empty_
)
403 YYCDEBUG
<< "Reading a token: ";
407 /* Convert token to internal form. */
412 YYCDEBUG
<< "Now at end of input." << std::endl
;
416 ilooka_
= translate_ (looka_
);
420 YYCDEBUG
<< "Next token is " << looka_
421 << " (" << name_
[[ilooka_]];
423 YYCDEBUG
<< ')' << std::endl
;
429 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
432 /* Reduce or error. */
451 /* Shift the lookahead token. */
452 YYCDEBUG
<< "Shifting token " << looka_
453 << " (" << name_
[[ilooka_]] << "), ";
455 /* Discard the token being shifted unless it is eof. */
459 semantic_stack_
.push (value
);
460 location_stack_
.push (location
);
462 /* Count tokens shifted since error; after three, turn off error
470 /* Default action. */
472 n_
= defact_
[[state_]];
482 yyval
= semantic_stack_
[[len_
- 1]];
483 yyloc
= location_stack_
[[len_
- 1]];
487 yyval
= semantic_stack_
[[0]];
488 yyloc
= location_stack_
[[0]];
494 YYCDEBUG
<< "Reducing via rule " << n_
- 1
495 << " (line " << rline_
[[n_]] << "), ";
496 for (b4_uint_type(b4_prhs_max
) i
= prhs_
[[n_]];
498 YYCDEBUG
<< name_
[[rhs_
[i
]]] << ' ';
499 YYCDEBUG
<< "-> " << name_
[[r1_
[n_
]]] << std::endl
;
505 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
506 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
514 /* Line __line__ of __file__. */
515 #line __oline__ "__ofile__"
517 state_stack_
.pop (len_
);
518 semantic_stack_
.pop (len_
);
519 location_stack_
.pop (len_
);
524 YYCDEBUG
<< "state stack now";
525 for (StateStack::ConstIterator i
= state_stack_
.begin ();
526 i
!= state_stack_
.end (); ++i
)
527 YYCDEBUG
<< ' ' << *i
;
528 YYCDEBUG
<< std::endl
;
532 semantic_stack_
.push (yyval
);
533 location_stack_
.push (yyloc
);
535 /* Shift the result of the reduction. */
537 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
538 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
539 state_
= table_
[[state_]];
541 state_
= defgoto_
[[n_
- ntokens_
]];
544 /* Report and recover from errors. This is very incomplete. */
546 /* If not already recovering from an error, report this error. */
552 n_
= pact_
[[state_]];
553 if (n_
> flag_
&& n_
< last_
)
555 message
= "parse error, unexpected ";
556 message
+= name_
[[ilooka_]];
559 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
560 if (check_
[[x
+ n_
]] == x
)
565 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
566 if (check_
[[x
+ n_
]] == x
)
568 message
+= (!count
++) ? ", expecting " : " or ";
569 message
+= name_
[[x]];
576 message
= "parse error";
581 /* Error raised explicitly by an action. */
585 /* If just tried and failed to reuse lookahead token after an
586 error, discard it. */
588 /* Return failure if at end of input. */
591 YYCDEBUG
<< "Discarding token " << looka_
592 << " (" << name_
[[ilooka_]] << ")." << std::endl
;
596 /* Else will try to reuse lookahead token after shifting the error
603 n_
= pact_
[[state_]];
607 if (0 <= n_
&& n_
<= last_
&& check_
[[n_]] == terror_
)
615 /* Pop the current state because it cannot handle the error token. */
616 if (!state_stack_
.height ())
622 if (stos_
[[state_]] < ntokens_
)
624 YYCDEBUG
<< "Error: popping token "
625 << token_number_
[[stos_
[state_
]]]
626 << " (" << name_
[[stos_
[state_
]]];
628 YYPRINT (stderr
, token_number_
[[stos_
[state_
]]],
629 semantic_stack_
.top ());
631 YYCDEBUG
<< ')' << std::endl
;
635 YYCDEBUG
<< "Error: popping nonterminal ("
636 << name_
[[stos_
[state_
]]] << ')' << std::endl
;
641 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
642 semantic_stack_
.pop ();
643 location_stack_
.pop ();;
648 YYCDEBUG
<< "Error: state stack now";
649 for (StateStack::ConstIterator i
= state_stack_
.begin ();
650 i
!= state_stack_
.end (); ++i
)
651 YYCDEBUG
<< ' ' << *i
;
652 YYCDEBUG
<< std::endl
;
660 YYCDEBUG
<< "Shifting error token, ";
662 semantic_stack_
.push (value
);
663 location_stack_
.push (location
);
681 looka_
= yylex (&value
, &location
);
683 looka_
= yylex (&value
);
687 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
690 yy::b4_name::pact_
[[]] =
695 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
696 doesn't specify something else to do. Zero means the default is an
699 yy::b4_name::defact_
[[]] =
704 /* YYPGOTO[[NTERM-NUM]]. */
706 yy::b4_name::pgoto_
[[]] =
711 /* YYDEFGOTO[[NTERM-NUM]]. */
713 yy::b4_name::defgoto_
[[]] =
718 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
719 positive, shift that token. If negative, reduce the rule which
720 number is the opposite. If zero, do what YYDEFACT says. */
722 yy::b4_name::table_
[[]] =
729 yy::b4_name::check_
[[]] =
735 /* STOS_[[STATE-NUM]] -- The (internal number of the) accessing
736 symbol of state STATE-NUM. */
737 const b4_uint_type(b4_stos_max
)
738 yy::b4_name::stos_
[[]] =
743 /* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding
746 yy::b4_name::token_number_
[[]] =
752 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
753 const b4_uint_type(b4_r1_max
)
754 yy::b4_name::r1_
[[]] =
759 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
760 const b4_uint_type(b4_r2_max
)
761 yy::b4_name::r2_
[[]] =
766 #if YYDEBUG || YYERROR_VERBOSE
767 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
768 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
770 const yy::b4_name::name_
[[]] =
777 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
778 const yy::b4_name::RhsNumberType
779 yy::b4_name::rhs_
[[]] =
784 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
786 const b4_uint_type(b4_prhs_max
)
787 yy::b4_name::prhs_
[[]] =
792 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
793 const b4_uint_type(b4_rline_max
)
794 yy::b4_name::rline_
[[]] =
800 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
801 yy::b4_name::TokenNumberType
802 yy::b4_name::translate_ (int token
)
805 const TokenNumberType
810 if ((unsigned) token
<= user_token_number_max_
)
811 return translate_
[[token]];
816 const int yy::b4_name::eof_
= 0;
817 const int yy::b4_name::last_
= b4_last
;
818 const int yy::b4_name::flag_
= b4_flag
;
819 const int yy::b4_name::nnts_
= b4_nnts
;
820 const int yy::b4_name::nsym_
= b4_nsym
;
821 const int yy::b4_name::empty_
= -2;
822 const int yy::b4_name::final_
= b4_final
;
823 const int yy::b4_name::terror_
= 1;
824 const int yy::b4_name::errcode_
= 256;
825 const int yy::b4_name::ntokens_
= b4_ntokens
;
826 const int yy::b4_name::initdepth_
= b4_initdepth
;
828 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
829 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
836 #ifndef BISON_STACK_HH
837 # define BISON_STACK_HH
843 template < class T
, class S
= std::deque
< T
> >
848 typedef typename
S::iterator Iterator
;
849 typedef typename
S::const_iterator ConstIterator
;
855 Stack (unsigned n
) : seq_ (n
)
861 operator [[]] (unsigned index
)
863 return seq_
[[index]];
868 operator [[]] (unsigned index
) const
870 return seq_
[[index]];
895 inline ConstIterator
begin () const { return seq_
.begin (); }
896 inline ConstIterator
end () const { return seq_
.end (); }
903 template < class T
, class S
= Stack
< T
> >
908 Slice (const S
& stack
,
909 unsigned range
) : stack_ (stack
),
916 operator [[]] (unsigned index
) const
918 return stack_
[[range_
- index
]];
928 #endif // not BISON_STACK_HH
930 #output "location.hh"
933 #ifndef BISON_LOCATION_HH
934 # define BISON_LOCATION_HH
951 #endif // not BISON_LOCATION_HH