5 # Return the smallest signed int type able to handle the number MAX.
6 m4_define([b4_sint_type
],
7 [m4_if(m4_eval([$
1 <= 127]), [1], [signed char],
8 m4_eval([$
1 <= 32767]), [1], [signed short],
14 # Return the smallest unsigned int type able to handle the number MAX.
15 m4_define([b4_uint_type
],
16 [m4_if(m4_eval([$
1 <= 255]), [1], [unsigned char],
17 m4_eval([$
1 <= 65535]), [1], [unsigned short],
21 # b4_lhs_value([TYPE])
22 # --------------------
23 # Expansion of $<TYPE>$.
24 m4_define([b4_lhs_value
],
25 [yyval
[]m4_ifval([$
1], [.$
1])])
28 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
29 # --------------------------------------
30 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
32 m4_define([b4_rhs_value
],
33 [semantic_stack_@
<:@
m4_eval([$
1 - $
2])@
:>@
m4_ifval([$
3], [.$
3])])
39 m4_define([b4_lhs_location
],
43 # b4_rhs_location(RULE-LENGTH, NUM)
44 # ---------------------------------
45 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
47 m4_define([b4_rhs_location
],
48 [location_stack_@
<:@
m4_eval([$
1 - $
2])@
:>@
])
51 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
52 # -----------------------------------------
53 # Output the definition of this token as #define.
54 m4_define([b4_token_define
],
59 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
60 # -------------------------------------------------------
61 # Output the definition of the tokens as #define.
62 m4_define([b4_token_defines
],
63 [m4_map([b4_token_define
], [$@
])])
65 m4_define_default([b4_input_suffix
], [.y
])
67 m4_define_default([b4_output_parser_suffix
],
68 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
70 m4_define_default([b4_output_parser_name
],
71 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
74 m4_define_default([b4_output_header_suffix
],
75 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
77 m4_define_default([b4_output_header_name
],
78 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
80 m4_define_default([b4_header_guard
],
81 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
82 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
84 m4_define([b4_inherit
],
96 m4_define([b4_constructor
],
102 m4_define([b4_copyright
],
104 /* A Bison parser, made from b4_filename,
105 by GNU bison b4_version. */
107 /* Skeleton output parser for bison,
108 Copyright 2002 Free Software Foundation, Inc.
110 This program is free software; you can redistribute it and/or modify
111 it under the terms of the GNU General Public License as published by
112 the Free Software Foundation; either version 2, or (at your option)
115 This program is distributed in the hope that it will be useful,
116 but WITHOUT ANY WARRANTY; without even the implied warranty of
117 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 GNU General Public License for more details.
120 You should have received a copy of the GNU General Public License
121 along with this program; if not, write to the Free Software
122 Foundation, Inc., 59 Temple Place - Suite 330,
123 Boston, MA 02111-1307, USA. */
125 /* As a special exception, when this file is copied by Bison into a
126 Bison output file, you may use that output file without restriction.
127 This special exception was added by the Free Software Foundation
128 in version 1.24 of Bison. */])
131 #output "b4_output_header_name"
133 #ifndef b4_header_guard
134 # define b4_header_guard
137 #include "location.hh"
141 /* Using locations. */
142 #define YYLSP_NEEDED b4_locations_flag
144 /* Copy the first part of user declarations. */
148 b4_token_defines(b4_tokens
)
150 /* Enabling traces. */
152 # define YYDEBUG b4_debug
155 /* Enabling verbose error message. */
156 #ifndef YYERROR_VERBOSE
157 # define YYERROR_VERBOSE b4_error_verbose
161 m4_ifdef([b4_stype_line
],
162 [#line b4_stype_line "b4_filename"
166 # define YYSTYPE yystype
169 /* Copy the second part of user declarations. */
172 #line __oline__ "__ofile__"
173 #ifndef YYLLOC_DEFAULT
174 # define YYLLOC_DEFAULT(Current, Rhs, N) \
175 Current.last_line = Rhs[[N]].last_line; \
176 Current.last_column = Rhs[[N]].last_column;
179 m4_if(b4_locations_flag
, [0], [],
181 typedef struct yyltype
188 # define YYLTYPE yyltype
195 template < typename P
>
201 struct Traits
< b4_name
>
203 typedef b4_uint_type(b4_translate_max
) TokenNumberType
;
204 typedef b4_sint_type(b4_rhs_max
) RhsNumberType
;
205 typedef int StateType
;
206 typedef yystype SemanticType
;
207 typedef b4_ltype LocationType
;
213 class b4_name b4_inherit
217 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
218 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
219 typedef Traits
< b4_name
>::StateType StateType
;
220 typedef Traits
< b4_name
>::SemanticType SemanticType
;
221 typedef Traits
< b4_name
>::LocationType LocationType
;
223 typedef Stack
< StateType
> StateStack
;
224 typedef Stack
< SemanticType
> SemanticStack
;
225 typedef Stack
< LocationType
> LocationStack
;
229 LocationType initlocation
[]b4_param
) :
230 b4_constructor
[]debug_ (debug
),
231 initlocation_ (initlocation
)
233 b4_name (bool debug
[]b4_param
) :
234 b4_constructor
[]debug_ (debug
)
243 virtual int parse ();
247 virtual void lex_ ();
248 virtual void error_ ();
249 virtual void print_ ();
252 StateStack state_stack_
;
253 SemanticStack semantic_stack_
;
254 LocationStack location_stack_
;
257 static const short pact_
[[]];
258 static const short defact_
[[]];
259 static const short pgoto_
[[]];
260 static const short defgoto_
[[]];
261 static const short table_
[[]];
262 static const short check_
[[]];
263 static const b4_uint_type(b4_r1_max
) r1_
[[]];
264 static const b4_uint_type(b4_r2_max
) r2_
[[]];
266 #if YYDEBUG || YYERROR_VERBOSE
267 static const char* const name_
[[]];
270 /* More tables, for debugging. */
272 static const RhsNumberType rhs_
[[]];
273 static const b4_uint_type(b4_prhs_max
) prhs_
[[]];
274 static const b4_uint_type(b4_rline_max
) rline_
[[]];
277 /* Even more tables. */
278 static inline TokenNumberType
translate_ (int token
);
281 static const int eof_
;
282 static const int last_
;
283 static const int flag_
;
284 static const int nnts_
;
285 static const int nsym_
;
286 static const int empty_
;
287 static const int final_
;
288 static const int terror_
;
289 static const int errcode_
;
290 static const int ntokens_
;
291 static const int initdepth_
;
292 static const unsigned user_token_number_max_
;
293 static const TokenNumberType undef_token_
;
301 /* Lookahead and lookahead in internal form. */
308 /* Semantic value and location of lookahead token. */
310 LocationType location
;
316 /* Initial location. */
317 LocationType initlocation_
;
321 #endif /* not b4_header_guard */
323 #output "b4_output_prefix[]b4_output_infix[].cc"
326 #include "b4_output_header_name"
328 /* Enable debugging if requested. */
331 # define YYFPRINTF std::fprintf
332 # define YYDPRINTF(Args) \
338 # define YYDPRINTF(Args)
339 #endif /* !YYDEBUG */
342 yy::b4_name::parse ()
347 /* Initialize stack. */
348 state_stack_
= StateStack (0);
349 semantic_stack_
= SemanticStack (1);
350 location_stack_
= LocationStack (1);
356 location
= initlocation_
;
358 YYDPRINTF ((stderr
, "Starting parse\n"));
362 state_stack_
.push (state_
);
363 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
369 /* Try to take a decision without lookahead. */
370 n_
= pact_
[[state_]];
374 /* Read a lookahead token. */
375 if (looka_
== empty_
)
377 YYDPRINTF ((stderr
, "Reading a token: "));
381 /* Convert token to internal form. */
386 YYDPRINTF ((stderr
, "Now at end of input.\n"));
390 ilooka_
= translate_ (looka_
);
394 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
396 YYFPRINTF (stderr
, ")\n");
402 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
405 /* Reduce or error. */
424 /* Shift the lookahead token. */
425 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
427 /* Discard the token being shifted unless it is eof. */
431 semantic_stack_
.push (value
);
432 location_stack_
.push (location
);
434 /* Count tokens shifted since error; after three, turn off error
442 /* Default action. */
444 n_
= defact_
[[state_]];
454 yyval
= semantic_stack_
[[len_
- 1]];
455 yyloc
= location_stack_
[[len_
- 1]];
459 yyval
= semantic_stack_
[[0]];
460 yyloc
= location_stack_
[[0]];
466 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
467 for (b4_uint_type(b4_prhs_max
) i
= prhs_
[[n_]];
469 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
470 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
476 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
477 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
485 /* Line __line__ of __file__. */
486 #line __oline__ "__ofile__"
488 state_stack_
.pop (len_
);
489 semantic_stack_
.pop (len_
);
490 location_stack_
.pop (len_
);
495 YYFPRINTF (stderr
, "state stack now");
496 for (StateStack::ConstIterator i
= state_stack_
.begin ();
497 i
!= state_stack_
.end (); ++i
)
498 YYFPRINTF (stderr
, " %d", *i
);
499 YYFPRINTF (stderr
, "\n");
503 semantic_stack_
.push (yyval
);
504 location_stack_
.push (yyloc
);
506 /* Shift the result of the reduction. */
508 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
509 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
510 state_
= table_
[[state_]];
512 state_
= defgoto_
[[n_
- ntokens_
]];
515 /* Report and recover from errors. This is very incomplete. */
517 /* If not already recovering from an error, report this error. */
523 n_
= pact_
[[state_]];
524 if (n_
> flag_
&& n_
< last_
)
526 message
= "parse error, unexpected ";
527 message
+= name_
[[ilooka_]];
530 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
531 if (check_
[[x
+ n_
]] == x
)
536 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
537 if (check_
[[x
+ n_
]] == x
)
539 message
+= (!count
++) ? ", expecting " : " or ";
540 message
+= name_
[[x]];
547 message
= "parse error";
552 /* Error raised explicitly by an action. */
556 /* If just tried and failed to reuse lookahead token after an
557 error, discard it. */
559 /* Return failure if at end of input. */
562 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
566 /* Else will try to reuse lookahead token after shifting the error
572 /* Pop the current state because it cannot handle the error token. */
575 if (!state_stack_
.height ())
577 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
578 semantic_stack_
.pop ();
579 location_stack_
.pop ();;
584 YYFPRINTF (stderr
, "Error: state stack now");
585 for (StateStack::ConstIterator i
= state_stack_
.begin ();
586 i
!= state_stack_
.end (); ++i
)
587 YYFPRINTF (stderr
, " %d", *i
);
588 YYFPRINTF (stderr
, "\n");
593 n_
= pact_
[[state_]];
598 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
615 YYDPRINTF ((stderr
, "Shifting error token, "));
617 semantic_stack_
.push (value
);
618 location_stack_
.push (location
);
636 looka_
= yylex (&value
, &location
);
638 looka_
= yylex (&value
);
642 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
645 yy::b4_name::pact_
[[]] =
650 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
651 doesn't specify something else to do. Zero means the default is an
654 yy::b4_name::defact_
[[]] =
659 /* YYPGOTO[[NTERM-NUM]]. */
661 yy::b4_name::pgoto_
[[]] =
666 /* YYDEFGOTO[[NTERM-NUM]]. */
668 yy::b4_name::defgoto_
[[]] =
673 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
674 positive, shift that token. If negative, reduce the rule which
675 number is the opposite. If zero, do what YYDEFACT says. */
677 yy::b4_name::table_
[[]] =
684 yy::b4_name::check_
[[]] =
689 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
690 const b4_uint_type(b4_r1_max
)
691 yy::b4_name::r1_
[[]] =
696 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
697 const b4_uint_type(b4_r2_max
)
698 yy::b4_name::r2_
[[]] =
703 #if YYDEBUG || YYERROR_VERBOSE
704 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
705 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
707 const yy::b4_name::name_
[[]] =
714 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
715 const yy::b4_name::RhsNumberType
716 yy::b4_name::rhs_
[[]] =
721 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
723 const b4_uint_type(b4_prhs_max
)
724 yy::b4_name::prhs_
[[]] =
729 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
730 const b4_uint_type(b4_rline_max
)
731 yy::b4_name::rline_
[[]] =
737 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
738 yy::b4_name::TokenNumberType
739 yy::b4_name::translate_ (int token
)
742 const TokenNumberType
747 if ((unsigned) token
<= user_token_number_max_
)
748 return translate_
[[token]];
753 const int yy::b4_name::eof_
= 0;
754 const int yy::b4_name::last_
= b4_last
;
755 const int yy::b4_name::flag_
= b4_flag
;
756 const int yy::b4_name::nnts_
= b4_nnts
;
757 const int yy::b4_name::nsym_
= b4_nsym
;
758 const int yy::b4_name::empty_
= -2;
759 const int yy::b4_name::final_
= b4_final
;
760 const int yy::b4_name::terror_
= 1;
761 const int yy::b4_name::errcode_
= 256;
762 const int yy::b4_name::ntokens_
= b4_ntokens
;
763 const int yy::b4_name::initdepth_
= b4_initdepth
;
765 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
766 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
773 #ifndef BISON_STACK_HH
774 # define BISON_STACK_HH
780 template < class T
, class S
= std::deque
< T
> >
785 typedef typename
S::iterator Iterator
;
786 typedef typename
S::const_iterator ConstIterator
;
792 Stack (unsigned n
) : seq_ (n
)
798 operator [[]] (unsigned index
)
800 return seq_
[[index]];
805 operator [[]] (unsigned index
) const
807 return seq_
[[index]];
832 inline ConstIterator
begin () const { return seq_
.begin (); }
833 inline ConstIterator
end () const { return seq_
.end (); }
840 template < class T
, class S
= Stack
< T
> >
845 Slice (const S
& stack
,
846 unsigned range
) : stack_ (stack
),
853 operator [[]] (unsigned index
) const
855 return stack_
[[range_
- index
]];
865 #endif // not BISON_STACK_HH
867 #output "location.hh"
870 #ifndef BISON_LOCATION_HH
871 # define BISON_LOCATION_HH
888 #endif // not BISON_LOCATION_HH