1 #output "b4_output_prefix[]b4_output_infix[].hh"
4 /* A Bison parser, made from %%filename,
5 by GNU bison %%version. */
7 /* Skeleton output parser for bison,
8 Copyright (C) 2002 Free Software Foundation, Inc.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* As a special exception, when this file is copied by Bison into a
26 Bison output file, you may use that output file without restriction.
27 This special exception was added by the Free Software Foundation
28 in version 1.24 of Bison. */
31 /* #include "parser.hh" */
32 #include "location.hh"
38 template < typename P
>
44 struct Traits
< b4_name
>
46 typedef int StateType
;
47 typedef b4_stype SemanticType
;
48 typedef Location LocationType
;
60 typedef Traits
< b4_name
>::StateType StateType
;
61 typedef Traits
< b4_name
>::SemanticType SemanticType
;
62 typedef Traits
< b4_name
>::LocationType LocationType
;
64 typedef Stack
< StateType
> StateStack
;
65 typedef Stack
< SemanticType
> SemanticStack
;
66 typedef Stack
< LocationType
> LocationStack
;
68 b4_name () : debug (1)
77 /* Call to lexical analyser. */
82 looka
= yylex (&value
);
86 StateStack state_stack
;
87 SemanticStack semantic_stack
;
88 LocationStack location_stack
;
91 static const short pact_
[[]];
92 static const short defact_
[[]];
93 static const short pgoto_
[[]];
94 static const short defgoto_
[[]];
95 static const short table_
[[]];
96 static const short check_
[[]];
97 static const short line_
[[]];
98 static const short r1_
[[]];
99 static const short r2_
[[]];
100 static const char* const name_
[[]];
102 /* More tables, for debugging. */
103 /* FIXME: These tables should not be printed when not in debug
105 static const short rhs_
[[]];
106 static const short prhs_
[[]];
107 static const short rline_
[[]];
109 /* Even more tables. */
110 static inline char translate (int token
);
113 static const int eof
;
114 static const int empty
;
128 LocationType location
;
132 #output "b4_output_prefix[]b4_output_infix[].cc"
133 #include "b4_output_prefix[]b4_output_infix.hh"
135 /* Enable debugging if requested. */
139 # define YYFPRINTF std::fprintf
141 # define YYDPRINTF(Args) \
146 /* Nonzero means print parse trace. Since this is uninitialized, it
147 does not stop multiple parsers from coexisting. */
150 # define YYDPRINTF(Args)
151 #endif /* !YYDEBUG */
157 yy::b4_name::parse ()
159 /* Initialize stack. */
160 state_stack
= StateStack (0);
161 semantic_stack
= SemanticStack (1);
162 location_stack
= LocationStack (1);
164 /* Reserve initial space. The C parser needed that, but is it really
166 state_stack
.reserve (b4_initdepth
);
167 semantic_stack
.reserve (b4_initdepth
);
168 location_stack
.reserve (b4_initdepth
);
172 YYDPRINTF ((stderr
, "Starting parse\n"));
176 state_stack
.push (state
);
177 YYDPRINTF ((stderr
, "Entering state %d\n", state
));
182 /* Try to take a decision without lookahead. */
187 /* Read a lookahead token. */
190 YYDPRINTF ((stderr
, "Reading a token: "));
194 /* Convert token to internal form. */
199 YYDPRINTF ((stderr
, "Now at end of input.\n"));
203 ilooka
= translate (looka
);
205 YYFPRINTF (stderr
, "Next token is %d (%s", looka
, name_
[[ilooka]]);
206 YYFPRINTF (stderr
, ")\n");
211 if (n
< 0 || n
> b4_last
|| check_
[[n]] != ilooka
)
214 /* Reduce or error. */
233 /* Shift the lookahead token. */
234 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka
, name_
[[ilooka]]));
236 /* Discard the token being shifted unless it is eof. */
240 semantic_stack
.push (value
);
241 location_stack
.push (location
);
245 /* Default action. */
247 n
= defact_
[[state]];
254 value
= semantic_stack
[[1 - len
]];
255 location
= location_stack
[[1 - len
]];
260 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n
- 1, rline_
[[n]]);
261 for (unsigned i
= prhs_
[[n]];
263 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
264 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n
]]]);
269 SemanticType
& yyval (value
);
270 SemanticStack
& yyvsp (semantic_stack
);
278 state_stack
.pop (len
);
279 semantic_stack
.pop (len
);
280 location_stack
.pop (len
);
285 YYFPRINTF (stderr
, "state stack now");
286 for (StateStack::ConstIterator i
= state_stack
.begin ();
287 i
!= state_stack
.end (); ++i
)
288 YYFPRINTF (stderr
, " %d", *i
);
289 YYFPRINTF (stderr
, "\n");
293 semantic_stack
.push (value
);
294 location_stack
.push (location
);
296 /* Shift the result of the reduction. */
298 state
= pgoto_
[[n
- b4_ntokens
]] + state_stack
[[0]];
299 if (state
>= 0 && state
<= b4_last
&& check_
[[state]] == state_stack
[[0]])
300 state
= table_
[[state]];
302 state
= defgoto_
[[n
- b4_ntokens
]];
305 /* Report and recover from errors. This is very incomplete. */
307 // FIXME: Need something like yyerror?
308 std::cerr
<< "Parse error." << std::endl
;
316 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
319 yy::b4_name::pact_
[[]] =
324 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
325 doesn't specify something else to do. Zero means the default is an
328 yy::b4_name::defact_
[[]] =
333 /* YYPGOTO[[NTERM-NUM]]. */
335 yy::b4_name::pgoto_
[[]] =
340 /* YYDEFGOTO[[NTERM-NUM]]. */
342 yy::b4_name::defgoto_
[[]] =
347 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
348 positive, shift that token. If negative, reduce the rule which
349 number is the opposite. If zero, do what YYDEFACT says. */
351 yy::b4_name::table_
[[]] =
358 yy::b4_name::check_
[[]] =
363 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
365 yy::b4_name::line_
[[]] =
370 /*YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
372 yy::b4_name::r1_
[[]] =
377 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
379 yy::b4_name::r2_
[[]] =
384 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
385 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
387 const yy::b4_name::name_
[[]] =
392 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
394 yy::b4_name::rhs_
[[]] =
399 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
402 yy::b4_name::prhs_
[[]] =
407 /* YYRLINE[[YYN]] -- Source line where rule number YYN was defined. */
409 yy::b4_name::rline_
[[]] =
414 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
416 yy::b4_name::translate (int token
)
424 return ((unsigned)(token
) <= b4_maxtok
? translate_
[[token]] : b4_nsym
);
427 const int yy::b4_name::eof
= 0;
428 const int yy::b4_name::empty
= -2;
433 #ifndef BISON_STACK_HH
434 # define BISON_STACK_HH
440 template < class T
, class S
= std::vector
< T
> >
445 typedef typename
S::iterator Iterator
;
446 typedef typename
S::const_iterator ConstIterator
;
452 Stack (unsigned n
) : seq_ (n
)
458 operator [[]] (int index
)
460 return seq_
[[seq_
.size () - 1 + index
]];
465 operator [[]] (int index
) const
467 return seq_
[[seq_
.size () - 1 + index
]];
492 inline ConstIterator
begin () const { return seq_
.begin (); }
493 inline ConstIterator
end () const { return seq_
.end (); }
501 #endif // not BISON_STACK_HH
503 #output "location.hh"
504 #ifndef BISON_LOCATION_HH
505 # define BISON_LOCATION_HH
522 #endif // not BISON_LOCATION_HH