]> git.saurik.com Git - bison.git/blame_incremental - data/lalr1.cc
Remove PARAMS and upgrade to latest obstack.h.
[bison.git] / data / lalr1.cc
... / ...
CommitLineData
1m4_divert(-1)
2# C++ skeleton for Bison
3# Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
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
20## ---------------- ##
21## Default values. ##
22## ---------------- ##
23
24# Default Parser class name.
25m4_define_default([b4_parser_class_name], [Parser])
26
27
28
29## ----------------- ##
30## Semantic Values. ##
31## ----------------- ##
32
33
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],
46[semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
47
48m4_define_default([b4_location_type], [Location])
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],
62[location_stack_@{m4_eval([$1 - $2])@}])
63
64
65m4_define([b4_inherit],
66 [m4_ifdef([b4_root],
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
83
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
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
125# We do want M4 expansion after # for CPP macros.
126m4_changecom()
127m4_divert(0)dnl
128m4_if(b4_defines_flag, 0, [],
129[@output @output_header_name@
130b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
131 [2002, 2003, 2004])[
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
136
137#include "stack.hh"
138#include "location.hh"
139
140#include <string>
141#include <iostream>
142
143/* Using locations. */
144#define YYLSP_NEEDED ]b4_locations_flag[
145
146]b4_token_defines(b4_tokens)[
147
148/* Copy the first part of user declarations. */
149]b4_pre_prologue[
150
151]/* Line __line__ of lalr1.cc. */
152b4_syncline([@oline@], [@ofile@])[
153
154/* Enabling traces. */
155#ifndef YYDEBUG
156# define YYDEBUG ]b4_debug[
157#endif
158
159/* Enabling verbose error message. */
160#ifndef YYERROR_VERBOSE
161# define YYERROR_VERBOSE ]b4_error_verbose[
162#endif
163
164#ifndef YYSTYPE
165]m4_ifdef([b4_stype],
166[b4_syncline([b4_stype_line], [b4_filename])
167typedef union b4_stype yystype;
168/* Line __line__ of lalr1.cc. */
169b4_syncline([@oline@], [@ofile@])],
170[typedef int yystype;])[
171# define YYSTYPE yystype
172#endif
173
174/* Copy the second part of user declarations. */
175]b4_post_prologue[
176
177]/* Line __line__ of lalr1.cc. */
178b4_syncline([@oline@], [@ofile@])[
179#ifndef YYLLOC_DEFAULT
180# define YYLLOC_DEFAULT(Current, Rhs, N) \
181 ((Current).end = Rhs[N].end)
182#endif
183
184namespace yy
185{
186 class ]b4_parser_class_name[;
187
188 template < typename P >
189 struct Traits
190 {
191 };
192
193 template < >
194 struct Traits< ]b4_parser_class_name[ >
195 {
196 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
197 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
198 typedef int StateType;
199 typedef yystype SemanticType;
200 typedef ]b4_location_type[ LocationType;
201 };
202}
203
204namespace yy
205{
206 class ]b4_parser_class_name b4_inherit[
207 {
208 public:
209
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;
215
216 typedef Stack< StateType > StateStack;
217 typedef Stack< SemanticType > SemanticStack;
218 typedef Stack< LocationType > LocationStack;
219
220#if YYLSP_NEEDED
221 ]b4_parser_class_name[ (bool debug,
222 LocationType initlocation][]b4_param[]b4_parse_param_decl[) :
223 ]b4_constructor[][debug_ (debug),
224 cdebug_ (std::cerr),
225 initlocation_ (initlocation)]b4_parse_param_cons[
226#else
227 ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
228 ]b4_constructor[][debug_ (debug),
229 cdebug_ (std::cerr)]b4_parse_param_cons[
230#endif
231 {
232 }
233
234 virtual ~]b4_parser_class_name[ ()
235 {
236 }
237
238 virtual int parse ();
239
240 private:
241
242 virtual void lex_ ();
243 virtual void error_ ();
244 virtual void print_ ();
245 virtual void report_syntax_error_ ();
246
247 /* Stacks. */
248 StateStack state_stack_;
249 SemanticStack semantic_stack_;
250 LocationStack location_stack_;
251
252 /* Tables. */
253 static const ]b4_int_type_for([b4_pact])[ pact_[];
254 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ pact_ninf_;
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_[];
259 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ table_ninf_;
260 static const ]b4_int_type_for([b4_check])[ check_[];
261 static const ]b4_int_type_for([b4_stos])[ stos_[];
262 static const ]b4_int_type_for([b4_r1])[ r1_[];
263 static const ]b4_int_type_for([b4_r2])[ r2_[];
264
265#if YYDEBUG || YYERROR_VERBOSE
266 static const char* const name_[];
267#endif
268
269 /* More tables, for debugging. */
270#if YYDEBUG
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_[];
274 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
275 virtual void reduce_print_ (int yyrule);
276 virtual void stack_print_ ();
277#endif
278
279 /* Even more tables. */
280 static inline TokenNumberType translate_ (int token);
281 static inline void destruct_ (int yytype, SemanticType *yyvaluep,
282 LocationType *yylocationp);
283
284 /* Constants. */
285 static const int eof_;
286 /* LAST_ -- Last index in TABLE_. */
287 static const int last_;
288 static const int nnts_;
289 static const int empty_;
290 static const int final_;
291 static const int terror_;
292 static const int errcode_;
293 static const int ntokens_;
294 static const unsigned int user_token_number_max_;
295 static const TokenNumberType undef_token_;
296
297 /* State. */
298 int n_;
299 int len_;
300 int state_;
301
302 /* Error handling. */
303 int nerrs_;
304 int errstatus_;
305
306 /* Debugging. */
307 int debug_;
308 std::ostream &cdebug_;
309
310 /* Lookahead and lookahead in internal form. */
311 int looka_;
312 int ilooka_;
313
314 /* Message. */
315 std::string message;
316
317 /* Semantic value and location of lookahead token. */
318 SemanticType value;
319 LocationType location;
320 /* Beginning of the last erroneous token popped off. */
321 Position error_start_;
322
323 /* @@$ and $$. */
324 SemanticType yyval;
325 LocationType yyloc;
326
327 /* Initial location. */
328 LocationType initlocation_;
329]b4_parse_param_vars[
330 };
331}
332
333#endif /* ! defined PARSER_HEADER_H */]
334])dnl
335@output @output_parser_name@
336b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
337 [2002, 2003, 2004])
338
339m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
340
341/* Enable debugging if requested. */
342#if YYDEBUG
343# define YYCDEBUG if (debug_) cdebug_
344# define YY_REDUCE_PRINT(Rule) \
345do { \
346 if (debug_) \
347 reduce_print_ (Rule); \
348} while (0)
349# define YY_STACK_PRINT() \
350do { \
351 if (debug_) \
352 stack_print_ (); \
353} while (0)
354#else /* !YYDEBUG */
355# define YYCDEBUG if (0) cdebug_
356# define YY_REDUCE_PRINT(Rule)
357# define YY_STACK_PRINT()
358#endif /* !YYDEBUG */
359
360#define YYACCEPT goto yyacceptlab
361#define YYABORT goto yyabortlab
362#define YYERROR goto yyerrorlab
363
364]b4_yydestruct_generate([b4_cxx_destruct_def])[
365
366int
367yy::]b4_parser_class_name[::parse ()
368{
369 nerrs_ = 0;
370 errstatus_ = 0;
371
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. */
376 state_stack_ = StateStack (0);
377 semantic_stack_ = SemanticStack (1);
378 location_stack_ = LocationStack (1);
379
380 /* Start. */
381 state_ = 0;
382 looka_ = empty_;
383#if YYLSP_NEEDED
384 location = initlocation_;
385#endif
386 YYCDEBUG << "Starting parse" << std::endl;
387
388 /* New state. */
389 yynewstate:
390 state_stack_.push (state_);
391 YYCDEBUG << "Entering state " << state_ << std::endl;
392 goto yybackup;
393
394 /* Backup. */
395 yybackup:
396
397 /* Try to take a decision without lookahead. */
398 n_ = pact_[state_];
399 if (n_ == pact_ninf_)
400 goto yydefault;
401
402 /* Read a lookahead token. */
403 if (looka_ == empty_)
404 {
405 YYCDEBUG << "Reading a token: ";
406 lex_ ();
407 }
408
409 /* Convert token to internal form. */
410 if (looka_ <= 0)
411 {
412 looka_ = eof_;
413 ilooka_ = 0;
414 YYCDEBUG << "Now at end of input." << std::endl;
415 }
416 else
417 {
418 ilooka_ = translate_ (looka_);
419#if YYDEBUG
420 if (debug_)
421 {
422 YYCDEBUG << "Next token is " << looka_
423 << " (" << name_[ilooka_];
424 print_ ();
425 YYCDEBUG << ')' << std::endl;
426 }
427#endif
428 }
429
430 /* If the proper action on seeing token YYTOKEN is to reduce or to
431 detect an error, take that action. */
432 n_ += ilooka_;
433 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
434 goto yydefault;
435
436 /* Reduce or error. */
437 n_ = table_[n_];
438 if (n_ < 0)
439 {
440 if (n_ == table_ninf_)
441 goto yyerrlab;
442 else
443 {
444 n_ = -n_;
445 goto yyreduce;
446 }
447 }
448 else if (n_ == 0)
449 goto yyerrlab;
450
451 /* Accept? */
452 if (n_ == final_)
453 goto yyacceptlab;
454
455 /* Shift the lookahead token. */
456#if YYDEBUG
457 YYCDEBUG << "Shifting token " << looka_
458 << " (" << name_[ilooka_] << "), ";
459#endif
460
461 /* Discard the token being shifted unless it is eof. */
462 if (looka_ != eof_)
463 looka_ = empty_;
464
465 semantic_stack_.push (value);
466 location_stack_.push (location);
467
468 /* Count tokens shifted since error; after three, turn off error
469 status. */
470 if (errstatus_)
471 --errstatus_;
472
473 state_ = n_;
474 goto yynewstate;
475
476/*-----------------------------------------------------------.
477| yydefault -- do the default action for the current state. |
478`-----------------------------------------------------------*/
479 yydefault:
480 n_ = defact_[state_];
481 if (n_ == 0)
482 goto yyerrlab;
483 goto yyreduce;
484
485/*-----------------------------.
486| yyreduce -- Do a reduction. |
487`-----------------------------*/
488 yyreduce:
489 len_ = r2_[n_];
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. */
496 if (len_)
497 {
498 yyval = semantic_stack_[len_ - 1];
499 yyloc = location_stack_[len_ - 1];
500 }
501 else
502 {
503 yyval = semantic_stack_[0];
504 yyloc = location_stack_[0];
505 }
506
507 if (len_)
508 {
509 Slice< LocationType, LocationStack > slice (location_stack_, len_);
510 YYLLOC_DEFAULT (yyloc, slice, len_);
511 }
512 YY_REDUCE_PRINT (n_);
513 switch (n_)
514 {
515 ]b4_actions[
516 }
517
518]/* Line __line__ of lalr1.cc. */
519b4_syncline([@oline@], [@ofile@])[
520
521 state_stack_.pop (len_);
522 semantic_stack_.pop (len_);
523 location_stack_.pop (len_);
524
525 YY_STACK_PRINT ();
526
527 semantic_stack_.push (yyval);
528 location_stack_.push (yyloc);
529
530 /* Shift the result of the reduction. */
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_];
535 else
536 state_ = defgoto_[n_ - ntokens_];
537 goto yynewstate;
538
539/*------------------------------------.
540| yyerrlab -- here on detecting error |
541`------------------------------------*/
542 yyerrlab:
543 /* If not already recovering from an error, report this error. */
544 report_syntax_error_ ();
545
546 error_start_ = location.begin;
547 if (errstatus_ == 3)
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. */
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 {
560 error_start_ = location_stack_[0].begin;
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);
567 destruct_ (stos_[state_stack_[0]],
568 &semantic_stack_[0],
569 &location_stack_[0]);
570 }
571 }
572 else
573 {
574#if YYDEBUG
575 YYCDEBUG << "Discarding token " << looka_
576 << " (" << name_[ilooka_] << ")." << std::endl;
577#endif
578 destruct_ (ilooka_, &value, &location);
579 looka_ = empty_;
580 }
581 }
582
583 /* Else will try to reuse lookahead token after shifting the error
584 token. */
585 goto yyerrlab1;
586
587
588/*---------------------------------------------------.
589| yyerrorlab -- error raised explicitly by YYERROR. |
590`---------------------------------------------------*/
591yyerrorlab:
592
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
600 state_stack_.pop (len_);
601 semantic_stack_.pop (len_);
602 error_start_ = location_stack_[len_ - 1].begin;
603 location_stack_.pop (len_);
604 state_ = state_stack_[0];
605 goto yyerrlab1;
606
607/*-------------------------------------------------------------.
608| yyerrlab1 -- common code for both syntax error and YYERROR. |
609`-------------------------------------------------------------*/
610yyerrlab1:
611 errstatus_ = 3; /* Each real token shifted decrements this. */
612
613 for (;;)
614 {
615 n_ = pact_[state_];
616 if (n_ != pact_ninf_)
617 {
618 n_ += terror_;
619 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
620 {
621 n_ = table_[n_];
622 if (0 < n_)
623 break;
624 }
625 }
626
627 /* Pop the current state because it cannot handle the error token. */
628 if (state_stack_.height () == 1)
629 YYABORT;
630
631#if YYDEBUG
632 if (debug_)
633 {
634 if (stos_[state_] < ntokens_)
635 {
636 YYCDEBUG << "Error: popping token "
637 << token_number_[stos_[state_]]
638 << " (" << name_[stos_[state_]];
639# ifdef YYPRINT
640 YYPRINT (stderr, token_number_[stos_[state_]],
641 semantic_stack_.top ());
642# endif
643 YYCDEBUG << ')' << std::endl;
644 }
645 else
646 {
647 YYCDEBUG << "Error: popping nonterminal ("
648 << name_[stos_[state_]] << ')' << std::endl;
649 }
650 }
651#endif
652 destruct_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]);
653 error_start_ = location_stack_[0].begin;
654
655 state_stack_.pop ();
656 semantic_stack_.pop ();
657 location_stack_.pop ();
658 state_ = state_stack_[0];
659 YY_STACK_PRINT ();
660 }
661
662 if (n_ == final_)
663 goto yyacceptlab;
664
665 YYCDEBUG << "Shifting error token, ";
666
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 }
674
675 state_ = n_;
676 goto yynewstate;
677
678 /* Accept. */
679 yyacceptlab:
680 return 0;
681
682 /* Abort. */
683 yyabortlab:
684 return 1;
685}
686
687void
688yy::]b4_parser_class_name[::lex_ ()
689{
690#if YYLSP_NEEDED
691 looka_ = yylex (&value, &location);
692#else
693 looka_ = yylex (&value);
694#endif
695}
696
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
736
737/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
738 STATE-NUM. */
739const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
740const ]b4_int_type_for([b4_pact])[
741yy::]b4_parser_class_name[::pact_[] =
742{
743 ]b4_pact[
744};
745
746/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
747 doesn't specify something else to do. Zero means the default is an
748 error. */
749const ]b4_int_type_for([b4_defact])[
750yy::]b4_parser_class_name[::defact_[] =
751{
752 ]b4_defact[
753};
754
755/* YYPGOTO[NTERM-NUM]. */
756const ]b4_int_type_for([b4_pgoto])[
757yy::]b4_parser_class_name[::pgoto_[] =
758{
759 ]b4_pgoto[
760};
761
762/* YYDEFGOTO[NTERM-NUM]. */
763const ]b4_int_type_for([b4_defgoto])[
764yy::]b4_parser_class_name[::defgoto_[] =
765{
766 ]b4_defgoto[
767};
768
769/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
770 positive, shift that token. If negative, reduce the rule which
771 number is the opposite. If zero, do what YYDEFACT says. */
772const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
773const ]b4_int_type_for([b4_table])[
774yy::]b4_parser_class_name[::table_[] =
775{
776 ]b4_table[
777};
778
779/* YYCHECK. */
780const ]b4_int_type_for([b4_check])[
781yy::]b4_parser_class_name[::check_[] =
782{
783 ]b4_check[
784};
785
786/* STOS_[STATE-NUM] -- The (internal number of the) accessing
787 symbol of state STATE-NUM. */
788const ]b4_int_type_for([b4_stos])[
789yy::]b4_parser_class_name[::stos_[] =
790{
791 ]b4_stos[
792};
793
794#if YYDEBUG
795/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
796 to YYLEX-NUM. */
797const ]b4_int_type_for([b4_toknum])[
798yy::]b4_parser_class_name[::token_number_[] =
799{
800 ]b4_toknum[
801};
802#endif
803
804/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
805const ]b4_int_type_for([b4_r1])[
806yy::]b4_parser_class_name[::r1_[] =
807{
808 ]b4_r1[
809};
810
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_[] =
814{
815 ]b4_r2[
816};
817
818#if YYDEBUG || YYERROR_VERBOSE
819/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
820 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
821const char*
822const yy::]b4_parser_class_name[::name_[] =
823{
824 ]b4_tname[
825};
826#endif
827
828#if YYDEBUG
829/* YYRHS -- A `-1'-separated list of the rules' RHS. */
830const yy::]b4_parser_class_name[::RhsNumberType
831yy::]b4_parser_class_name[::rhs_[] =
832{
833 ]b4_rhs[
834};
835
836/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
837 YYRHS. */
838const ]b4_int_type_for([b4_prhs])[
839yy::]b4_parser_class_name[::prhs_[] =
840{
841 ]b4_prhs[
842};
843
844/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
845const ]b4_int_type_for([b4_rline])[
846yy::]b4_parser_class_name[::rline_[] =
847{
848 ]b4_rline[
849};
850
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
863/** Report that the YYRULE is going to be reduced. */
864
865void
866yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
867{
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
877
878/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
879yy::]b4_parser_class_name[::TokenNumberType
880yy::]b4_parser_class_name[::translate_ (int token)
881{
882 static
883 const TokenNumberType
884 translate_table[] =
885 {
886 ]b4_translate[
887 };
888 if ((unsigned int) token <= user_token_number_max_)
889 return translate_table[token];
890 else
891 return undef_token_;
892}
893
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[;
902
903const unsigned int yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
904const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
905
906]b4_epilogue
907dnl
908@output stack.hh
909b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003, 2004])[
910
911#ifndef BISON_STACK_HH
912# define BISON_STACK_HH
913
914#include <deque>
915
916namespace yy
917{
918 template < class T, class S = std::deque< T > >
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
930 Stack (unsigned int n) : seq_ (n)
931 {
932 }
933
934 inline
935 T&
936 operator [] (unsigned int i)
937 {
938 return seq_[i];
939 }
940
941 inline
942 const T&
943 operator [] (unsigned int i) const
944 {
945 return seq_[i];
946 }
947
948 inline
949 void
950 push (const T& t)
951 {
952 seq_.push_front (t);
953 }
954
955 inline
956 void
957 pop (unsigned int n = 1)
958 {
959 for (; n; --n)
960 seq_.pop_front ();
961 }
962
963 inline
964 unsigned int
965 height () const
966 {
967 return seq_.size ();
968 }
969
970 inline ConstIterator begin () const { return seq_.begin (); }
971 inline ConstIterator end () const { return seq_.end (); }
972
973 private:
974
975 S seq_;
976 };
977
978 template < class T, class S = Stack< T > >
979 class Slice
980 {
981 public:
982
983 Slice (const S& stack,
984 unsigned int range) : stack_ (stack),
985 range_ (range)
986 {
987 }
988
989 inline
990 const T&
991 operator [] (unsigned int i) const
992 {
993 return stack_[range_ - i];
994 }
995
996 private:
997
998 const S& stack_;
999 unsigned int range_;
1000 };
1001}
1002
1003#endif // not BISON_STACK_HH]
1004dnl
1005@output position.hh
1006b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004])[
1007
1008/**
1009 ** \file position.hh
1010 ** Define the Location class.
1011 */
1012
1013#ifndef BISON_POSITION_HH
1014# define BISON_POSITION_HH
1015
1016# include <iostream>
1017# include <string>
1018
1019namespace yy
1020{
1021 /** \brief Abstract a Position. */
1022 class Position
1023 {
1024 public:
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
1042
1043 /** \name Line and Column related manipulators
1044 ** \{ */
1045 public:
1046 /** \brief (line related) Advance to the COUNT next lines. */
1047 inline void lines (int count = 1)
1048 {
1049 column = initial_column;
1050 line += count;
1051 }
1052
1053 /** \brief (column related) Advance to the COUNT next columns. */
1054 inline void columns (int count = 1)
1055 {
1056 int leftmost = initial_column;
1057 int current = column;
1058 if (leftmost <= current + count)
1059 column += count;
1060 else
1061 column = initial_column;
1062 }
1063 /** \} */
1064
1065 public:
1066 /** \brief File name to which this position refers. */
1067 std::string filename;
1068 /** \brief Current line number. */
1069 unsigned int line;
1070 /** \brief Current column number. */
1071 unsigned int column;
1072 };
1073
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 */
1108 inline std::ostream&
1109 operator<< (std::ostream& ostr, const Position& pos)
1110 {
1111 if (!pos.filename.empty ())
1112 ostr << pos.filename << ':';
1113 return ostr << pos.line << '.' << pos.column;
1114 }
1115
1116}
1117#endif // not BISON_POSITION_HH]
1118@output location.hh
1119b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004])[
1120
1121/**
1122 ** \file location.hh
1123 ** Define the Location class.
1124 */
1125
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. */
1137 class Location
1138 {
1139 /** \name Ctor & dtor.
1140 ** \{ */
1141 public:
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
1160 /** \brief Extend the current location to the COUNT next columns. */
1161 inline void columns (unsigned int count = 1)
1162 {
1163 end += count;
1164 }
1165
1166 /** \brief Extend the current location to the COUNT next lines. */
1167 inline void lines (unsigned int count = 1)
1168 {
1169 end.lines (count);
1170 }
1171 /** \} */
1172
1173
1174 public:
1175 /** \brief Beginning of the located region. */
1176 Position begin;
1177 /** \brief End of the located region. */
1178 Position end;
1179 };
1180
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 */
1190 inline const Location operator+ (const Location& begin, unsigned int width)
1191 {
1192 Location res = begin;
1193 res.columns (width);
1194 return res;
1195 }
1196
1197 /** \brief Add and assign a Location */
1198 inline Location &operator+= (Location& res, unsigned int width)
1199 {
1200 res.columns (width);
1201 return res;
1202 }
1203
1204 /** \brief Intercept output stream redirection.
1205 ** \param ostr the destination output stream
1206 ** \param loc a reference to the Location to redirect
1207 **
1208 ** Avoid duplicate information.
1209 */
1210 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
1211 {
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;
1220 return ostr;
1221 }
1222
1223}
1224
1225#endif // not BISON_LOCATION_HH]