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