]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
* tests/atlocal.in (LDFLAGS, LIBS): New vars.
[bison.git] / data / lalr1.cc
CommitLineData
a75c057f 1m4_divert(-1)
60491a94 2# C++ skeleton for Bison
b61c6978 3# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
60491a94
AD
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA
19
66d30cd4
AD
20## ---------------- ##
21## Default values. ##
22## ---------------- ##
23
24# Stack parameters.
25m4_define_default([b4_stack_depth_init], [200])
26
27# Default Parser class name.
28m4_define_default([b4_parser_class_name], [Parser])
29
30
31
32## ----------------- ##
33## Semantic Values. ##
34## ----------------- ##
35
36
82b6cb3f
AD
37# b4_lhs_value([TYPE])
38# --------------------
39# Expansion of $<TYPE>$.
40m4_define([b4_lhs_value],
41[yyval[]m4_ifval([$1], [.$1])])
42
43
44# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
45# --------------------------------------
46# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
47# symbols on RHS.
48m4_define([b4_rhs_value],
6ad762a8 49[semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
82b6cb3f 50
66d30cd4 51m4_define_default([b4_location_type], [Location])
82b6cb3f
AD
52
53# b4_lhs_location()
54# -----------------
55# Expansion of @$.
56m4_define([b4_lhs_location],
57[yyloc])
58
59
60# b4_rhs_location(RULE-LENGTH, NUM)
61# ---------------------------------
62# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
63# on RHS.
64m4_define([b4_rhs_location],
6ad762a8 65[location_stack_@{m4_eval([$1 - $2])@}])
82b6cb3f
AD
66
67
af27eacb 68m4_define([b4_inherit],
0d8bed56 69 [m4_ifdef([b4_root],
af27eacb
RA
70 [: public b4_root
71],
72 [])])
73
74m4_define([b4_param],
75 [m4_ifdef([b4_root],
76 [,
77 const Param& param],
78 [])])
79
80m4_define([b4_constructor],
81 [m4_ifdef([b4_root],
82 [b4_root (param),
83 ],
84 [])])
85
98254360 86
b526ee61
AD
87# We do want M4 expansion after # for CPP macros.
88m4_changecom()
98254360 89m4_divert(0)dnl
b61c6978
PE
90m4_if(b4_defines_flag, 0, [],
91[@output @output_header_name@
fb8135fa 92b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 93 [2002, 2003])[
c5e3e510
AD
94/* FIXME: This is wrong, we want computed header guards.
95 I don't know why the macros are missing now. :( */
96#ifndef PARSER_HEADER_H
97# define PARSER_HEADER_H
2b548aa6
RA
98
99#include "stack.hh"
2b548aa6
RA
100#include "location.hh"
101
8d69a1a3 102#include <string>
717be197 103#include <iostream>
50997c6e 104
4162fa07 105/* Using locations. */
c5e3e510 106#define YYLSP_NEEDED ]b4_locations_flag[
4162fa07 107
c5e3e510 108]b4_token_defines(b4_tokens)[
17acead5 109
0dd1580a 110/* Copy the first part of user declarations. */
c5e3e510 111]b4_pre_prologue[
4162fa07 112
996b1c7e 113]/* Line __line__ of lalr1.cc. */
c5e3e510 114b4_syncline([@oline@], [@ofile@])[
e96c9728 115
69e2658b
RA
116/* Enabling traces. */
117#ifndef YYDEBUG
c5e3e510 118# define YYDEBUG ]b4_debug[
69e2658b
RA
119#endif
120
121/* Enabling verbose error message. */
122#ifndef YYERROR_VERBOSE
c5e3e510 123# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
124#endif
125
98254360 126#ifndef YYSTYPE
c5e3e510 127]m4_ifdef([b4_stype],
437c2d80 128[b4_syncline([b4_stype_line], [b4_filename])
e96c9728 129typedef union b4_stype yystype;
996b1c7e 130/* Line __line__ of lalr1.cc. */
6ad762a8 131b4_syncline([@oline@], [@ofile@])],
c5e3e510 132[typedef int yystype;])[
98254360
RA
133# define YYSTYPE yystype
134#endif
135
0dd1580a 136/* Copy the second part of user declarations. */
c5e3e510 137]b4_post_prologue[
0dd1580a 138
996b1c7e 139]/* Line __line__ of lalr1.cc. */
c5e3e510 140b4_syncline([@oline@], [@ofile@])[
374f5a14
RA
141#ifndef YYLLOC_DEFAULT
142# define YYLLOC_DEFAULT(Current, Rhs, N) \
7548fed2 143 Current.end = Rhs[N].end;
374f5a14
RA
144#endif
145
2b548aa6
RA
146namespace yy
147{
c5e3e510 148 class ]b4_parser_class_name[;
3f3eed27 149
2b548aa6
RA
150 template < typename P >
151 struct Traits
152 {
153 };
154
155 template < >
c5e3e510 156 struct Traits< ]b4_parser_class_name[ >
2b548aa6 157 {
c5e3e510
AD
158 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
159 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
50997c6e
RA
160 typedef int StateType;
161 typedef yystype SemanticType;
c5e3e510 162 typedef ]b4_location_type[ LocationType;
2b548aa6
RA
163 };
164}
165
2b548aa6
RA
166namespace yy
167{
c5e3e510 168 class ]b4_parser_class_name b4_inherit[
2b548aa6
RA
169 {
170 public:
3f3eed27 171
c5e3e510
AD
172 typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType;
173 typedef Traits< ]b4_parser_class_name[ >::RhsNumberType RhsNumberType;
174 typedef Traits< ]b4_parser_class_name[ >::StateType StateType;
175 typedef Traits< ]b4_parser_class_name[ >::SemanticType SemanticType;
176 typedef Traits< ]b4_parser_class_name[ >::LocationType LocationType;
2b548aa6
RA
177
178 typedef Stack< StateType > StateStack;
179 typedef Stack< SemanticType > SemanticStack;
180 typedef Stack< LocationType > LocationStack;
181
8d69a1a3 182#if YYLSP_NEEDED
c5e3e510
AD
183 ]b4_parser_class_name[ (bool debug,
184 LocationType initlocation][]b4_param[) :
185 ]b4_constructor[][debug_ (debug),
717be197 186 cdebug_ (std::cerr),
af27eacb 187 initlocation_ (initlocation)
8d69a1a3 188#else
c5e3e510
AD
189 ]b4_parser_class_name[ (bool debug][]b4_param[) :
190 ]b4_constructor[][debug_ (debug),
717be197 191 cdebug_ (std::cerr)
8d69a1a3 192#endif
50997c6e 193 {
50997c6e
RA
194 }
195
c5e3e510 196 virtual ~]b4_parser_class_name[ ()
2b548aa6 197 {
2b548aa6
RA
198 }
199
200 virtual int parse ();
201
202 private:
3f3eed27 203
69e2658b 204 virtual void lex_ ();
4bb2bc3f 205 virtual void error_ ();
4aacc3a7 206 virtual void print_ ();
4bb2bc3f 207
2b548aa6 208 /* Stacks. */
69e2658b
RA
209 StateStack state_stack_;
210 SemanticStack semantic_stack_;
211 LocationStack location_stack_;
2b548aa6
RA
212
213 /* Tables. */
c5e3e510
AD
214 static const ]b4_int_type_for([b4_pact])[ pact_[];
215 static const ]b4_int_type_for([b4_pact])[ pact_ninf_;
216 static const ]b4_int_type_for([b4_defact])[ defact_[];
217 static const ]b4_int_type_for([b4_pgoto])[ pgoto_[];
218 static const ]b4_int_type_for([b4_defgoto])[ defgoto_[];
219 static const ]b4_int_type_for([b4_table])[ table_[];
220 static const ]b4_int_type_for([b4_table])[ table_ninf_;
221 static const ]b4_int_type_for([b4_check])[ check_[];
222 static const ]b4_int_type_for([b4_r1])[ r1_[];
223 static const ]b4_int_type_for([b4_r2])[ r2_[];
69e2658b
RA
224
225#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 226 static const char* const name_[];
69e2658b 227#endif
2b548aa6
RA
228
229 /* More tables, for debugging. */
69e2658b 230#if YYDEBUG
c5e3e510
AD
231 static const RhsNumberType rhs_[];
232 static const ]b4_int_type_for([b4_prhs])[ prhs_[];
233 static const ]b4_int_type_for([b4_rline])[ rline_[];
234 static const ]b4_int_type_for([b4_stos])[ stos_[];
235 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
69e2658b 236#endif
2b548aa6
RA
237
238 /* Even more tables. */
680e8701 239 static inline TokenNumberType translate_ (int token);
2b548aa6 240
762a801e 241 /* Constants. */
50997c6e 242 static const int eof_;
39912f52 243 /* LAST_ -- Last index in TABLE_. */
69e2658b 244 static const int last_;
69e2658b 245 static const int nnts_;
50997c6e 246 static const int empty_;
69e2658b 247 static const int final_;
762a801e
RA
248 static const int terror_;
249 static const int errcode_;
50997c6e 250 static const int ntokens_;
69e2658b 251 static const int initdepth_;
007a50a4
AD
252 static const unsigned user_token_number_max_;
253 static const TokenNumberType undef_token_;
2b548aa6
RA
254
255 /* State. */
69e2658b
RA
256 int n_;
257 int len_;
69e2658b 258 int state_;
4bb2bc3f 259
717be197
AD
260 /* Debugging. */
261 int debug_;
262 std::ostream &cdebug_;
263
69e2658b
RA
264 /* Lookahead and lookahead in internal form. */
265 int looka_;
266 int ilooka_;
4bb2bc3f
RA
267
268 /* Message. */
269 std::string message;
270
374f5a14 271 /* Semantic value and location of lookahead token. */
2b548aa6
RA
272 SemanticType value;
273 LocationType location;
8d69a1a3 274
6ad762a8 275 /* @@$ and $$. */
374f5a14
RA
276 SemanticType yyval;
277 LocationType yyloc;
278
8d69a1a3
RA
279 /* Initial location. */
280 LocationType initlocation_;
2b548aa6
RA
281 };
282}
283
c5e3e510 284#endif /* ! defined PARSER_HEADER_H */]
b61c6978 285])dnl
6ad762a8 286@output @output_parser_name@
fb8135fa 287b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 288 [2002, 2003])
98254360 289
b61c6978 290m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
50997c6e 291
2b548aa6 292/* Enable debugging if requested. */
50997c6e 293#if YYDEBUG
717be197 294# define YYCDEBUG if (debug_) cdebug_
2b548aa6 295#else /* !YYDEBUG */
717be197 296# define YYCDEBUG if (0) cdebug_
2b548aa6
RA
297#endif /* !YYDEBUG */
298
2b548aa6 299int
c5e3e510 300yy::]b4_parser_class_name[::parse ()
2b548aa6 301{
4bb2bc3f
RA
302 int nerrs = 0;
303 int errstatus = 0;
304
3ae831b4
AD
305 /* Initialize the stacks. The initial state will be pushed in
306 yynewstate, since the latter expects the semantical and the
307 location values to have been already stored, initialize these
308 stacks with a primary value. */
69e2658b
RA
309 state_stack_ = StateStack (0);
310 semantic_stack_ = SemanticStack (1);
311 location_stack_ = LocationStack (1);
2b548aa6 312
2b548aa6 313 /* Start. */
69e2658b
RA
314 state_ = 0;
315 looka_ = empty_;
8d69a1a3
RA
316#if YYLSP_NEEDED
317 location = initlocation_;
318#endif
717be197 319 YYCDEBUG << "Starting parse" << std::endl;
2b548aa6
RA
320
321 /* New state. */
322 yynewstate:
69e2658b 323 state_stack_.push (state_);
717be197 324 YYCDEBUG << "Entering state " << state_ << std::endl;
50997c6e 325 goto yybackup;
2b548aa6
RA
326
327 /* Backup. */
328 yybackup:
329
330 /* Try to take a decision without lookahead. */
c5e3e510 331 n_ = pact_[state_];
12b0043a 332 if (n_ == pact_ninf_)
2b548aa6
RA
333 goto yydefault;
334
335 /* Read a lookahead token. */
69e2658b 336 if (looka_ == empty_)
2b548aa6 337 {
717be197 338 YYCDEBUG << "Reading a token: ";
69e2658b 339 lex_ ();
2b548aa6
RA
340 }
341
342 /* Convert token to internal form. */
69e2658b 343 if (looka_ <= 0)
2b548aa6 344 {
69e2658b
RA
345 looka_ = eof_;
346 ilooka_ = 0;
717be197 347 YYCDEBUG << "Now at end of input." << std::endl;
2b548aa6
RA
348 }
349 else
350 {
69e2658b 351 ilooka_ = translate_ (looka_);
50997c6e
RA
352#if YYDEBUG
353 if (debug_)
354 {
717be197 355 YYCDEBUG << "Next token is " << looka_
c5e3e510 356 << " (" << name_[ilooka_];
4aacc3a7 357 print_ ();
717be197 358 YYCDEBUG << ')' << std::endl;
50997c6e 359 }
2b548aa6
RA
360#endif
361 }
362
69e2658b 363 n_ += ilooka_;
c5e3e510 364 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
2b548aa6
RA
365 goto yydefault;
366
367 /* Reduce or error. */
c5e3e510 368 n_ = table_[n_];
69e2658b 369 if (n_ < 0)
2b548aa6 370 {
12b0043a 371 if (n_ == table_ninf_)
2b548aa6
RA
372 goto yyerrlab;
373 else
374 {
69e2658b 375 n_ = -n_;
2b548aa6
RA
376 goto yyreduce;
377 }
378 }
69e2658b 379 else if (n_ == 0)
2b548aa6 380 goto yyerrlab;
a75c057f 381
2b548aa6 382 /* Accept? */
69e2658b 383 if (n_ == final_)
2b548aa6
RA
384 goto yyacceptlab;
385
386 /* Shift the lookahead token. */
fc049e9c 387#if YYDEBUG
717be197 388 YYCDEBUG << "Shifting token " << looka_
fc049e9c
AD
389 << " (" << name_[ilooka_] << "), ";
390#endif
2b548aa6
RA
391
392 /* Discard the token being shifted unless it is eof. */
69e2658b
RA
393 if (looka_ != eof_)
394 looka_ = empty_;
2b548aa6 395
69e2658b
RA
396 semantic_stack_.push (value);
397 location_stack_.push (location);
8d69a1a3
RA
398
399 /* Count tokens shifted since error; after three, turn off error
400 status. */
401 if (errstatus)
402 --errstatus;
403
69e2658b 404 state_ = n_;
2b548aa6
RA
405 goto yynewstate;
406
407 /* Default action. */
408 yydefault:
c5e3e510 409 n_ = defact_[state_];
69e2658b 410 if (n_ == 0)
2b548aa6 411 goto yyerrlab;
50997c6e 412 goto yyreduce;
2b548aa6
RA
413
414 /* Reduce. */
415 yyreduce:
c5e3e510 416 len_ = r2_[n_];
69e2658b 417 if (len_)
50997c6e 418 {
c5e3e510
AD
419 yyval = semantic_stack_[len_ - 1];
420 yyloc = location_stack_[len_ - 1];
50997c6e
RA
421 }
422 else
69e2658b 423 {
c5e3e510
AD
424 yyval = semantic_stack_[0];
425 yyloc = location_stack_[0];
50997c6e 426 }
2b548aa6 427
50997c6e
RA
428#if YYDEBUG
429 if (debug_)
2b548aa6 430 {
717be197 431 YYCDEBUG << "Reducing via rule " << n_ - 1
c5e3e510
AD
432 << " (line " << rline_[n_] << "), ";
433 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
434 0 <= rhs_[i]; ++i)
435 YYCDEBUG << name_[rhs_[i]] << ' ';
436 YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl;
2b548aa6
RA
437 }
438#endif
a75c057f 439
374f5a14
RA
440 if (len_)
441 {
442 Slice< LocationType, LocationStack > slice (location_stack_, len_);
443 YYLLOC_DEFAULT (yyloc, slice, len_);
444 }
445
45119f04
RA
446 switch (n_)
447 {
c5e3e510 448 ]b4_actions[
45119f04 449 }
a75c057f 450
996b1c7e 451]/* Line __line__ of lalr1.cc. */
c5e3e510 452b4_syncline([@oline@], [@ofile@])[
06446ccf 453
69e2658b
RA
454 state_stack_.pop (len_);
455 semantic_stack_.pop (len_);
456 location_stack_.pop (len_);
2b548aa6 457
50997c6e
RA
458#if YYDEBUG
459 if (debug_)
2b548aa6 460 {
717be197 461 YYCDEBUG << "state stack now";
a75c057f 462 for (StateStack::ConstIterator i = state_stack_.begin ();
69e2658b 463 i != state_stack_.end (); ++i)
717be197
AD
464 YYCDEBUG << ' ' << *i;
465 YYCDEBUG << std::endl;
2b548aa6
RA
466 }
467#endif
a75c057f 468
374f5a14
RA
469 semantic_stack_.push (yyval);
470 location_stack_.push (yyloc);
2b548aa6
RA
471
472 /* Shift the result of the reduction. */
c5e3e510
AD
473 n_ = r1_[n_];
474 state_ = pgoto_[n_ - ntokens_] + state_stack_[0];
475 if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0])
476 state_ = table_[state_];
2b548aa6 477 else
c5e3e510 478 state_ = defgoto_[n_ - ntokens_];
2b548aa6
RA
479 goto yynewstate;
480
481 /* Report and recover from errors. This is very incomplete. */
482 yyerrlab:
4bb2bc3f
RA
483 /* If not already recovering from an error, report this error. */
484 if (!errstatus)
485 {
486 ++nerrs;
a75c057f 487
69e2658b 488#if YYERROR_VERBOSE
c5e3e510 489 n_ = pact_[state_];
12b0043a 490 if (pact_ninf_ < n_ && n_ < last_)
4bb2bc3f 491 {
6e649e65 492 message = "syntax error, unexpected ";
c5e3e510 493 message += name_[ilooka_];
4bb2bc3f
RA
494 {
495 int count = 0;
69e2658b 496 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
c5e3e510 497 if (check_[x + n_] == x && x != terror_)
4bb2bc3f
RA
498 ++count;
499 if (count < 5)
500 {
501 count = 0;
69e2658b 502 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
c5e3e510 503 if (check_[x + n_] == x && x != terror_)
4bb2bc3f 504 {
a75c057f 505 message += (!count++) ? ", expecting " : " or ";
c5e3e510 506 message += name_[x];
4bb2bc3f
RA
507 }
508 }
509 }
510 }
511 else
69e2658b 512#endif
6e649e65 513 message = "syntax error";
8d69a1a3 514 error_ ();
4bb2bc3f 515 }
762a801e 516 goto yyerrlab1;
a75c057f 517
762a801e
RA
518 /* Error raised explicitly by an action. */
519 yyerrlab1:
520 if (errstatus == 3)
521 {
522 /* If just tried and failed to reuse lookahead token after an
523 error, discard it. */
524
525 /* Return failure if at end of input. */
69e2658b 526 if (looka_ == eof_)
762a801e 527 goto yyabortlab;
7548fed2 528#if YYDEBUG
717be197 529 YYCDEBUG << "Discarding token " << looka_
7548fed2
AD
530 << " (" << name_[ilooka_] << ")." << std::endl;
531#endif
69e2658b 532 looka_ = empty_;
762a801e
RA
533 }
534
535 /* Else will try to reuse lookahead token after shifting the error
536 token. */
537
538 errstatus = 3;
762a801e 539
769b430f
AD
540 for (;;)
541 {
c5e3e510 542 n_ = pact_[state_];
12b0043a 543 if (n_ != pact_ninf_)
769b430f
AD
544 {
545 n_ += terror_;
c5e3e510 546 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
769b430f 547 {
c5e3e510 548 n_ = table_[n_];
769b430f
AD
549 if (0 < n_)
550 break;
551 }
552 }
553
554 /* Pop the current state because it cannot handle the error token. */
3ae831b4 555 if (state_stack_.height () == 1)
769b430f 556 goto yyabortlab;
762a801e
RA
557
558#if YYDEBUG
769b430f
AD
559 if (debug_)
560 {
c5e3e510 561 if (stos_[state_] < ntokens_)
769b430f 562 {
717be197 563 YYCDEBUG << "Error: popping token "
c5e3e510
AD
564 << token_number_[stos_[state_]]
565 << " (" << name_[stos_[state_]];
769b430f 566# ifdef YYPRINT
c5e3e510 567 YYPRINT (stderr, token_number_[stos_[state_]],
769b430f
AD
568 semantic_stack_.top ());
569# endif
717be197 570 YYCDEBUG << ')' << std::endl;
769b430f
AD
571 }
572 else
573 {
717be197 574 YYCDEBUG << "Error: popping nonterminal ("
c5e3e510 575 << name_[stos_[state_]] << ')' << std::endl;
769b430f
AD
576 }
577 }
762a801e
RA
578#endif
579
c5e3e510 580 state_ = (state_stack_.pop (), state_stack_[0]);
769b430f
AD
581 semantic_stack_.pop ();
582 location_stack_.pop ();;
762a801e 583
769b430f
AD
584#if YYDEBUG
585 if (debug_)
586 {
717be197 587 YYCDEBUG << "Error: state stack now";
769b430f
AD
588 for (StateStack::ConstIterator i = state_stack_.begin ();
589 i != state_stack_.end (); ++i)
717be197
AD
590 YYCDEBUG << ' ' << *i;
591 YYCDEBUG << std::endl;
769b430f
AD
592 }
593#endif
762a801e 594 }
762a801e 595
69e2658b 596 if (n_ == final_)
762a801e
RA
597 goto yyacceptlab;
598
717be197 599 YYCDEBUG << "Shifting error token, ";
762a801e 600
69e2658b
RA
601 semantic_stack_.push (value);
602 location_stack_.push (location);
762a801e 603
69e2658b 604 state_ = n_;
762a801e
RA
605 goto yynewstate;
606
2b548aa6
RA
607 /* Accept. */
608 yyacceptlab:
609 return 0;
762a801e
RA
610
611 /* Abort. */
612 yyabortlab:
613 return 1;
2b548aa6
RA
614}
615
69e2658b 616void
c5e3e510 617yy::]b4_parser_class_name[::lex_ ()
69e2658b
RA
618{
619#if YYLSP_NEEDED
620 looka_ = yylex (&value, &location);
621#else
622 looka_ = yylex (&value);
623#endif
624}
625
c5e3e510 626/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6 627 STATE-NUM. */
c5e3e510
AD
628const ]b4_int_type_for([b4_pact]) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
629const ]b4_int_type_for([b4_pact])[
630yy::]b4_parser_class_name[::pact_[] =
2b548aa6 631{
c5e3e510 632 ]b4_pact[
2b548aa6
RA
633};
634
c5e3e510 635/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
636 doesn't specify something else to do. Zero means the default is an
637 error. */
c5e3e510
AD
638const ]b4_int_type_for([b4_defact])[
639yy::]b4_parser_class_name[::defact_[] =
2b548aa6 640{
c5e3e510 641 ]b4_defact[
2b548aa6
RA
642};
643
c5e3e510
AD
644/* YYPGOTO[NTERM-NUM]. */
645const ]b4_int_type_for([b4_pgoto])[
646yy::]b4_parser_class_name[::pgoto_[] =
2b548aa6 647{
c5e3e510 648 ]b4_pgoto[
2b548aa6
RA
649};
650
c5e3e510
AD
651/* YYDEFGOTO[NTERM-NUM]. */
652const ]b4_int_type_for([b4_defgoto])[
653yy::]b4_parser_class_name[::defgoto_[] =
2b548aa6 654{
c5e3e510 655 ]b4_defgoto[
2b548aa6
RA
656};
657
c5e3e510 658/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
659 positive, shift that token. If negative, reduce the rule which
660 number is the opposite. If zero, do what YYDEFACT says. */
c5e3e510
AD
661const ]b4_int_type_for([b4_table]) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
662const ]b4_int_type_for([b4_table])[
663yy::]b4_parser_class_name[::table_[] =
2b548aa6 664{
c5e3e510 665 ]b4_table[
2b548aa6
RA
666};
667
668/* YYCHECK. */
c5e3e510
AD
669const ]b4_int_type_for([b4_check])[
670yy::]b4_parser_class_name[::check_[] =
2b548aa6 671{
c5e3e510 672 ]b4_check[
2b548aa6
RA
673};
674
769b430f 675#if YYDEBUG
c5e3e510 676/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f 677 symbol of state STATE-NUM. */
c5e3e510
AD
678const ]b4_int_type_for([b4_stos])[
679yy::]b4_parser_class_name[::stos_[] =
769b430f 680{
c5e3e510 681 ]b4_stos[
769b430f
AD
682};
683
c5e3e510 684/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
769b430f 685 to YYLEX-NUM. */
c5e3e510
AD
686const ]b4_int_type_for([b4_toknum])[
687yy::]b4_parser_class_name[::token_number_[] =
769b430f 688{
c5e3e510 689 ]b4_toknum[
769b430f
AD
690};
691#endif
692
c5e3e510
AD
693/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
694const ]b4_int_type_for([b4_r1])[
695yy::]b4_parser_class_name[::r1_[] =
2b548aa6 696{
c5e3e510 697 ]b4_r1[
2b548aa6
RA
698};
699
c5e3e510
AD
700/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
701const ]b4_int_type_for([b4_r2])[
702yy::]b4_parser_class_name[::r2_[] =
2b548aa6 703{
c5e3e510 704 ]b4_r2[
2b548aa6
RA
705};
706
69e2658b 707#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 708/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2b548aa6
RA
709 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
710const char*
c5e3e510 711const yy::]b4_parser_class_name[::name_[] =
2b548aa6 712{
c5e3e510 713 ]b4_tname[
2b548aa6 714};
69e2658b 715#endif
2b548aa6 716
69e2658b 717#if YYDEBUG
2b548aa6 718/* YYRHS -- A `-1'-separated list of the rules' RHS. */
c5e3e510
AD
719const yy::]b4_parser_class_name[::RhsNumberType
720yy::]b4_parser_class_name[::rhs_[] =
2b548aa6 721{
c5e3e510 722 ]b4_rhs[
2b548aa6
RA
723};
724
c5e3e510 725/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 726 YYRHS. */
c5e3e510
AD
727const ]b4_int_type_for([b4_prhs])[
728yy::]b4_parser_class_name[::prhs_[] =
2b548aa6 729{
c5e3e510 730 ]b4_prhs[
2b548aa6
RA
731};
732
c5e3e510
AD
733/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
734const ]b4_int_type_for([b4_rline])[
735yy::]b4_parser_class_name[::rline_[] =
69e2658b 736{
c5e3e510 737 ]b4_rline[
69e2658b
RA
738};
739#endif
740
2b548aa6 741/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
c5e3e510
AD
742yy::]b4_parser_class_name[::TokenNumberType
743yy::]b4_parser_class_name[::translate_ (int token)
2b548aa6 744{
a75c057f 745 static
680e8701 746 const TokenNumberType
c5e3e510 747 translate_[] =
2b548aa6 748 {
c5e3e510 749 ]b4_translate[
2b548aa6 750 };
007a50a4 751 if ((unsigned) token <= user_token_number_max_)
c5e3e510 752 return translate_[token];
007a50a4
AD
753 else
754 return undef_token_;
2b548aa6
RA
755}
756
c5e3e510
AD
757const int yy::]b4_parser_class_name[::eof_ = 0;
758const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
759const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
760const int yy::]b4_parser_class_name[::empty_ = -2;
761const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
762const int yy::]b4_parser_class_name[::terror_ = 1;
763const int yy::]b4_parser_class_name[::errcode_ = 256;
764const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
765const int yy::]b4_parser_class_name[::initdepth_ = ]b4_stack_depth_init[;
66d30cd4 766
c5e3e510
AD
767const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
768const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
2b548aa6 769
c5e3e510 770]b4_epilogue
21846f69 771dnl
6ad762a8 772@output stack.hh
7548fed2 773b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[
98254360 774
2b548aa6
RA
775#ifndef BISON_STACK_HH
776# define BISON_STACK_HH
777
45119f04 778#include <deque>
2b548aa6
RA
779
780namespace yy
781{
45119f04 782 template < class T, class S = std::deque< T > >
2b548aa6
RA
783 class Stack
784 {
785 public:
786
787 typedef typename S::iterator Iterator;
788 typedef typename S::const_iterator ConstIterator;
789
790 Stack () : seq_ ()
791 {
792 }
793
794 Stack (unsigned n) : seq_ (n)
795 {
796 }
797
798 inline
799 T&
c5e3e510 800 operator [] (unsigned index)
2b548aa6 801 {
c5e3e510 802 return seq_[index];
2b548aa6
RA
803 }
804
805 inline
806 const T&
c5e3e510 807 operator [] (unsigned index) const
2b548aa6 808 {
c5e3e510 809 return seq_[index];
2b548aa6
RA
810 }
811
812 inline
813 void
814 push (const T& t)
815 {
45119f04 816 seq_.push_front (t);
2b548aa6
RA
817 }
818
819 inline
820 void
821 pop (unsigned n = 1)
822 {
823 for (; n; --n)
45119f04 824 seq_.pop_front ();
2b548aa6
RA
825 }
826
762a801e
RA
827 inline
828 unsigned
829 height () const
830 {
831 return seq_.size ();
832 }
833
2b548aa6
RA
834 inline ConstIterator begin () const { return seq_.begin (); }
835 inline ConstIterator end () const { return seq_.end (); }
836
837 private:
838
839 S seq_;
840 };
374f5a14
RA
841
842 template < class T, class S = Stack< T > >
843 class Slice
844 {
845 public:
846
847 Slice (const S& stack,
848 unsigned range) : stack_ (stack),
849 range_ (range)
850 {
851 }
852
853 inline
854 const T&
c5e3e510 855 operator [] (unsigned index) const
374f5a14 856 {
c5e3e510 857 return stack_[range_ - index];
374f5a14
RA
858 }
859
860 private:
861
862 const S& stack_;
863 unsigned range_;
864 };
2b548aa6
RA
865}
866
c5e3e510 867#endif // not BISON_STACK_HH]
21846f69 868dnl
6ad762a8 869@output location.hh
7548fed2 870b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[
98254360 871
2b548aa6
RA
872#ifndef BISON_LOCATION_HH
873# define BISON_LOCATION_HH
874
7548fed2
AD
875# include <iostream>
876# include <string>
877
2b548aa6
RA
878namespace yy
879{
7548fed2 880 class Position
2b548aa6 881 {
7548fed2
AD
882 public:
883 Position ()
884 : filename (), line (1), column (0)
885 {}
886
887 std::string filename;
2b548aa6
RA
888 int line;
889 int column;
890 };
891
7548fed2
AD
892 inline std::ostream&
893 operator<< (std::ostream& ostr, const Position& pos)
894 {
895 if (pos.filename != "")
896 ostr << pos.filename << ':';
897 ostr << pos.line << '.' << pos.column;
898 return ostr;
899 }
900
901 inline Position
902 operator- (const Position& pos, int col)
903 {
904 Position res (pos);
905 res.column -= col;
906 return res;
907 }
908
909
910 class Location
2b548aa6 911 {
7548fed2
AD
912 public:
913 Position begin;
914 Position end;
2b548aa6 915 };
7548fed2
AD
916
917 /* Don't issue twice the line number when the location is on a single
918 line. */
919
920 inline std::ostream&
921 operator<< (std::ostream& ostr, const Location& pos)
922 {
923 ostr << pos.begin;
924 if (pos.begin.filename != pos.end.filename)
925 ostr << '-' << pos.end - 1;
926 else if (pos.begin.line != pos.end.line)
927 ostr << '-' << pos.end.line << '.' << pos.end.column - 1;
928 else if (pos.begin.column != pos.end.column - 1)
929 ostr << '-' << pos.end.column - 1;
930 return ostr;
931 }
932
2b548aa6
RA
933}
934
c5e3e510 935#endif // not BISON_LOCATION_HH]