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. */
148 /* Line __line__ of __file__. */
149 #line __oline__ "__ofile__"
152 b4_token_defines(b4_tokens
)
154 /* Enabling traces. */
156 # define YYDEBUG b4_debug
159 /* Enabling verbose error message. */
160 #ifndef YYERROR_VERBOSE
161 # define YYERROR_VERBOSE b4_error_verbose
166 [#line b4_stype_line "b4_filename"
167 typedef union b4_stype yystype
;
168 /* Line __line__ of __file__. */
169 #line __oline__ "__ofile__"],
170 [typedef int yystype
;])
171 # define YYSTYPE yystype
174 /* Copy the second part of user declarations. */
177 /* Line __line__ of __file__. */
178 #line __oline__ "__ofile__"
179 #ifndef YYLLOC_DEFAULT
180 # define YYLLOC_DEFAULT(Current, Rhs, N) \
181 Current.last_line = Rhs[[N]].last_line; \
182 Current.last_column = Rhs[[N]].last_column;
185 m4_if(b4_locations_flag
, [0], [],
187 typedef struct yyltype
194 # define YYLTYPE yyltype
201 template < typename P
>
207 struct Traits
< b4_name
>
209 typedef b4_uint_type(b4_translate_max
) TokenNumberType
;
210 typedef b4_sint_type(b4_rhs_max
) RhsNumberType
;
211 typedef int StateType
;
212 typedef yystype SemanticType
;
213 typedef b4_ltype LocationType
;
219 class b4_name b4_inherit
223 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
224 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
225 typedef Traits
< b4_name
>::StateType StateType
;
226 typedef Traits
< b4_name
>::SemanticType SemanticType
;
227 typedef Traits
< b4_name
>::LocationType LocationType
;
229 typedef Stack
< StateType
> StateStack
;
230 typedef Stack
< SemanticType
> SemanticStack
;
231 typedef Stack
< LocationType
> LocationStack
;
235 LocationType initlocation
[]b4_param
) :
236 b4_constructor
[]debug_ (debug
),
238 initlocation_ (initlocation
)
240 b4_name (bool debug
[]b4_param
) :
241 b4_constructor
[]debug_ (debug
),
251 virtual int parse ();
255 virtual void lex_ ();
256 virtual void error_ ();
257 virtual void print_ ();
260 StateStack state_stack_
;
261 SemanticStack semantic_stack_
;
262 LocationStack location_stack_
;
265 static const short pact_
[[]];
266 static const short defact_
[[]];
267 static const short pgoto_
[[]];
268 static const short defgoto_
[[]];
269 static const short table_
[[]];
270 static const short check_
[[]];
271 static const b4_uint_type(b4_r1_max
) r1_
[[]];
272 static const b4_uint_type(b4_r2_max
) r2_
[[]];
274 #if YYDEBUG || YYERROR_VERBOSE
275 static const char* const name_
[[]];
278 /* More tables, for debugging. */
280 static const RhsNumberType rhs_
[[]];
281 static const b4_uint_type(b4_prhs_max
) prhs_
[[]];
282 static const b4_uint_type(b4_rline_max
) rline_
[[]];
283 static const b4_uint_type(b4_stos_max
) stos_
[[]];
284 static const short token_number_
[[]];
287 /* Even more tables. */
288 static inline TokenNumberType
translate_ (int token
);
291 static const int eof_
;
292 static const int last_
;
293 static const int flag_
;
294 static const int nnts_
;
295 static const int nsym_
;
296 static const int empty_
;
297 static const int final_
;
298 static const int terror_
;
299 static const int errcode_
;
300 static const int ntokens_
;
301 static const int initdepth_
;
302 static const unsigned user_token_number_max_
;
303 static const TokenNumberType undef_token_
;
312 std::ostream
&cdebug_
;
314 /* Lookahead and lookahead in internal form. */
321 /* Semantic value and location of lookahead token. */
323 LocationType location
;
329 /* Initial location. */
330 LocationType initlocation_
;
334 #endif /* not b4_header_guard */
336 #output "b4_output_prefix[]b4_output_infix[].cc"
339 #include "b4_output_header_name"
341 /* Enable debugging if requested. */
343 # define YYCDEBUG if (debug_) cdebug_
345 # define YYCDEBUG if (0) cdebug_
346 #endif /* !YYDEBUG */
349 yy::b4_name::parse ()
354 /* Initialize stack. */
355 state_stack_
= StateStack (0);
356 semantic_stack_
= SemanticStack (1);
357 location_stack_
= LocationStack (1);
363 location
= initlocation_
;
365 YYCDEBUG
<< "Starting parse" << std::endl
;
369 state_stack_
.push (state_
);
370 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
376 /* Try to take a decision without lookahead. */
377 n_
= pact_
[[state_]];
381 /* Read a lookahead token. */
382 if (looka_
== empty_
)
384 YYCDEBUG
<< "Reading a token: ";
388 /* Convert token to internal form. */
393 YYCDEBUG
<< "Now at end of input." << std::endl
;
397 ilooka_
= translate_ (looka_
);
401 YYCDEBUG
<< "Next token is " << looka_
402 << " (" << name_
[[ilooka_]];
404 YYCDEBUG
<< ')' << std::endl
;
410 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
413 /* Reduce or error. */
432 /* Shift the lookahead token. */
433 YYCDEBUG
<< "Shifting token " << looka_
434 << " (" << name_
[[ilooka_]] << "), ";
436 /* Discard the token being shifted unless it is eof. */
440 semantic_stack_
.push (value
);
441 location_stack_
.push (location
);
443 /* Count tokens shifted since error; after three, turn off error
451 /* Default action. */
453 n_
= defact_
[[state_]];
463 yyval
= semantic_stack_
[[len_
- 1]];
464 yyloc
= location_stack_
[[len_
- 1]];
468 yyval
= semantic_stack_
[[0]];
469 yyloc
= location_stack_
[[0]];
475 YYCDEBUG
<< "Reducing via rule " << n_
- 1
476 << " (line " << rline_
[[n_]] << "), ";
477 for (b4_uint_type(b4_prhs_max
) i
= prhs_
[[n_]];
479 YYCDEBUG
<< name_
[[rhs_
[i
]]] << ' ';
480 YYCDEBUG
<< "-> " << name_
[[r1_
[n_
]]] << std::endl
;
486 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
487 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
495 /* Line __line__ of __file__. */
496 #line __oline__ "__ofile__"
498 state_stack_
.pop (len_
);
499 semantic_stack_
.pop (len_
);
500 location_stack_
.pop (len_
);
505 YYCDEBUG
<< "state stack now";
506 for (StateStack::ConstIterator i
= state_stack_
.begin ();
507 i
!= state_stack_
.end (); ++i
)
508 YYCDEBUG
<< ' ' << *i
;
509 YYCDEBUG
<< std::endl
;
513 semantic_stack_
.push (yyval
);
514 location_stack_
.push (yyloc
);
516 /* Shift the result of the reduction. */
518 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
519 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
520 state_
= table_
[[state_]];
522 state_
= defgoto_
[[n_
- ntokens_
]];
525 /* Report and recover from errors. This is very incomplete. */
527 /* If not already recovering from an error, report this error. */
533 n_
= pact_
[[state_]];
534 if (n_
> flag_
&& n_
< last_
)
536 message
= "parse error, unexpected ";
537 message
+= name_
[[ilooka_]];
540 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
541 if (check_
[[x
+ n_
]] == x
)
546 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
547 if (check_
[[x
+ n_
]] == x
)
549 message
+= (!count
++) ? ", expecting " : " or ";
550 message
+= name_
[[x]];
557 message
= "parse error";
562 /* Error raised explicitly by an action. */
566 /* If just tried and failed to reuse lookahead token after an
567 error, discard it. */
569 /* Return failure if at end of input. */
572 YYCDEBUG
<< "Discarding token " << looka_
573 << " (" << name_
[[ilooka_]] << ")." << std::endl
;
577 /* Else will try to reuse lookahead token after shifting the error
584 n_
= pact_
[[state_]];
588 if (0 <= n_
&& n_
<= last_
&& check_
[[n_]] == terror_
)
596 /* Pop the current state because it cannot handle the error token. */
597 if (!state_stack_
.height ())
603 if (stos_
[[state_]] < ntokens_
)
605 YYCDEBUG
<< "Error: popping token "
606 << token_number_
[[stos_
[state_
]]]
607 << " (" << name_
[[stos_
[state_
]]];
609 YYPRINT (stderr
, token_number_
[[stos_
[state_
]]],
610 semantic_stack_
.top ());
612 YYCDEBUG
<< ')' << std::endl
;
616 YYCDEBUG
<< "Error: popping nonterminal ("
617 << name_
[[stos_
[state_
]]] << ')' << std::endl
;
622 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
623 semantic_stack_
.pop ();
624 location_stack_
.pop ();;
629 YYCDEBUG
<< "Error: state stack now";
630 for (StateStack::ConstIterator i
= state_stack_
.begin ();
631 i
!= state_stack_
.end (); ++i
)
632 YYCDEBUG
<< ' ' << *i
;
633 YYCDEBUG
<< std::endl
;
641 YYCDEBUG
<< "Shifting error token, ";
643 semantic_stack_
.push (value
);
644 location_stack_
.push (location
);
662 looka_
= yylex (&value
, &location
);
664 looka_
= yylex (&value
);
668 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
671 yy::b4_name::pact_
[[]] =
676 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
677 doesn't specify something else to do. Zero means the default is an
680 yy::b4_name::defact_
[[]] =
685 /* YYPGOTO[[NTERM-NUM]]. */
687 yy::b4_name::pgoto_
[[]] =
692 /* YYDEFGOTO[[NTERM-NUM]]. */
694 yy::b4_name::defgoto_
[[]] =
699 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
700 positive, shift that token. If negative, reduce the rule which
701 number is the opposite. If zero, do what YYDEFACT says. */
703 yy::b4_name::table_
[[]] =
710 yy::b4_name::check_
[[]] =
716 /* STOS_[[STATE-NUM]] -- The (internal number of the) accessing
717 symbol of state STATE-NUM. */
718 const b4_uint_type(b4_stos_max
)
719 yy::b4_name::stos_
[[]] =
724 /* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding
727 yy::b4_name::token_number_
[[]] =
733 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
734 const b4_uint_type(b4_r1_max
)
735 yy::b4_name::r1_
[[]] =
740 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
741 const b4_uint_type(b4_r2_max
)
742 yy::b4_name::r2_
[[]] =
747 #if YYDEBUG || YYERROR_VERBOSE
748 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
749 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
751 const yy::b4_name::name_
[[]] =
758 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
759 const yy::b4_name::RhsNumberType
760 yy::b4_name::rhs_
[[]] =
765 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
767 const b4_uint_type(b4_prhs_max
)
768 yy::b4_name::prhs_
[[]] =
773 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
774 const b4_uint_type(b4_rline_max
)
775 yy::b4_name::rline_
[[]] =
781 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
782 yy::b4_name::TokenNumberType
783 yy::b4_name::translate_ (int token
)
786 const TokenNumberType
791 if ((unsigned) token
<= user_token_number_max_
)
792 return translate_
[[token]];
797 const int yy::b4_name::eof_
= 0;
798 const int yy::b4_name::last_
= b4_last
;
799 const int yy::b4_name::flag_
= b4_flag
;
800 const int yy::b4_name::nnts_
= b4_nnts
;
801 const int yy::b4_name::nsym_
= b4_nsym
;
802 const int yy::b4_name::empty_
= -2;
803 const int yy::b4_name::final_
= b4_final
;
804 const int yy::b4_name::terror_
= 1;
805 const int yy::b4_name::errcode_
= 256;
806 const int yy::b4_name::ntokens_
= b4_ntokens
;
807 const int yy::b4_name::initdepth_
= b4_initdepth
;
809 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
810 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
817 #ifndef BISON_STACK_HH
818 # define BISON_STACK_HH
824 template < class T
, class S
= std::deque
< T
> >
829 typedef typename
S::iterator Iterator
;
830 typedef typename
S::const_iterator ConstIterator
;
836 Stack (unsigned n
) : seq_ (n
)
842 operator [[]] (unsigned index
)
844 return seq_
[[index]];
849 operator [[]] (unsigned index
) const
851 return seq_
[[index]];
876 inline ConstIterator
begin () const { return seq_
.begin (); }
877 inline ConstIterator
end () const { return seq_
.end (); }
884 template < class T
, class S
= Stack
< T
> >
889 Slice (const S
& stack
,
890 unsigned range
) : stack_ (stack
),
897 operator [[]] (unsigned index
) const
899 return stack_
[[range_
- index
]];
909 #endif // not BISON_STACK_HH
911 #output "location.hh"
914 #ifndef BISON_LOCATION_HH
915 # define BISON_LOCATION_HH
932 #endif // not BISON_LOCATION_HH