]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
Don't pass C-only options to g++.
[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
66d30cd4
AD
24# Default Parser class name.
25m4_define_default([b4_parser_class_name], [Parser])
26
27
28
29## ----------------- ##
30## Semantic Values. ##
31## ----------------- ##
32
33
82b6cb3f
AD
34# b4_lhs_value([TYPE])
35# --------------------
36# Expansion of $<TYPE>$.
37m4_define([b4_lhs_value],
38[yyval[]m4_ifval([$1], [.$1])])
39
40
41# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42# --------------------------------------
43# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
44# symbols on RHS.
45m4_define([b4_rhs_value],
6ad762a8 46[semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
82b6cb3f 47
66d30cd4 48m4_define_default([b4_location_type], [Location])
82b6cb3f
AD
49
50# b4_lhs_location()
51# -----------------
52# Expansion of @$.
53m4_define([b4_lhs_location],
54[yyloc])
55
56
57# b4_rhs_location(RULE-LENGTH, NUM)
58# ---------------------------------
59# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60# on RHS.
61m4_define([b4_rhs_location],
6ad762a8 62[location_stack_@{m4_eval([$1 - $2])@}])
82b6cb3f
AD
63
64
af27eacb 65m4_define([b4_inherit],
0d8bed56 66 [m4_ifdef([b4_root],
af27eacb
RA
67 [: public b4_root
68],
69 [])])
70
71m4_define([b4_param],
72 [m4_ifdef([b4_root],
73 [,
74 const Param& param],
75 [])])
76
77m4_define([b4_constructor],
78 [m4_ifdef([b4_root],
79 [b4_root (param),
80 ],
81 [])])
82
98254360 83
caf37a36
ADL
84# b4_parse_param_decl
85# -------------------
86# Constructor's extra arguments.
87m4_define([b4_parse_param_decl],
88 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
89
90# b4_parse_param_cons
91# -------------------
92# constructor's extra initialisations.
93m4_define([b4_parse_param_cons],
94 [m4_ifset([b4_parse_param],
95 [,
96 b4_cc_constructor_calls(b4_parse_param)])])
97m4_define([b4_cc_constructor_calls],
98 [m4_map_sep([b4_cc_constructor_call], [,
99 ], [$@])])
100m4_define([b4_cc_constructor_call],
101 [$2($2)])
102
103# b4_parse_param_vars
104# -------------------
105# Extra instance variables.
106m4_define([b4_parse_param_vars],
107 [m4_ifset([b4_parse_param],
108 [
109 /* User arguments. */
110b4_cc_var_decls(b4_parse_param)])])
111m4_define([b4_cc_var_decls],
112 [m4_map_sep([b4_cc_var_decl], [
113], [$@])])
114m4_define([b4_cc_var_decl],
115 [ $1;])
116
b526ee61
AD
117# We do want M4 expansion after # for CPP macros.
118m4_changecom()
98254360 119m4_divert(0)dnl
b61c6978
PE
120m4_if(b4_defines_flag, 0, [],
121[@output @output_header_name@
fb8135fa 122b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 123 [2002, 2003])[
c5e3e510
AD
124/* FIXME: This is wrong, we want computed header guards.
125 I don't know why the macros are missing now. :( */
126#ifndef PARSER_HEADER_H
127# define PARSER_HEADER_H
2b548aa6
RA
128
129#include "stack.hh"
2b548aa6
RA
130#include "location.hh"
131
8d69a1a3 132#include <string>
717be197 133#include <iostream>
50997c6e 134
4162fa07 135/* Using locations. */
c5e3e510 136#define YYLSP_NEEDED ]b4_locations_flag[
4162fa07 137
c5e3e510 138]b4_token_defines(b4_tokens)[
17acead5 139
0dd1580a 140/* Copy the first part of user declarations. */
c5e3e510 141]b4_pre_prologue[
4162fa07 142
996b1c7e 143]/* Line __line__ of lalr1.cc. */
c5e3e510 144b4_syncline([@oline@], [@ofile@])[
e96c9728 145
69e2658b
RA
146/* Enabling traces. */
147#ifndef YYDEBUG
c5e3e510 148# define YYDEBUG ]b4_debug[
69e2658b
RA
149#endif
150
151/* Enabling verbose error message. */
152#ifndef YYERROR_VERBOSE
c5e3e510 153# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
154#endif
155
98254360 156#ifndef YYSTYPE
c5e3e510 157]m4_ifdef([b4_stype],
437c2d80 158[b4_syncline([b4_stype_line], [b4_filename])
e96c9728 159typedef union b4_stype yystype;
996b1c7e 160/* Line __line__ of lalr1.cc. */
6ad762a8 161b4_syncline([@oline@], [@ofile@])],
c5e3e510 162[typedef int yystype;])[
98254360
RA
163# define YYSTYPE yystype
164#endif
165
0dd1580a 166/* Copy the second part of user declarations. */
c5e3e510 167]b4_post_prologue[
0dd1580a 168
996b1c7e 169]/* Line __line__ of lalr1.cc. */
c5e3e510 170b4_syncline([@oline@], [@ofile@])[
374f5a14
RA
171#ifndef YYLLOC_DEFAULT
172# define YYLLOC_DEFAULT(Current, Rhs, N) \
7548fed2 173 Current.end = Rhs[N].end;
374f5a14
RA
174#endif
175
2b548aa6
RA
176namespace yy
177{
c5e3e510 178 class ]b4_parser_class_name[;
3f3eed27 179
2b548aa6
RA
180 template < typename P >
181 struct Traits
182 {
183 };
184
185 template < >
c5e3e510 186 struct Traits< ]b4_parser_class_name[ >
2b548aa6 187 {
c5e3e510
AD
188 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
189 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
50997c6e
RA
190 typedef int StateType;
191 typedef yystype SemanticType;
c5e3e510 192 typedef ]b4_location_type[ LocationType;
2b548aa6
RA
193 };
194}
195
2b548aa6
RA
196namespace yy
197{
c5e3e510 198 class ]b4_parser_class_name b4_inherit[
2b548aa6
RA
199 {
200 public:
3f3eed27 201
c5e3e510
AD
202 typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType;
203 typedef Traits< ]b4_parser_class_name[ >::RhsNumberType RhsNumberType;
204 typedef Traits< ]b4_parser_class_name[ >::StateType StateType;
205 typedef Traits< ]b4_parser_class_name[ >::SemanticType SemanticType;
206 typedef Traits< ]b4_parser_class_name[ >::LocationType LocationType;
2b548aa6
RA
207
208 typedef Stack< StateType > StateStack;
209 typedef Stack< SemanticType > SemanticStack;
210 typedef Stack< LocationType > LocationStack;
211
8d69a1a3 212#if YYLSP_NEEDED
c5e3e510 213 ]b4_parser_class_name[ (bool debug,
caf37a36 214 LocationType initlocation][]b4_param[]b4_parse_param_decl[) :
c5e3e510 215 ]b4_constructor[][debug_ (debug),
717be197 216 cdebug_ (std::cerr),
caf37a36 217 initlocation_ (initlocation)]b4_parse_param_cons[
8d69a1a3 218#else
caf37a36 219 ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
c5e3e510 220 ]b4_constructor[][debug_ (debug),
caf37a36 221 cdebug_ (std::cerr)]b4_parse_param_cons[
8d69a1a3 222#endif
50997c6e 223 {
50997c6e
RA
224 }
225
c5e3e510 226 virtual ~]b4_parser_class_name[ ()
2b548aa6 227 {
2b548aa6
RA
228 }
229
230 virtual int parse ();
231
232 private:
3f3eed27 233
69e2658b 234 virtual void lex_ ();
4bb2bc3f 235 virtual void error_ ();
4aacc3a7 236 virtual void print_ ();
4bb2bc3f 237
2b548aa6 238 /* Stacks. */
69e2658b
RA
239 StateStack state_stack_;
240 SemanticStack semantic_stack_;
241 LocationStack location_stack_;
2b548aa6
RA
242
243 /* Tables. */
c5e3e510 244 static const ]b4_int_type_for([b4_pact])[ pact_[];
0c3c1f98 245 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ pact_ninf_;
c5e3e510
AD
246 static const ]b4_int_type_for([b4_defact])[ defact_[];
247 static const ]b4_int_type_for([b4_pgoto])[ pgoto_[];
248 static const ]b4_int_type_for([b4_defgoto])[ defgoto_[];
249 static const ]b4_int_type_for([b4_table])[ table_[];
0c3c1f98 250 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ table_ninf_;
c5e3e510
AD
251 static const ]b4_int_type_for([b4_check])[ check_[];
252 static const ]b4_int_type_for([b4_r1])[ r1_[];
253 static const ]b4_int_type_for([b4_r2])[ r2_[];
69e2658b
RA
254
255#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 256 static const char* const name_[];
69e2658b 257#endif
2b548aa6
RA
258
259 /* More tables, for debugging. */
69e2658b 260#if YYDEBUG
c5e3e510
AD
261 static const RhsNumberType rhs_[];
262 static const ]b4_int_type_for([b4_prhs])[ prhs_[];
263 static const ]b4_int_type_for([b4_rline])[ rline_[];
264 static const ]b4_int_type_for([b4_stos])[ stos_[];
265 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
69e2658b 266#endif
2b548aa6
RA
267
268 /* Even more tables. */
680e8701 269 static inline TokenNumberType translate_ (int token);
2b548aa6 270
762a801e 271 /* Constants. */
50997c6e 272 static const int eof_;
39912f52 273 /* LAST_ -- Last index in TABLE_. */
69e2658b 274 static const int last_;
69e2658b 275 static const int nnts_;
50997c6e 276 static const int empty_;
69e2658b 277 static const int final_;
762a801e
RA
278 static const int terror_;
279 static const int errcode_;
50997c6e 280 static const int ntokens_;
007a50a4
AD
281 static const unsigned user_token_number_max_;
282 static const TokenNumberType undef_token_;
2b548aa6
RA
283
284 /* State. */
69e2658b
RA
285 int n_;
286 int len_;
69e2658b 287 int state_;
4bb2bc3f 288
717be197
AD
289 /* Debugging. */
290 int debug_;
291 std::ostream &cdebug_;
292
69e2658b
RA
293 /* Lookahead and lookahead in internal form. */
294 int looka_;
295 int ilooka_;
4bb2bc3f
RA
296
297 /* Message. */
298 std::string message;
299
374f5a14 300 /* Semantic value and location of lookahead token. */
2b548aa6
RA
301 SemanticType value;
302 LocationType location;
8d69a1a3 303
6ad762a8 304 /* @@$ and $$. */
374f5a14
RA
305 SemanticType yyval;
306 LocationType yyloc;
307
8d69a1a3
RA
308 /* Initial location. */
309 LocationType initlocation_;
caf37a36 310]b4_parse_param_vars[
2b548aa6
RA
311 };
312}
313
c5e3e510 314#endif /* ! defined PARSER_HEADER_H */]
b61c6978 315])dnl
6ad762a8 316@output @output_parser_name@
fb8135fa 317b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 318 [2002, 2003])
98254360 319
b61c6978 320m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
50997c6e 321
2b548aa6 322/* Enable debugging if requested. */
50997c6e 323#if YYDEBUG
717be197 324# define YYCDEBUG if (debug_) cdebug_
2b548aa6 325#else /* !YYDEBUG */
717be197 326# define YYCDEBUG if (0) cdebug_
2b548aa6
RA
327#endif /* !YYDEBUG */
328
60a777aa
AD
329#define YYACCEPT goto yyacceptlab
330#define YYABORT goto yyabortlab
331#define YYERROR goto yyerrlab1
332
333
2b548aa6 334int
c5e3e510 335yy::]b4_parser_class_name[::parse ()
2b548aa6 336{
4bb2bc3f
RA
337 int nerrs = 0;
338 int errstatus = 0;
339
3ae831b4
AD
340 /* Initialize the stacks. The initial state will be pushed in
341 yynewstate, since the latter expects the semantical and the
342 location values to have been already stored, initialize these
343 stacks with a primary value. */
69e2658b
RA
344 state_stack_ = StateStack (0);
345 semantic_stack_ = SemanticStack (1);
346 location_stack_ = LocationStack (1);
2b548aa6 347
2b548aa6 348 /* Start. */
69e2658b
RA
349 state_ = 0;
350 looka_ = empty_;
8d69a1a3
RA
351#if YYLSP_NEEDED
352 location = initlocation_;
353#endif
717be197 354 YYCDEBUG << "Starting parse" << std::endl;
2b548aa6
RA
355
356 /* New state. */
357 yynewstate:
69e2658b 358 state_stack_.push (state_);
717be197 359 YYCDEBUG << "Entering state " << state_ << std::endl;
50997c6e 360 goto yybackup;
2b548aa6
RA
361
362 /* Backup. */
363 yybackup:
364
365 /* Try to take a decision without lookahead. */
c5e3e510 366 n_ = pact_[state_];
12b0043a 367 if (n_ == pact_ninf_)
2b548aa6
RA
368 goto yydefault;
369
370 /* Read a lookahead token. */
69e2658b 371 if (looka_ == empty_)
2b548aa6 372 {
717be197 373 YYCDEBUG << "Reading a token: ";
69e2658b 374 lex_ ();
2b548aa6
RA
375 }
376
377 /* Convert token to internal form. */
69e2658b 378 if (looka_ <= 0)
2b548aa6 379 {
69e2658b
RA
380 looka_ = eof_;
381 ilooka_ = 0;
717be197 382 YYCDEBUG << "Now at end of input." << std::endl;
2b548aa6
RA
383 }
384 else
385 {
69e2658b 386 ilooka_ = translate_ (looka_);
50997c6e
RA
387#if YYDEBUG
388 if (debug_)
389 {
717be197 390 YYCDEBUG << "Next token is " << looka_
c5e3e510 391 << " (" << name_[ilooka_];
4aacc3a7 392 print_ ();
717be197 393 YYCDEBUG << ')' << std::endl;
50997c6e 394 }
2b548aa6
RA
395#endif
396 }
397
69e2658b 398 n_ += ilooka_;
c5e3e510 399 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
2b548aa6
RA
400 goto yydefault;
401
402 /* Reduce or error. */
c5e3e510 403 n_ = table_[n_];
69e2658b 404 if (n_ < 0)
2b548aa6 405 {
12b0043a 406 if (n_ == table_ninf_)
2b548aa6
RA
407 goto yyerrlab;
408 else
409 {
69e2658b 410 n_ = -n_;
2b548aa6
RA
411 goto yyreduce;
412 }
413 }
69e2658b 414 else if (n_ == 0)
2b548aa6 415 goto yyerrlab;
a75c057f 416
2b548aa6 417 /* Accept? */
69e2658b 418 if (n_ == final_)
2b548aa6
RA
419 goto yyacceptlab;
420
421 /* Shift the lookahead token. */
fc049e9c 422#if YYDEBUG
717be197 423 YYCDEBUG << "Shifting token " << looka_
fc049e9c
AD
424 << " (" << name_[ilooka_] << "), ";
425#endif
2b548aa6
RA
426
427 /* Discard the token being shifted unless it is eof. */
69e2658b
RA
428 if (looka_ != eof_)
429 looka_ = empty_;
2b548aa6 430
69e2658b
RA
431 semantic_stack_.push (value);
432 location_stack_.push (location);
8d69a1a3
RA
433
434 /* Count tokens shifted since error; after three, turn off error
435 status. */
436 if (errstatus)
437 --errstatus;
438
69e2658b 439 state_ = n_;
2b548aa6
RA
440 goto yynewstate;
441
442 /* Default action. */
443 yydefault:
c5e3e510 444 n_ = defact_[state_];
69e2658b 445 if (n_ == 0)
2b548aa6 446 goto yyerrlab;
50997c6e 447 goto yyreduce;
2b548aa6
RA
448
449 /* Reduce. */
450 yyreduce:
c5e3e510 451 len_ = r2_[n_];
69e2658b 452 if (len_)
50997c6e 453 {
c5e3e510
AD
454 yyval = semantic_stack_[len_ - 1];
455 yyloc = location_stack_[len_ - 1];
50997c6e
RA
456 }
457 else
69e2658b 458 {
c5e3e510
AD
459 yyval = semantic_stack_[0];
460 yyloc = location_stack_[0];
50997c6e 461 }
2b548aa6 462
50997c6e
RA
463#if YYDEBUG
464 if (debug_)
2b548aa6 465 {
0d1c3a04
AD
466 // Short files will use "unsigned char" for line numbers,
467 // in which case they will be output as character litterals
468 // by "<<".
9b76b786 469 unsigned yylno = rline_[n_];
717be197 470 YYCDEBUG << "Reducing via rule " << n_ - 1
9b76b786 471 << " (line " << yylno << "), ";
c5e3e510
AD
472 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
473 0 <= rhs_[i]; ++i)
474 YYCDEBUG << name_[rhs_[i]] << ' ';
475 YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl;
2b548aa6
RA
476 }
477#endif
a75c057f 478
374f5a14
RA
479 if (len_)
480 {
481 Slice< LocationType, LocationStack > slice (location_stack_, len_);
482 YYLLOC_DEFAULT (yyloc, slice, len_);
483 }
484
45119f04
RA
485 switch (n_)
486 {
c5e3e510 487 ]b4_actions[
45119f04 488 }
a75c057f 489
996b1c7e 490]/* Line __line__ of lalr1.cc. */
c5e3e510 491b4_syncline([@oline@], [@ofile@])[
06446ccf 492
69e2658b
RA
493 state_stack_.pop (len_);
494 semantic_stack_.pop (len_);
495 location_stack_.pop (len_);
2b548aa6 496
50997c6e
RA
497#if YYDEBUG
498 if (debug_)
2b548aa6 499 {
717be197 500 YYCDEBUG << "state stack now";
a75c057f 501 for (StateStack::ConstIterator i = state_stack_.begin ();
69e2658b 502 i != state_stack_.end (); ++i)
717be197
AD
503 YYCDEBUG << ' ' << *i;
504 YYCDEBUG << std::endl;
2b548aa6
RA
505 }
506#endif
a75c057f 507
374f5a14
RA
508 semantic_stack_.push (yyval);
509 location_stack_.push (yyloc);
2b548aa6
RA
510
511 /* Shift the result of the reduction. */
c5e3e510
AD
512 n_ = r1_[n_];
513 state_ = pgoto_[n_ - ntokens_] + state_stack_[0];
514 if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0])
515 state_ = table_[state_];
2b548aa6 516 else
c5e3e510 517 state_ = defgoto_[n_ - ntokens_];
2b548aa6
RA
518 goto yynewstate;
519
520 /* Report and recover from errors. This is very incomplete. */
521 yyerrlab:
4bb2bc3f
RA
522 /* If not already recovering from an error, report this error. */
523 if (!errstatus)
524 {
525 ++nerrs;
a75c057f 526
69e2658b 527#if YYERROR_VERBOSE
c5e3e510 528 n_ = pact_[state_];
12b0043a 529 if (pact_ninf_ < n_ && n_ < last_)
4bb2bc3f 530 {
6e649e65 531 message = "syntax error, unexpected ";
c5e3e510 532 message += name_[ilooka_];
4bb2bc3f
RA
533 {
534 int count = 0;
c4749565
AD
535 /* Start YYX at -YYN if negative to avoid negative indexes in
536 YYCHECK. */
537 int xbegin = n_ < 0 ? -n_ : 0;
538 /* Stay within bounds of both yycheck and yytname. */
539 int checklim = last_ - n_;
540 int xend = checklim < ntokens_ ? checklim : ntokens_;
541 for (int x = xbegin; x < xend; ++x)
c5e3e510 542 if (check_[x + n_] == x && x != terror_)
4bb2bc3f
RA
543 ++count;
544 if (count < 5)
545 {
546 count = 0;
c4749565 547 for (int x = xbegin; x < xend; ++x)
c5e3e510 548 if (check_[x + n_] == x && x != terror_)
4bb2bc3f 549 {
a75c057f 550 message += (!count++) ? ", expecting " : " or ";
c5e3e510 551 message += name_[x];
4bb2bc3f
RA
552 }
553 }
554 }
555 }
556 else
69e2658b 557#endif
6e649e65 558 message = "syntax error";
8d69a1a3 559 error_ ();
4bb2bc3f 560 }
762a801e 561 goto yyerrlab1;
a75c057f 562
60a777aa
AD
563
564 /*----------------------------------------------------.
565 | yyerrlab1 -- error raised explicitly by an action. |
566 `----------------------------------------------------*/
762a801e
RA
567 yyerrlab1:
568 if (errstatus == 3)
569 {
570 /* If just tried and failed to reuse lookahead token after an
571 error, discard it. */
572
573 /* Return failure if at end of input. */
69e2658b 574 if (looka_ == eof_)
762a801e 575 goto yyabortlab;
7548fed2 576#if YYDEBUG
717be197 577 YYCDEBUG << "Discarding token " << looka_
7548fed2
AD
578 << " (" << name_[ilooka_] << ")." << std::endl;
579#endif
69e2658b 580 looka_ = empty_;
762a801e
RA
581 }
582
583 /* Else will try to reuse lookahead token after shifting the error
584 token. */
585
586 errstatus = 3;
762a801e 587
769b430f
AD
588 for (;;)
589 {
c5e3e510 590 n_ = pact_[state_];
12b0043a 591 if (n_ != pact_ninf_)
769b430f
AD
592 {
593 n_ += terror_;
c5e3e510 594 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
769b430f 595 {
c5e3e510 596 n_ = table_[n_];
769b430f
AD
597 if (0 < n_)
598 break;
599 }
600 }
601
602 /* Pop the current state because it cannot handle the error token. */
3ae831b4 603 if (state_stack_.height () == 1)
769b430f 604 goto yyabortlab;
762a801e
RA
605
606#if YYDEBUG
769b430f
AD
607 if (debug_)
608 {
c5e3e510 609 if (stos_[state_] < ntokens_)
769b430f 610 {
717be197 611 YYCDEBUG << "Error: popping token "
c5e3e510
AD
612 << token_number_[stos_[state_]]
613 << " (" << name_[stos_[state_]];
769b430f 614# ifdef YYPRINT
c5e3e510 615 YYPRINT (stderr, token_number_[stos_[state_]],
769b430f
AD
616 semantic_stack_.top ());
617# endif
717be197 618 YYCDEBUG << ')' << std::endl;
769b430f
AD
619 }
620 else
621 {
717be197 622 YYCDEBUG << "Error: popping nonterminal ("
c5e3e510 623 << name_[stos_[state_]] << ')' << std::endl;
769b430f
AD
624 }
625 }
762a801e
RA
626#endif
627
c5e3e510 628 state_ = (state_stack_.pop (), state_stack_[0]);
769b430f
AD
629 semantic_stack_.pop ();
630 location_stack_.pop ();;
762a801e 631
769b430f
AD
632#if YYDEBUG
633 if (debug_)
634 {
717be197 635 YYCDEBUG << "Error: state stack now";
769b430f
AD
636 for (StateStack::ConstIterator i = state_stack_.begin ();
637 i != state_stack_.end (); ++i)
717be197
AD
638 YYCDEBUG << ' ' << *i;
639 YYCDEBUG << std::endl;
769b430f
AD
640 }
641#endif
762a801e 642 }
762a801e 643
69e2658b 644 if (n_ == final_)
762a801e
RA
645 goto yyacceptlab;
646
717be197 647 YYCDEBUG << "Shifting error token, ";
762a801e 648
69e2658b
RA
649 semantic_stack_.push (value);
650 location_stack_.push (location);
762a801e 651
69e2658b 652 state_ = n_;
762a801e
RA
653 goto yynewstate;
654
2b548aa6
RA
655 /* Accept. */
656 yyacceptlab:
657 return 0;
762a801e
RA
658
659 /* Abort. */
660 yyabortlab:
661 return 1;
2b548aa6
RA
662}
663
69e2658b 664void
c5e3e510 665yy::]b4_parser_class_name[::lex_ ()
69e2658b
RA
666{
667#if YYLSP_NEEDED
668 looka_ = yylex (&value, &location);
669#else
670 looka_ = yylex (&value);
671#endif
672}
673
c5e3e510 674/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6 675 STATE-NUM. */
0c3c1f98 676const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
c5e3e510
AD
677const ]b4_int_type_for([b4_pact])[
678yy::]b4_parser_class_name[::pact_[] =
2b548aa6 679{
c5e3e510 680 ]b4_pact[
2b548aa6
RA
681};
682
c5e3e510 683/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
684 doesn't specify something else to do. Zero means the default is an
685 error. */
c5e3e510
AD
686const ]b4_int_type_for([b4_defact])[
687yy::]b4_parser_class_name[::defact_[] =
2b548aa6 688{
c5e3e510 689 ]b4_defact[
2b548aa6
RA
690};
691
c5e3e510
AD
692/* YYPGOTO[NTERM-NUM]. */
693const ]b4_int_type_for([b4_pgoto])[
694yy::]b4_parser_class_name[::pgoto_[] =
2b548aa6 695{
c5e3e510 696 ]b4_pgoto[
2b548aa6
RA
697};
698
c5e3e510
AD
699/* YYDEFGOTO[NTERM-NUM]. */
700const ]b4_int_type_for([b4_defgoto])[
701yy::]b4_parser_class_name[::defgoto_[] =
2b548aa6 702{
c5e3e510 703 ]b4_defgoto[
2b548aa6
RA
704};
705
c5e3e510 706/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
707 positive, shift that token. If negative, reduce the rule which
708 number is the opposite. If zero, do what YYDEFACT says. */
0c3c1f98 709const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
c5e3e510
AD
710const ]b4_int_type_for([b4_table])[
711yy::]b4_parser_class_name[::table_[] =
2b548aa6 712{
c5e3e510 713 ]b4_table[
2b548aa6
RA
714};
715
716/* YYCHECK. */
c5e3e510
AD
717const ]b4_int_type_for([b4_check])[
718yy::]b4_parser_class_name[::check_[] =
2b548aa6 719{
c5e3e510 720 ]b4_check[
2b548aa6
RA
721};
722
769b430f 723#if YYDEBUG
c5e3e510 724/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f 725 symbol of state STATE-NUM. */
c5e3e510
AD
726const ]b4_int_type_for([b4_stos])[
727yy::]b4_parser_class_name[::stos_[] =
769b430f 728{
c5e3e510 729 ]b4_stos[
769b430f
AD
730};
731
c5e3e510 732/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
769b430f 733 to YYLEX-NUM. */
c5e3e510
AD
734const ]b4_int_type_for([b4_toknum])[
735yy::]b4_parser_class_name[::token_number_[] =
769b430f 736{
c5e3e510 737 ]b4_toknum[
769b430f
AD
738};
739#endif
740
c5e3e510
AD
741/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
742const ]b4_int_type_for([b4_r1])[
743yy::]b4_parser_class_name[::r1_[] =
2b548aa6 744{
c5e3e510 745 ]b4_r1[
2b548aa6
RA
746};
747
c5e3e510
AD
748/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
749const ]b4_int_type_for([b4_r2])[
750yy::]b4_parser_class_name[::r2_[] =
2b548aa6 751{
c5e3e510 752 ]b4_r2[
2b548aa6
RA
753};
754
69e2658b 755#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 756/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2b548aa6
RA
757 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
758const char*
c5e3e510 759const yy::]b4_parser_class_name[::name_[] =
2b548aa6 760{
c5e3e510 761 ]b4_tname[
2b548aa6 762};
69e2658b 763#endif
2b548aa6 764
69e2658b 765#if YYDEBUG
2b548aa6 766/* YYRHS -- A `-1'-separated list of the rules' RHS. */
c5e3e510
AD
767const yy::]b4_parser_class_name[::RhsNumberType
768yy::]b4_parser_class_name[::rhs_[] =
2b548aa6 769{
c5e3e510 770 ]b4_rhs[
2b548aa6
RA
771};
772
c5e3e510 773/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 774 YYRHS. */
c5e3e510
AD
775const ]b4_int_type_for([b4_prhs])[
776yy::]b4_parser_class_name[::prhs_[] =
2b548aa6 777{
c5e3e510 778 ]b4_prhs[
2b548aa6
RA
779};
780
c5e3e510
AD
781/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
782const ]b4_int_type_for([b4_rline])[
783yy::]b4_parser_class_name[::rline_[] =
69e2658b 784{
c5e3e510 785 ]b4_rline[
69e2658b
RA
786};
787#endif
788
2b548aa6 789/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
c5e3e510
AD
790yy::]b4_parser_class_name[::TokenNumberType
791yy::]b4_parser_class_name[::translate_ (int token)
2b548aa6 792{
a75c057f 793 static
680e8701 794 const TokenNumberType
c5e3e510 795 translate_[] =
2b548aa6 796 {
c5e3e510 797 ]b4_translate[
2b548aa6 798 };
007a50a4 799 if ((unsigned) token <= user_token_number_max_)
c5e3e510 800 return translate_[token];
007a50a4
AD
801 else
802 return undef_token_;
2b548aa6
RA
803}
804
c5e3e510
AD
805const int yy::]b4_parser_class_name[::eof_ = 0;
806const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
807const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
808const int yy::]b4_parser_class_name[::empty_ = -2;
809const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
810const int yy::]b4_parser_class_name[::terror_ = 1;
811const int yy::]b4_parser_class_name[::errcode_ = 256;
812const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
66d30cd4 813
c5e3e510
AD
814const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
815const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
2b548aa6 816
c5e3e510 817]b4_epilogue
21846f69 818dnl
6ad762a8 819@output stack.hh
7548fed2 820b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[
98254360 821
2b548aa6
RA
822#ifndef BISON_STACK_HH
823# define BISON_STACK_HH
824
45119f04 825#include <deque>
2b548aa6
RA
826
827namespace yy
828{
45119f04 829 template < class T, class S = std::deque< T > >
2b548aa6
RA
830 class Stack
831 {
832 public:
833
834 typedef typename S::iterator Iterator;
835 typedef typename S::const_iterator ConstIterator;
836
837 Stack () : seq_ ()
838 {
839 }
840
841 Stack (unsigned n) : seq_ (n)
842 {
843 }
844
845 inline
846 T&
c5e3e510 847 operator [] (unsigned index)
2b548aa6 848 {
c5e3e510 849 return seq_[index];
2b548aa6
RA
850 }
851
852 inline
853 const T&
c5e3e510 854 operator [] (unsigned index) const
2b548aa6 855 {
c5e3e510 856 return seq_[index];
2b548aa6
RA
857 }
858
859 inline
860 void
861 push (const T& t)
862 {
45119f04 863 seq_.push_front (t);
2b548aa6
RA
864 }
865
866 inline
867 void
868 pop (unsigned n = 1)
869 {
870 for (; n; --n)
45119f04 871 seq_.pop_front ();
2b548aa6
RA
872 }
873
762a801e
RA
874 inline
875 unsigned
876 height () const
877 {
878 return seq_.size ();
879 }
880
2b548aa6
RA
881 inline ConstIterator begin () const { return seq_.begin (); }
882 inline ConstIterator end () const { return seq_.end (); }
883
884 private:
885
886 S seq_;
887 };
374f5a14
RA
888
889 template < class T, class S = Stack< T > >
890 class Slice
891 {
892 public:
893
894 Slice (const S& stack,
895 unsigned range) : stack_ (stack),
896 range_ (range)
897 {
898 }
899
900 inline
901 const T&
c5e3e510 902 operator [] (unsigned index) const
374f5a14 903 {
c5e3e510 904 return stack_[range_ - index];
374f5a14
RA
905 }
906
907 private:
908
909 const S& stack_;
910 unsigned range_;
911 };
2b548aa6
RA
912}
913
c5e3e510 914#endif // not BISON_STACK_HH]
21846f69 915dnl
5d003116
AD
916@output position.hh
917b4_copyright([Position class for Bison C++ parsers], [2002, 2003])[
98254360 918
5d003116
AD
919/**
920 ** \file position.hh
921 ** Define the Location class.
922 */
923
924#ifndef BISON_POSITION_HH
925# define BISON_POSITION_HH
2b548aa6 926
7548fed2
AD
927# include <iostream>
928# include <string>
929
2b548aa6
RA
930namespace yy
931{
5d003116 932 /** \brief Abstract a Position. */
7548fed2 933 class Position
2b548aa6 934 {
7548fed2 935 public:
5d003116
AD
936 /** \brief Initial column number. */
937 static const unsigned int initial_column = 0;
938 /** \brief Initial line number. */
939 static const unsigned int initial_line = 1;
940
941 /** \name Ctor & dtor.
942 ** \{ */
943 public:
944 /** \brief Construct a Position. */
945 Position () :
946 filename (),
947 line (initial_line),
948 column (initial_column)
949 {
950 }
951 /** \} */
952
7548fed2 953
5d003116
AD
954 /** \name Line and Column related manipulators
955 ** \{ */
956 public:
957 /** \brief (line related) Advance to the LINES next lines. */
958 inline void lines (int lines = 1)
959 {
960 column = initial_column;
961 line += lines;
962 }
963
964 /** \brief (column related) Advance to the COLUMNS next columns. */
965 inline void columns (int columns = 1)
966 {
f939fc12
AD
967 int leftmost = initial_column;
968 int current = column;
969 if (leftmost <= current + columns)
2cdc240e
AD
970 column += columns;
971 else
972 column = initial_column;
5d003116
AD
973 }
974 /** \} */
975
976 public:
977 /** \brief File name to which this position refers. */
7548fed2 978 std::string filename;
5d003116
AD
979 /** \brief Current line number. */
980 unsigned int line;
981 /** \brief Current column number. */
982 unsigned int column;
2b548aa6
RA
983 };
984
5d003116
AD
985 /** \brief Add and assign a Position. */
986 inline const Position&
987 operator+= (Position& res, const int width)
988 {
989 res.columns (width);
990 return res;
991 }
992
993 /** \brief Add two Position objects. */
994 inline const Position
995 operator+ (const Position& begin, const int width)
996 {
997 Position res = begin;
998 return res += width;
999 }
1000
1001 /** \brief Add and assign a Position. */
1002 inline const Position&
1003 operator-= (Position& res, const int width)
1004 {
1005 return res += -width;
1006 }
1007
1008 /** \brief Add two Position objects. */
1009 inline const Position
1010 operator- (const Position& begin, const int width)
1011 {
1012 return begin + -width;
1013 }
1014
1015 /** \brief Intercept output stream redirection.
1016 ** \param ostr the destination output stream
1017 ** \param pos a reference to the Position to redirect
1018 */
7548fed2
AD
1019 inline std::ostream&
1020 operator<< (std::ostream& ostr, const Position& pos)
1021 {
1022 if (pos.filename != "")
1023 ostr << pos.filename << ':';
5d003116 1024 return ostr << pos.line << '.' << pos.column;
7548fed2
AD
1025 }
1026
5d003116
AD
1027}
1028#endif // not BISON_POSITION_HH]
1029@output location.hh
1030b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[
7548fed2 1031
5d003116
AD
1032/**
1033 ** \file location.hh
1034 ** Define the Location class.
1035 */
7548fed2 1036
5d003116
AD
1037#ifndef BISON_LOCATION_HH
1038# define BISON_LOCATION_HH
1039
1040# include <iostream>
1041# include <string>
1042# include "position.hh"
1043
1044namespace yy
1045{
1046
1047 /** \brief Abstract a Location. */
7548fed2 1048 class Location
2b548aa6 1049 {
5d003116
AD
1050 /** \name Ctor & dtor.
1051 ** \{ */
7548fed2 1052 public:
5d003116
AD
1053 /** \brief Construct a Location. */
1054 Location (void) :
1055 begin (),
1056 end ()
1057 {
1058 }
1059 /** \} */
1060
1061
1062 /** \name Line and Column related manipulators
1063 ** \{ */
1064 public:
1065 /** \brief Reset initial location to final location. */
1066 inline void step (void)
1067 {
1068 begin = end;
1069 }
1070
1071 /** \brief Extend the current location to the COLUMNS next columns. */
1072 inline void columns (unsigned columns = 1)
1073 {
1074 end += columns;
1075 }
1076
1077 /** \brief Extend the current location to the LINES next lines. */
1078 inline void lines (unsigned lines = 1)
1079 {
1080 end.lines (lines);
1081 }
1082 /** \} */
1083
1084
1085 public:
1086 /** \brief Beginning of the located region. */
7548fed2 1087 Position begin;
5d003116 1088 /** \brief End of the located region. */
7548fed2 1089 Position end;
2b548aa6 1090 };
7548fed2 1091
5d003116
AD
1092 /** \brief Join two Location objects to create a Location. */
1093 inline const Location operator+ (const Location& begin, const Location& end)
1094 {
1095 Location res = begin;
1096 res.end = end.end;
1097 return res;
1098 }
1099
1100 /** \brief Add two Location objects */
1101 inline const Location operator+ (const Location& begin, unsigned width)
1102 {
1103 Location res = begin;
1104 res.columns (width);
1105 return res;
1106 }
7548fed2 1107
5d003116
AD
1108 /** \brief Add and assign a Location */
1109 inline Location &operator+= (Location& res, unsigned width)
1110 {
1111 res.columns (width);
1112 return res;
1113 }
1114
1115 /** \brief Intercept output stream redirection.
1116 ** \param ostr the destination output stream
2cdc240e 1117 ** \param loc a reference to the Location to redirect
5d003116 1118 **
2cdc240e 1119 ** Avoid duplicate information.
5d003116 1120 */
2cdc240e 1121 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
7548fed2 1122 {
2cdc240e
AD
1123 Position last = loc.end - 1;
1124 ostr << loc.begin;
1125 if (loc.begin.filename != last.filename)
1126 ostr << '-' << last;
1127 else if (loc.begin.line != last.line)
1128 ostr << '-' << last.line << '.' << last.column;
1129 else if (loc.begin.column != last.column)
1130 ostr << '-' << last.column;
7548fed2
AD
1131 return ostr;
1132 }
1133
2b548aa6
RA
1134}
1135
c5e3e510 1136#endif // not BISON_LOCATION_HH]