3 # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
4 # ------------------------------------------
5 # Output the definition of this token as #define.
6 m4_define([b4_token_define
],
11 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
12 # -------------------------------------------------------
13 # Output the definition of the tokens as #define.
14 m4_define([b4_token_defines
],
15 [m4_map([b4_token_define
], [$@
])])
17 m4_define_default([b4_input_suffix
], [.y
])
19 m4_define_default([b4_output_parser_suffix
],
20 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
22 m4_define_default([b4_output_parser_name
],
23 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
26 m4_define_default([b4_output_header_suffix
],
27 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
29 m4_define_default([b4_output_header_name
],
30 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
32 m4_define_default([b4_header_guard
],
33 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
34 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
36 m4_define([b4_inherit
],
48 m4_define([b4_constructor
],
54 m4_define([b4_copyright
],
56 /* A Bison parser, made from b4_filename,
57 by GNU bison b4_version. */
59 /* Skeleton output parser for bison,
60 Copyright 2002 Free Software Foundation, Inc.
62 This program is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2, or (at your option)
67 This program is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
72 You should have received a copy of the GNU General Public License
73 along with this program; if not, write to the Free Software
74 Foundation, Inc., 59 Temple Place - Suite 330,
75 Boston, MA 02111-1307, USA. */
77 /* As a special exception, when this file is copied by Bison into a
78 Bison output file, you may use that output file without restriction.
79 This special exception was added by the Free Software Foundation
80 in version 1.24 of Bison. */])
83 #output "b4_output_header_name"
85 #ifndef b4_header_guard
86 # define b4_header_guard
89 #include "location.hh"
93 /* Using locations. */
94 #define YYLSP_NEEDED b4_locations_flag
99 b4_token_defines(b4_tokens
)
101 /* Enabling traces. */
103 # define YYDEBUG b4_debug
106 /* Enabling verbose error message. */
107 #ifndef YYERROR_VERBOSE
108 # define YYERROR_VERBOSE b4_error_verbose
112 m4_ifdef([b4_stype_line
],
113 [#line b4_stype_line "b4_filename"
117 # define YYSTYPE yystype
120 #ifndef YYLLOC_DEFAULT
121 # define YYLLOC_DEFAULT(Current, Rhs, N) \
122 Current.last_line = Rhs[[N]].last_line; \
123 Current.last_column = Rhs[[N]].last_column;
126 m4_if(b4_locations_flag
, [0], [],
128 typedef struct yyltype
135 # define YYLTYPE yyltype
142 template < typename P
>
148 struct Traits
< b4_name
>
150 typedef int StateType
;
151 typedef yystype SemanticType
;
152 typedef b4_ltype LocationType
;
158 class b4_name b4_inherit
162 typedef Traits
< b4_name
>::StateType StateType
;
163 typedef Traits
< b4_name
>::SemanticType SemanticType
;
164 typedef Traits
< b4_name
>::LocationType LocationType
;
166 typedef Stack
< StateType
> StateStack
;
167 typedef Stack
< SemanticType
> SemanticStack
;
168 typedef Stack
< LocationType
> LocationStack
;
172 LocationType initlocation
[]b4_param
) :
173 b4_constructor
[]debug_ (debug
),
174 initlocation_ (initlocation
)
176 b4_name (bool debug
[]b4_param
) :
177 b4_constructor
[]debug_ (debug
)
186 virtual int parse ();
190 virtual void lex_ ();
191 virtual void error_ ();
192 virtual void print_ ();
195 StateStack state_stack_
;
196 SemanticStack semantic_stack_
;
197 LocationStack location_stack_
;
200 static const short pact_
[[]];
201 static const short defact_
[[]];
202 static const short pgoto_
[[]];
203 static const short defgoto_
[[]];
204 static const short table_
[[]];
205 static const short check_
[[]];
206 static const short r1_
[[]];
207 static const short r2_
[[]];
209 #if YYDEBUG || YYERROR_VERBOSE
210 static const char* const name_
[[]];
213 /* More tables, for debugging. */
215 static const short rhs_
[[]];
216 static const short prhs_
[[]];
217 static const short rline_
[[]];
220 /* Even more tables. */
221 static inline char translate_ (int token
);
224 static const int eof_
;
225 static const int last_
;
226 static const int flag_
;
227 static const int nnts_
;
228 static const int nsym_
;
229 static const int empty_
;
230 static const int final_
;
231 static const int terror_
;
232 static const int errcode_
;
233 static const int ntokens_
;
234 static const int initdepth_
;
235 static const unsigned maxtok_
;
243 /* Lookahead and lookahead in internal form. */
250 /* Semantic value and location of lookahead token. */
252 LocationType location
;
258 /* Initial location. */
259 LocationType initlocation_
;
263 #endif /* not b4_header_guard */
265 #output "b4_output_prefix[]b4_output_infix[].cc"
268 #include "b4_output_header_name"
270 /* Enable debugging if requested. */
273 # define YYFPRINTF std::fprintf
274 # define YYDPRINTF(Args) \
280 # define YYDPRINTF(Args)
281 #endif /* !YYDEBUG */
284 yy::b4_name::parse ()
289 /* Initialize stack. */
290 state_stack_
= StateStack (0);
291 semantic_stack_
= SemanticStack (1);
292 location_stack_
= LocationStack (1);
294 /* Reserve initial space. The C parser needed that, but is it really
296 state_stack_
.reserve (initdepth_
);
297 semantic_stack_
.reserve (initdepth_
);
298 location_stack_
.reserve (initdepth_
);
304 location
= initlocation_
;
306 YYDPRINTF ((stderr
, "Starting parse\n"));
310 state_stack_
.push (state_
);
311 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
317 /* Try to take a decision without lookahead. */
318 n_
= pact_
[[state_]];
322 /* Read a lookahead token. */
323 if (looka_
== empty_
)
325 YYDPRINTF ((stderr
, "Reading a token: "));
329 /* Convert token to internal form. */
334 YYDPRINTF ((stderr
, "Now at end of input.\n"));
338 ilooka_
= translate_ (looka_
);
342 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
344 YYFPRINTF (stderr
, ")\n");
350 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
353 /* Reduce or error. */
372 /* Shift the lookahead token. */
373 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
375 /* Discard the token being shifted unless it is eof. */
379 semantic_stack_
.push (value
);
380 location_stack_
.push (location
);
382 /* Count tokens shifted since error; after three, turn off error
390 /* Default action. */
392 n_
= defact_
[[state_]];
402 yyval
= semantic_stack_
[[1 - len_
]];
403 yyloc
= location_stack_
[[1 - len_
]];
407 yyval
= semantic_stack_
[[0]];
408 yyloc
= location_stack_
[[0]];
414 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
415 for (unsigned i
= prhs_
[[n_]];
417 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
418 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
424 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
425 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
429 SemanticStack
& yyvsp (semantic_stack_
);
430 LocationStack
& yylsp (location_stack_
);
438 state_stack_
.pop (len_
);
439 semantic_stack_
.pop (len_
);
440 location_stack_
.pop (len_
);
445 YYFPRINTF (stderr
, "state stack now");
446 for (StateStack::ConstIterator i
= state_stack_
.begin ();
447 i
!= state_stack_
.end (); ++i
)
448 YYFPRINTF (stderr
, " %d", *i
);
449 YYFPRINTF (stderr
, "\n");
453 semantic_stack_
.push (yyval
);
454 location_stack_
.push (yyloc
);
456 /* Shift the result of the reduction. */
458 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
459 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
460 state_
= table_
[[state_]];
462 state_
= defgoto_
[[n_
- ntokens_
]];
465 /* Report and recover from errors. This is very incomplete. */
467 /* If not already recovering from an error, report this error. */
473 n_
= pact_
[[state_]];
474 if (n_
> flag_
&& n_
< last_
)
476 message
= "parse error, unexpected ";
477 message
+= name_
[[ilooka_]];
480 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
481 if (check_
[[x
+ n_
]] == x
)
486 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
487 if (check_
[[x
+ n_
]] == x
)
489 message
+= (!count
++) ? ", expecting " : " or ";
490 message
+= name_
[[x]];
497 message
= "parse error";
502 /* Error raised explicitly by an action. */
506 /* If just tried and failed to reuse lookahead token after an
507 error, discard it. */
509 /* Return failure if at end of input. */
512 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
516 /* Else will try to reuse lookahead token after shifting the error
522 /* Pop the current state because it cannot handle the error token. */
525 if (!state_stack_
.height ())
527 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
528 semantic_stack_
.pop ();
529 location_stack_
.pop ();;
534 YYFPRINTF (stderr
, "Error: state stack now");
535 for (StateStack::ConstIterator i
= state_stack_
.begin ();
536 i
!= state_stack_
.end (); ++i
)
537 YYFPRINTF (stderr
, " %d", *i
);
538 YYFPRINTF (stderr
, "\n");
543 n_
= pact_
[[state_]];
548 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
565 YYDPRINTF ((stderr
, "Shifting error token, "));
567 semantic_stack_
.push (value
);
568 location_stack_
.push (location
);
586 looka_
= yylex (&value
, &location
);
588 looka_
= yylex (&value
);
592 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
595 yy::b4_name::pact_
[[]] =
600 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
601 doesn't specify something else to do. Zero means the default is an
604 yy::b4_name::defact_
[[]] =
609 /* YYPGOTO[[NTERM-NUM]]. */
611 yy::b4_name::pgoto_
[[]] =
616 /* YYDEFGOTO[[NTERM-NUM]]. */
618 yy::b4_name::defgoto_
[[]] =
623 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
624 positive, shift that token. If negative, reduce the rule which
625 number is the opposite. If zero, do what YYDEFACT says. */
627 yy::b4_name::table_
[[]] =
634 yy::b4_name::check_
[[]] =
639 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
641 yy::b4_name::r1_
[[]] =
646 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
648 yy::b4_name::r2_
[[]] =
653 #if YYDEBUG || YYERROR_VERBOSE
654 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
655 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
657 const yy::b4_name::name_
[[]] =
664 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
666 yy::b4_name::rhs_
[[]] =
671 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
674 yy::b4_name::prhs_
[[]] =
679 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
681 yy::b4_name::rline_
[[]] =
687 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
689 yy::b4_name::translate_ (int token
)
697 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
700 const int yy::b4_name::eof_
= 0;
701 const int yy::b4_name::last_
= b4_last
;
702 const int yy::b4_name::flag_
= b4_flag
;
703 const int yy::b4_name::nnts_
= b4_nnts
;
704 const int yy::b4_name::nsym_
= b4_nsym
;
705 const int yy::b4_name::empty_
= -2;
706 const int yy::b4_name::final_
= b4_final
;
707 const int yy::b4_name::terror_
= 1;
708 const int yy::b4_name::errcode_
= 256;
709 const int yy::b4_name::ntokens_
= b4_ntokens
;
710 const int yy::b4_name::initdepth_
= b4_initdepth
;
712 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
719 #ifndef BISON_STACK_HH
720 # define BISON_STACK_HH
726 template < class T
, class S
= std::vector
< T
> >
731 typedef typename
S::iterator Iterator
;
732 typedef typename
S::const_iterator ConstIterator
;
738 Stack (unsigned n
) : seq_ (n
)
744 operator [[]] (int index
)
746 return seq_
[[height () - 1 + index
]];
751 operator [[]] (int index
) const
753 return seq_
[[height () - 1 + index
]];
785 inline ConstIterator
begin () const { return seq_
.begin (); }
786 inline ConstIterator
end () const { return seq_
.end (); }
793 template < class T
, class S
= Stack
< T
> >
798 Slice (const S
& stack
,
799 unsigned range
) : stack_ (stack
),
806 operator [[]] (unsigned index
) const
808 return stack_
[[index
- range_
]];
818 #endif // not BISON_STACK_HH
820 #output "location.hh"
823 #ifndef BISON_LOCATION_HH
824 # define BISON_LOCATION_HH
841 #endif // not BISON_LOCATION_HH