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