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"
142 /* Using locations. */
143 #define YYLSP_NEEDED b4_locations_flag
145 /* Copy the first part of user declarations. */
149 b4_token_defines(b4_tokens
)
151 /* Enabling traces. */
153 # define YYDEBUG b4_debug
156 /* Enabling verbose error message. */
157 #ifndef YYERROR_VERBOSE
158 # define YYERROR_VERBOSE b4_error_verbose
162 m4_ifdef([b4_stype_line
],
163 [#line b4_stype_line "b4_filename"
167 # define YYSTYPE yystype
170 /* Copy the second part of user declarations. */
173 #line __oline__ "__ofile__"
174 #ifndef YYLLOC_DEFAULT
175 # define YYLLOC_DEFAULT(Current, Rhs, N) \
176 Current.last_line = Rhs[[N]].last_line; \
177 Current.last_column = Rhs[[N]].last_column;
180 m4_if(b4_locations_flag
, [0], [],
182 typedef struct yyltype
189 # define YYLTYPE yyltype
196 template < typename P
>
202 struct Traits
< b4_name
>
204 typedef b4_uint_type(b4_translate_max
) TokenNumberType
;
205 typedef b4_sint_type(b4_rhs_max
) RhsNumberType
;
206 typedef int StateType
;
207 typedef yystype SemanticType
;
208 typedef b4_ltype LocationType
;
214 class b4_name b4_inherit
218 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
219 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
220 typedef Traits
< b4_name
>::StateType StateType
;
221 typedef Traits
< b4_name
>::SemanticType SemanticType
;
222 typedef Traits
< b4_name
>::LocationType LocationType
;
224 typedef Stack
< StateType
> StateStack
;
225 typedef Stack
< SemanticType
> SemanticStack
;
226 typedef Stack
< LocationType
> LocationStack
;
230 LocationType initlocation
[]b4_param
) :
231 b4_constructor
[]debug_ (debug
),
233 initlocation_ (initlocation
)
235 b4_name (bool debug
[]b4_param
) :
236 b4_constructor
[]debug_ (debug
),
246 virtual int parse ();
250 virtual void lex_ ();
251 virtual void error_ ();
252 virtual void print_ ();
255 StateStack state_stack_
;
256 SemanticStack semantic_stack_
;
257 LocationStack location_stack_
;
260 static const short pact_
[[]];
261 static const short defact_
[[]];
262 static const short pgoto_
[[]];
263 static const short defgoto_
[[]];
264 static const short table_
[[]];
265 static const short check_
[[]];
266 static const b4_uint_type(b4_r1_max
) r1_
[[]];
267 static const b4_uint_type(b4_r2_max
) r2_
[[]];
269 #if YYDEBUG || YYERROR_VERBOSE
270 static const char* const name_
[[]];
273 /* More tables, for debugging. */
275 static const RhsNumberType rhs_
[[]];
276 static const b4_uint_type(b4_prhs_max
) prhs_
[[]];
277 static const b4_uint_type(b4_rline_max
) rline_
[[]];
278 static const b4_uint_type(b4_stos_max
) stos_
[[]];
279 static const short token_number_
[[]];
282 /* Even more tables. */
283 static inline TokenNumberType
translate_ (int token
);
286 static const int eof_
;
287 static const int last_
;
288 static const int flag_
;
289 static const int nnts_
;
290 static const int nsym_
;
291 static const int empty_
;
292 static const int final_
;
293 static const int terror_
;
294 static const int errcode_
;
295 static const int ntokens_
;
296 static const int initdepth_
;
297 static const unsigned user_token_number_max_
;
298 static const TokenNumberType undef_token_
;
307 std::ostream
&cdebug_
;
309 /* Lookahead and lookahead in internal form. */
316 /* Semantic value and location of lookahead token. */
318 LocationType location
;
324 /* Initial location. */
325 LocationType initlocation_
;
329 #endif /* not b4_header_guard */
331 #output "b4_output_prefix[]b4_output_infix[].cc"
334 #include "b4_output_header_name"
336 /* Enable debugging if requested. */
338 # define YYCDEBUG if (debug_) cdebug_
340 # define YYCDEBUG if (0) cdebug_
341 #endif /* !YYDEBUG */
344 yy::b4_name::parse ()
349 /* Initialize stack. */
350 state_stack_
= StateStack (0);
351 semantic_stack_
= SemanticStack (1);
352 location_stack_
= LocationStack (1);
358 location
= initlocation_
;
360 YYCDEBUG
<< "Starting parse" << std::endl
;
364 state_stack_
.push (state_
);
365 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
371 /* Try to take a decision without lookahead. */
372 n_
= pact_
[[state_]];
376 /* Read a lookahead token. */
377 if (looka_
== empty_
)
379 YYCDEBUG
<< "Reading a token: ";
383 /* Convert token to internal form. */
388 YYCDEBUG
<< "Now at end of input." << std::endl
;
392 ilooka_
= translate_ (looka_
);
396 YYCDEBUG
<< "Next token is " << looka_
397 << " (" << name_
[[ilooka_]];
399 YYCDEBUG
<< ')' << std::endl
;
405 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
408 /* Reduce or error. */
427 /* Shift the lookahead token. */
428 YYCDEBUG
<< "Shifting token " << looka_
429 << " (" << name_
[[ilooka_]] << "), ";
431 /* Discard the token being shifted unless it is eof. */
435 semantic_stack_
.push (value
);
436 location_stack_
.push (location
);
438 /* Count tokens shifted since error; after three, turn off error
446 /* Default action. */
448 n_
= defact_
[[state_]];
458 yyval
= semantic_stack_
[[len_
- 1]];
459 yyloc
= location_stack_
[[len_
- 1]];
463 yyval
= semantic_stack_
[[0]];
464 yyloc
= location_stack_
[[0]];
470 YYCDEBUG
<< "Reducing via rule " << n_
- 1
471 << " (line " << rline_
[[n_]] << "), ";
472 for (b4_uint_type(b4_prhs_max
) i
= prhs_
[[n_]];
474 YYCDEBUG
<< name_
[[rhs_
[i
]]] << ' ';
475 YYCDEBUG
<< "-> " << name_
[[r1_
[n_
]]] << std::endl
;
481 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
482 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
490 /* Line __line__ of __file__. */
491 #line __oline__ "__ofile__"
493 state_stack_
.pop (len_
);
494 semantic_stack_
.pop (len_
);
495 location_stack_
.pop (len_
);
500 YYCDEBUG
<< "state stack now";
501 for (StateStack::ConstIterator i
= state_stack_
.begin ();
502 i
!= state_stack_
.end (); ++i
)
503 YYCDEBUG
<< ' ' << *i
;
504 YYCDEBUG
<< std::endl
;
508 semantic_stack_
.push (yyval
);
509 location_stack_
.push (yyloc
);
511 /* Shift the result of the reduction. */
513 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
514 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
515 state_
= table_
[[state_]];
517 state_
= defgoto_
[[n_
- ntokens_
]];
520 /* Report and recover from errors. This is very incomplete. */
522 /* If not already recovering from an error, report this error. */
528 n_
= pact_
[[state_]];
529 if (n_
> flag_
&& n_
< last_
)
531 message
= "parse error, unexpected ";
532 message
+= name_
[[ilooka_]];
535 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
536 if (check_
[[x
+ n_
]] == x
)
541 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
542 if (check_
[[x
+ n_
]] == x
)
544 message
+= (!count
++) ? ", expecting " : " or ";
545 message
+= name_
[[x]];
552 message
= "parse error";
557 /* Error raised explicitly by an action. */
561 /* If just tried and failed to reuse lookahead token after an
562 error, discard it. */
564 /* Return failure if at end of input. */
567 YYCDEBUG
<< "Discarding token " << looka_
568 << " (" << name_
[[ilooka_]] << ")." << std::endl
;
572 /* Else will try to reuse lookahead token after shifting the error
579 n_
= pact_
[[state_]];
583 if (0 <= n_
&& n_
<= last_
&& check_
[[n_]] == terror_
)
591 /* Pop the current state because it cannot handle the error token. */
592 if (!state_stack_
.height ())
598 if (stos_
[[state_]] < ntokens_
)
600 YYCDEBUG
<< "Error: popping token "
601 << token_number_
[[stos_
[state_
]]]
602 << " (" << name_
[[stos_
[state_
]]];
604 YYPRINT (stderr
, token_number_
[[stos_
[state_
]]],
605 semantic_stack_
.top ());
607 YYCDEBUG
<< ')' << std::endl
;
611 YYCDEBUG
<< "Error: popping nonterminal ("
612 << name_
[[stos_
[state_
]]] << ')' << std::endl
;
617 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
618 semantic_stack_
.pop ();
619 location_stack_
.pop ();;
624 YYCDEBUG
<< "Error: state stack now";
625 for (StateStack::ConstIterator i
= state_stack_
.begin ();
626 i
!= state_stack_
.end (); ++i
)
627 YYCDEBUG
<< ' ' << *i
;
628 YYCDEBUG
<< std::endl
;
636 YYCDEBUG
<< "Shifting error token, ";
638 semantic_stack_
.push (value
);
639 location_stack_
.push (location
);
657 looka_
= yylex (&value
, &location
);
659 looka_
= yylex (&value
);
663 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
666 yy::b4_name::pact_
[[]] =
671 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
672 doesn't specify something else to do. Zero means the default is an
675 yy::b4_name::defact_
[[]] =
680 /* YYPGOTO[[NTERM-NUM]]. */
682 yy::b4_name::pgoto_
[[]] =
687 /* YYDEFGOTO[[NTERM-NUM]]. */
689 yy::b4_name::defgoto_
[[]] =
694 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
695 positive, shift that token. If negative, reduce the rule which
696 number is the opposite. If zero, do what YYDEFACT says. */
698 yy::b4_name::table_
[[]] =
705 yy::b4_name::check_
[[]] =
711 /* STOS_[[STATE-NUM]] -- The (internal number of the) accessing
712 symbol of state STATE-NUM. */
713 const b4_uint_type(b4_stos_max
)
714 yy::b4_name::stos_
[[]] =
719 /* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding
722 yy::b4_name::token_number_
[[]] =
728 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
729 const b4_uint_type(b4_r1_max
)
730 yy::b4_name::r1_
[[]] =
735 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
736 const b4_uint_type(b4_r2_max
)
737 yy::b4_name::r2_
[[]] =
742 #if YYDEBUG || YYERROR_VERBOSE
743 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
744 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
746 const yy::b4_name::name_
[[]] =
753 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
754 const yy::b4_name::RhsNumberType
755 yy::b4_name::rhs_
[[]] =
760 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
762 const b4_uint_type(b4_prhs_max
)
763 yy::b4_name::prhs_
[[]] =
768 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
769 const b4_uint_type(b4_rline_max
)
770 yy::b4_name::rline_
[[]] =
776 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
777 yy::b4_name::TokenNumberType
778 yy::b4_name::translate_ (int token
)
781 const TokenNumberType
786 if ((unsigned) token
<= user_token_number_max_
)
787 return translate_
[[token]];
792 const int yy::b4_name::eof_
= 0;
793 const int yy::b4_name::last_
= b4_last
;
794 const int yy::b4_name::flag_
= b4_flag
;
795 const int yy::b4_name::nnts_
= b4_nnts
;
796 const int yy::b4_name::nsym_
= b4_nsym
;
797 const int yy::b4_name::empty_
= -2;
798 const int yy::b4_name::final_
= b4_final
;
799 const int yy::b4_name::terror_
= 1;
800 const int yy::b4_name::errcode_
= 256;
801 const int yy::b4_name::ntokens_
= b4_ntokens
;
802 const int yy::b4_name::initdepth_
= b4_initdepth
;
804 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
805 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
812 #ifndef BISON_STACK_HH
813 # define BISON_STACK_HH
819 template < class T
, class S
= std::deque
< T
> >
824 typedef typename
S::iterator Iterator
;
825 typedef typename
S::const_iterator ConstIterator
;
831 Stack (unsigned n
) : seq_ (n
)
837 operator [[]] (unsigned index
)
839 return seq_
[[index]];
844 operator [[]] (unsigned index
) const
846 return seq_
[[index]];
871 inline ConstIterator
begin () const { return seq_
.begin (); }
872 inline ConstIterator
end () const { return seq_
.end (); }
879 template < class T
, class S
= Stack
< T
> >
884 Slice (const S
& stack
,
885 unsigned range
) : stack_ (stack
),
892 operator [[]] (unsigned index
) const
894 return stack_
[[range_
- index
]];
904 #endif // not BISON_STACK_HH
906 #output "location.hh"
909 #ifndef BISON_LOCATION_HH
910 # define BISON_LOCATION_HH
927 #endif // not BISON_LOCATION_HH