]>
Commit | Line | Data |
---|---|---|
50997c6e | 1 | #output "b4_output_prefix[]b4_output_infix[]-class.hh" |
2b548aa6 RA |
2 | /* -*- C++ -*- */ |
3 | ||
4 | /* A Bison parser, made from %%filename, | |
5 | by GNU bison %%version. */ | |
6 | ||
7 | /* Skeleton output parser for bison, | |
50997c6e | 8 | Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc. |
2b548aa6 RA |
9 | |
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) | |
13 | any later version. | |
14 | ||
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. | |
19 | ||
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. */ | |
24 | ||
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. */ | |
29 | ||
30 | #include "stack.hh" | |
2b548aa6 RA |
31 | #include "location.hh" |
32 | ||
50997c6e RA |
33 | b4_prologue |
34 | ||
35 | // FIXME: This should be defined in traits, not here. | |
36 | typedef b4_stype yystype; | |
37 | ||
2b548aa6 RA |
38 | namespace yy |
39 | { | |
3f3eed27 AD |
40 | class b4_name; |
41 | ||
2b548aa6 RA |
42 | template < typename P > |
43 | struct Traits | |
44 | { | |
45 | }; | |
46 | ||
47 | template < > | |
3f3eed27 | 48 | struct Traits< b4_name > |
2b548aa6 | 49 | { |
50997c6e RA |
50 | typedef int StateType; |
51 | typedef yystype SemanticType; | |
52 | typedef b4_ltype LocationType; | |
2b548aa6 RA |
53 | }; |
54 | } | |
55 | ||
2b548aa6 RA |
56 | namespace yy |
57 | { | |
3f3eed27 | 58 | class b4_name |
2b548aa6 RA |
59 | { |
60 | public: | |
3f3eed27 | 61 | |
50997c6e | 62 | typedef Traits< b4_name >::StateType StateType; |
3f3eed27 AD |
63 | typedef Traits< b4_name >::SemanticType SemanticType; |
64 | typedef Traits< b4_name >::LocationType LocationType; | |
2b548aa6 RA |
65 | |
66 | typedef Stack< StateType > StateStack; | |
67 | typedef Stack< SemanticType > SemanticStack; | |
68 | typedef Stack< LocationType > LocationStack; | |
69 | ||
50997c6e RA |
70 | b4_name (bool debug) : debug_ (debug) |
71 | { | |
72 | looka = empty_; | |
73 | } | |
74 | ||
75 | virtual ~b4_name () | |
2b548aa6 | 76 | { |
2b548aa6 RA |
77 | } |
78 | ||
79 | virtual int parse (); | |
80 | ||
81 | private: | |
3f3eed27 | 82 | |
2b548aa6 | 83 | /* Call to lexical analyser. */ |
50997c6e RA |
84 | virtual |
85 | void | |
86 | lex () | |
87 | { | |
88 | looka = yylex (&value, &location); | |
2b548aa6 RA |
89 | } |
90 | ||
91 | /* Stacks. */ | |
92 | StateStack state_stack; | |
93 | SemanticStack semantic_stack; | |
94 | LocationStack location_stack; | |
95 | ||
96 | /* Tables. */ | |
3f3eed27 AD |
97 | static const short pact_[[]]; |
98 | static const short defact_[[]]; | |
99 | static const short pgoto_[[]]; | |
100 | static const short defgoto_[[]]; | |
101 | static const short table_[[]]; | |
102 | static const short check_[[]]; | |
3f3eed27 AD |
103 | static const short r1_[[]]; |
104 | static const short r2_[[]]; | |
105 | static const char* const name_[[]]; | |
2b548aa6 RA |
106 | |
107 | /* More tables, for debugging. */ | |
50997c6e | 108 | /* FIXME: These tables should not be printed when not in debug |
2b548aa6 | 109 | mode. %%ifdef? */ |
3f3eed27 AD |
110 | static const short rhs_[[]]; |
111 | static const short prhs_[[]]; | |
112 | static const short rline_[[]]; | |
2b548aa6 RA |
113 | |
114 | /* Even more tables. */ | |
115 | static inline char translate (int token); | |
116 | ||
117 | /* Eof and empty. */ | |
50997c6e RA |
118 | static const int eof_; |
119 | static const int empty_; | |
120 | static const int ntokens_; | |
2b548aa6 RA |
121 | |
122 | /* State. */ | |
123 | int n; | |
124 | int len; | |
50997c6e | 125 | int debug_; |
2b548aa6 | 126 | int state; |
50997c6e | 127 | |
2b548aa6 RA |
128 | /* Lookahead. */ |
129 | int looka; | |
130 | int ilooka; | |
50997c6e | 131 | |
2b548aa6 RA |
132 | /* @$ and $$. */ |
133 | SemanticType value; | |
134 | LocationType location; | |
135 | }; | |
136 | } | |
137 | ||
3f3eed27 | 138 | #output "b4_output_prefix[]b4_output_infix[].cc" |
50997c6e RA |
139 | #include "b4_output_prefix[]b4_output_infix-class.hh" |
140 | ||
141 | /* Enabling traces. */ | |
142 | #ifndef YYDEBUG | |
143 | # define YYDEBUG b4_debug | |
144 | #endif | |
2b548aa6 RA |
145 | |
146 | /* Enable debugging if requested. */ | |
50997c6e | 147 | #if YYDEBUG |
2b548aa6 RA |
148 | |
149 | # include <cstdio> | |
150 | # define YYFPRINTF std::fprintf | |
151 | ||
152 | # define YYDPRINTF(Args) \ | |
153 | do { \ | |
50997c6e | 154 | if (debug_) \ |
2b548aa6 RA |
155 | YYFPRINTF Args; \ |
156 | } while (0) | |
50997c6e RA |
157 | /* Nonzero means print parse trace. [The following comment makes no |
158 | sense to me. Could someone clarify it? --akim] Since this is | |
159 | uninitialized, it does not stop multiple parsers from coexisting. | |
160 | */ | |
2b548aa6 RA |
161 | int yydebug; |
162 | #else /* !YYDEBUG */ | |
163 | # define YYDPRINTF(Args) | |
164 | #endif /* !YYDEBUG */ | |
165 | ||
166 | /* Tokens. */ | |
3f3eed27 | 167 | b4_tokendef |
2b548aa6 RA |
168 | |
169 | int | |
3f3eed27 | 170 | yy::b4_name::parse () |
2b548aa6 RA |
171 | { |
172 | /* Initialize stack. */ | |
173 | state_stack = StateStack (0); | |
174 | semantic_stack = SemanticStack (1); | |
175 | location_stack = LocationStack (1); | |
176 | ||
177 | /* Reserve initial space. The C parser needed that, but is it really | |
178 | useful here? */ | |
3f3eed27 AD |
179 | state_stack.reserve (b4_initdepth); |
180 | semantic_stack.reserve (b4_initdepth); | |
181 | location_stack.reserve (b4_initdepth); | |
2b548aa6 RA |
182 | |
183 | /* Start. */ | |
184 | state = 0; | |
185 | YYDPRINTF ((stderr, "Starting parse\n")); | |
186 | ||
187 | /* New state. */ | |
188 | yynewstate: | |
189 | state_stack.push (state); | |
190 | YYDPRINTF ((stderr, "Entering state %d\n", state)); | |
50997c6e | 191 | goto yybackup; |
2b548aa6 RA |
192 | |
193 | /* Backup. */ | |
194 | yybackup: | |
195 | ||
196 | /* Try to take a decision without lookahead. */ | |
3f3eed27 AD |
197 | n = pact_[[state]]; |
198 | if (n == b4_flag) | |
2b548aa6 RA |
199 | goto yydefault; |
200 | ||
201 | /* Read a lookahead token. */ | |
50997c6e | 202 | if (looka == empty_) |
2b548aa6 RA |
203 | { |
204 | YYDPRINTF ((stderr, "Reading a token: ")); | |
205 | lex (); | |
206 | } | |
207 | ||
208 | /* Convert token to internal form. */ | |
209 | if (looka <= 0) | |
210 | { | |
50997c6e | 211 | looka = eof_; |
2b548aa6 RA |
212 | ilooka = 0; |
213 | YYDPRINTF ((stderr, "Now at end of input.\n")); | |
214 | } | |
215 | else | |
216 | { | |
217 | ilooka = translate (looka); | |
50997c6e RA |
218 | #if YYDEBUG |
219 | if (debug_) | |
220 | { | |
221 | YYFPRINTF (stderr, "Next token is %d (%s", looka, name_[[ilooka]]); | |
222 | YYFPRINTF (stderr, ")\n"); | |
223 | } | |
2b548aa6 RA |
224 | #endif |
225 | } | |
226 | ||
227 | n += ilooka; | |
3f3eed27 | 228 | if (n < 0 || n > b4_last || check_[[n]] != ilooka) |
2b548aa6 RA |
229 | goto yydefault; |
230 | ||
231 | /* Reduce or error. */ | |
3f3eed27 | 232 | n = table_[[n]]; |
2b548aa6 RA |
233 | if (n < 0) |
234 | { | |
3f3eed27 | 235 | if (n == b4_flag) |
2b548aa6 RA |
236 | goto yyerrlab; |
237 | else | |
238 | { | |
239 | n = -n; | |
240 | goto yyreduce; | |
241 | } | |
242 | } | |
243 | else if (n == 0) | |
244 | goto yyerrlab; | |
50997c6e | 245 | |
2b548aa6 | 246 | /* Accept? */ |
3f3eed27 | 247 | if (n == b4_final) |
2b548aa6 RA |
248 | goto yyacceptlab; |
249 | ||
250 | /* Shift the lookahead token. */ | |
3f3eed27 | 251 | YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka, name_[[ilooka]])); |
2b548aa6 RA |
252 | |
253 | /* Discard the token being shifted unless it is eof. */ | |
50997c6e RA |
254 | if (looka != eof_) |
255 | looka = empty_; | |
2b548aa6 RA |
256 | |
257 | semantic_stack.push (value); | |
258 | location_stack.push (location); | |
259 | state = n; | |
260 | goto yynewstate; | |
261 | ||
262 | /* Default action. */ | |
263 | yydefault: | |
3f3eed27 | 264 | n = defact_[[state]]; |
2b548aa6 RA |
265 | if (n == 0) |
266 | goto yyerrlab; | |
50997c6e | 267 | goto yyreduce; |
2b548aa6 RA |
268 | |
269 | /* Reduce. */ | |
270 | yyreduce: | |
3f3eed27 | 271 | len = r2_[[n]]; |
50997c6e RA |
272 | if (len) |
273 | { | |
274 | value = semantic_stack[[1 - len]]; | |
275 | location = location_stack[[1 - len]]; | |
276 | } | |
277 | else | |
278 | { | |
279 | // FIXME: This is truly ugly. | |
280 | value = semantic_stack[[0]]; | |
281 | location = location_stack[[0]]; | |
282 | } | |
2b548aa6 | 283 | |
50997c6e RA |
284 | #if YYDEBUG |
285 | if (debug_) | |
2b548aa6 | 286 | { |
3f3eed27 AD |
287 | YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n - 1, rline_[[n]]); |
288 | for (unsigned i = prhs_[[n]]; | |
289 | rhs_[[i]] >= 0; ++i) | |
290 | YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]); | |
291 | YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n]]]); | |
2b548aa6 RA |
292 | } |
293 | #endif | |
50997c6e | 294 | |
2b548aa6 RA |
295 | { |
296 | SemanticType& yyval (value); | |
50997c6e | 297 | LocationType& yyloc (location); |
2b548aa6 | 298 | SemanticStack& yyvsp (semantic_stack); |
50997c6e | 299 | LocationStack& yylsp (location_stack); |
2b548aa6 RA |
300 | |
301 | switch (n) | |
302 | { | |
3f3eed27 | 303 | b4_actions |
2b548aa6 RA |
304 | } |
305 | } | |
50997c6e | 306 | |
2b548aa6 RA |
307 | state_stack.pop (len); |
308 | semantic_stack.pop (len); | |
309 | location_stack.pop (len); | |
310 | ||
50997c6e RA |
311 | #if YYDEBUG |
312 | if (debug_) | |
2b548aa6 RA |
313 | { |
314 | YYFPRINTF (stderr, "state stack now"); | |
50997c6e | 315 | for (StateStack::ConstIterator i = state_stack.begin (); |
2b548aa6 RA |
316 | i != state_stack.end (); ++i) |
317 | YYFPRINTF (stderr, " %d", *i); | |
318 | YYFPRINTF (stderr, "\n"); | |
319 | } | |
320 | #endif | |
50997c6e | 321 | |
2b548aa6 RA |
322 | semantic_stack.push (value); |
323 | location_stack.push (location); | |
324 | ||
325 | /* Shift the result of the reduction. */ | |
3f3eed27 | 326 | n = r1_[[n]]; |
50997c6e | 327 | state = pgoto_[[n - ntokens_]] + state_stack[[0]]; |
3f3eed27 AD |
328 | if (state >= 0 && state <= b4_last && check_[[state]] == state_stack[[0]]) |
329 | state = table_[[state]]; | |
2b548aa6 | 330 | else |
50997c6e | 331 | state = defgoto_[[n - ntokens_]]; |
2b548aa6 RA |
332 | goto yynewstate; |
333 | ||
334 | /* Report and recover from errors. This is very incomplete. */ | |
335 | yyerrlab: | |
50997c6e | 336 | std::cerr << "Parse error." << std::endl; // FIXME: Need something like yyerror? |
2b548aa6 | 337 | return 1; |
50997c6e | 338 | |
2b548aa6 RA |
339 | /* Accept. */ |
340 | yyacceptlab: | |
341 | return 0; | |
342 | } | |
343 | ||
6b45a3ca | 344 | /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing |
2b548aa6 | 345 | STATE-NUM. */ |
50997c6e | 346 | const short |
3f3eed27 | 347 | yy::b4_name::pact_[[]] = |
2b548aa6 | 348 | { |
3f3eed27 | 349 | b4_pact |
2b548aa6 RA |
350 | }; |
351 | ||
6b45a3ca | 352 | /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
353 | doesn't specify something else to do. Zero means the default is an |
354 | error. */ | |
50997c6e | 355 | const short |
3f3eed27 | 356 | yy::b4_name::defact_[[]] = |
2b548aa6 | 357 | { |
3f3eed27 | 358 | b4_defact |
2b548aa6 RA |
359 | }; |
360 | ||
6b45a3ca | 361 | /* YYPGOTO[[NTERM-NUM]]. */ |
50997c6e | 362 | const short |
3f3eed27 | 363 | yy::b4_name::pgoto_[[]] = |
2b548aa6 | 364 | { |
3f3eed27 | 365 | b4_pgoto |
2b548aa6 RA |
366 | }; |
367 | ||
6b45a3ca | 368 | /* YYDEFGOTO[[NTERM-NUM]]. */ |
50997c6e | 369 | const short |
3f3eed27 | 370 | yy::b4_name::defgoto_[[]] = |
2b548aa6 | 371 | { |
3f3eed27 | 372 | b4_defgoto |
2b548aa6 RA |
373 | }; |
374 | ||
6b45a3ca | 375 | /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
376 | positive, shift that token. If negative, reduce the rule which |
377 | number is the opposite. If zero, do what YYDEFACT says. */ | |
50997c6e | 378 | const short |
3f3eed27 | 379 | yy::b4_name::table_[[]] = |
2b548aa6 | 380 | { |
3f3eed27 | 381 | b4_table |
2b548aa6 RA |
382 | }; |
383 | ||
384 | /* YYCHECK. */ | |
50997c6e | 385 | const short |
3f3eed27 | 386 | yy::b4_name::check_[[]] = |
2b548aa6 | 387 | { |
3f3eed27 | 388 | b4_check |
2b548aa6 RA |
389 | }; |
390 | ||
6b45a3ca | 391 | /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ |
2b548aa6 | 392 | const short |
50997c6e | 393 | yy::b4_name::rline_[[]] = |
2b548aa6 | 394 | { |
50997c6e | 395 | b4_rline |
2b548aa6 RA |
396 | }; |
397 | ||
6b45a3ca | 398 | /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ |
50997c6e | 399 | const short |
3f3eed27 | 400 | yy::b4_name::r1_[[]] = |
2b548aa6 | 401 | { |
3f3eed27 | 402 | b4_r1 |
2b548aa6 RA |
403 | }; |
404 | ||
6b45a3ca | 405 | /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ |
50997c6e | 406 | const short |
3f3eed27 | 407 | yy::b4_name::r2_[[]] = |
2b548aa6 | 408 | { |
3f3eed27 | 409 | b4_r2 |
2b548aa6 RA |
410 | }; |
411 | ||
6b45a3ca | 412 | /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
413 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
414 | const char* | |
3f3eed27 | 415 | const yy::b4_name::name_[[]] = |
2b548aa6 | 416 | { |
3f3eed27 | 417 | b4_tname |
2b548aa6 RA |
418 | }; |
419 | ||
420 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ | |
50997c6e | 421 | const short |
3f3eed27 | 422 | yy::b4_name::rhs_[[]] = |
2b548aa6 | 423 | { |
3f3eed27 | 424 | b4_rhs |
2b548aa6 RA |
425 | }; |
426 | ||
6b45a3ca | 427 | /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 428 | YYRHS. */ |
50997c6e | 429 | const short |
3f3eed27 | 430 | yy::b4_name::prhs_[[]] = |
2b548aa6 | 431 | { |
3f3eed27 | 432 | b4_prhs |
2b548aa6 RA |
433 | }; |
434 | ||
2b548aa6 RA |
435 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
436 | char | |
3f3eed27 | 437 | yy::b4_name::translate (int token) |
2b548aa6 | 438 | { |
50997c6e RA |
439 | static |
440 | const char | |
3f3eed27 | 441 | translate_[[]] = |
2b548aa6 | 442 | { |
3f3eed27 | 443 | b4_translate |
2b548aa6 | 444 | }; |
3f3eed27 | 445 | return ((unsigned)(token) <= b4_maxtok ? translate_[[token]] : b4_nsym); |
2b548aa6 RA |
446 | } |
447 | ||
50997c6e RA |
448 | const int yy::b4_name::eof_ = 0; |
449 | const int yy::b4_name::empty_ = -2; | |
450 | const int yy::b4_name::ntokens_ = b4_ntokens; | |
2b548aa6 | 451 | |
3f3eed27 | 452 | b4_epilogue |
2b548aa6 | 453 | |
3f3eed27 | 454 | #output "stack.hh" |
2b548aa6 RA |
455 | #ifndef BISON_STACK_HH |
456 | # define BISON_STACK_HH | |
457 | ||
458 | #include <vector> | |
459 | ||
460 | namespace yy | |
461 | { | |
462 | template < class T, class S = std::vector< T > > | |
463 | class Stack | |
464 | { | |
465 | public: | |
466 | ||
467 | typedef typename S::iterator Iterator; | |
468 | typedef typename S::const_iterator ConstIterator; | |
469 | ||
470 | Stack () : seq_ () | |
471 | { | |
472 | } | |
473 | ||
474 | Stack (unsigned n) : seq_ (n) | |
475 | { | |
476 | } | |
477 | ||
478 | inline | |
479 | T& | |
3f3eed27 | 480 | operator [[]] (int index) |
2b548aa6 | 481 | { |
3f3eed27 | 482 | return seq_[[seq_.size () - 1 + index]]; |
2b548aa6 RA |
483 | } |
484 | ||
485 | inline | |
486 | const T& | |
3f3eed27 | 487 | operator [[]] (int index) const |
2b548aa6 | 488 | { |
3f3eed27 | 489 | return seq_[[seq_.size () - 1 + index]]; |
2b548aa6 RA |
490 | } |
491 | ||
492 | inline | |
493 | void | |
494 | push (const T& t) | |
495 | { | |
496 | seq_.push_back (t); | |
497 | } | |
498 | ||
499 | inline | |
500 | void | |
501 | pop (unsigned n = 1) | |
502 | { | |
503 | for (; n; --n) | |
504 | seq_.pop_back (); | |
505 | } | |
50997c6e | 506 | |
2b548aa6 RA |
507 | inline |
508 | void | |
509 | reserve (unsigned n) | |
510 | { | |
511 | seq_.reserve (n); | |
512 | } | |
513 | ||
514 | inline ConstIterator begin () const { return seq_.begin (); } | |
515 | inline ConstIterator end () const { return seq_.end (); } | |
516 | ||
517 | private: | |
518 | ||
519 | S seq_; | |
520 | }; | |
521 | } | |
522 | ||
523 | #endif // not BISON_STACK_HH | |
524 | ||
3f3eed27 | 525 | #output "location.hh" |
2b548aa6 RA |
526 | #ifndef BISON_LOCATION_HH |
527 | # define BISON_LOCATION_HH | |
528 | ||
529 | namespace yy | |
530 | { | |
531 | struct Position | |
532 | { | |
533 | int line; | |
534 | int column; | |
535 | }; | |
536 | ||
537 | struct Location | |
538 | { | |
539 | Position first; | |
540 | Position last; | |
541 | }; | |
542 | } | |
543 | ||
544 | #endif // not BISON_LOCATION_HH | |
50997c6e RA |
545 | |
546 | m4_if(b4_defines_flag, 0, [], | |
547 | [#output "b4_output_header_name" | |
548 | #ifndef b4_header_guard | |
549 | # define b4_header_guard | |
550 | ||
551 | b4_tokendef | |
552 | ||
553 | #ifndef YYSTYPE | |
554 | typedef b4_stype | |
555 | yystype; | |
556 | # define YYSTYPE yystype | |
557 | #endif | |
558 | ||
559 | m4_if(b4_pure, [0], | |
560 | [extern YYSTYPE b4_prefix[]lval;]) | |
561 | ||
562 | m4_if(b4_locations_flag, [0], [], | |
563 | [#ifndef YYLTYPE | |
564 | typedef struct yyltype | |
565 | { | |
566 | int first_line; | |
567 | int first_column; | |
568 | int last_line; | |
569 | int last_column; | |
570 | } yyltype; | |
571 | # define YYLTYPE yyltype | |
572 | #endif | |
573 | ||
574 | m4_if(b4_pure, [0], | |
575 | [extern YYLTYPE b4_prefix[]lloc;]) | |
576 | ]) | |
577 | #endif /* not b4_header_guard */ | |
578 | ]) |