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