]>
Commit | Line | Data |
---|---|---|
a75c057f | 1 | m4_divert(-1) |
60491a94 AD |
2 | # C++ skeleton for Bison |
3 | # Copyright (C) 2002 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 | ||
fb8135fa | 20 | m4_include([c.m4]) |
680e8701 | 21 | |
66d30cd4 AD |
22 | ## ---------------- ## |
23 | ## Default values. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | # Stack parameters. | |
27 | m4_define_default([b4_stack_depth_init], [200]) | |
28 | ||
29 | # Default Parser class name. | |
30 | m4_define_default([b4_parser_class_name], [Parser]) | |
31 | ||
32 | ||
33 | ||
34 | ## ----------------- ## | |
35 | ## Semantic Values. ## | |
36 | ## ----------------- ## | |
37 | ||
38 | ||
82b6cb3f AD |
39 | # b4_lhs_value([TYPE]) |
40 | # -------------------- | |
41 | # Expansion of $<TYPE>$. | |
42 | m4_define([b4_lhs_value], | |
43 | [yyval[]m4_ifval([$1], [.$1])]) | |
44 | ||
45 | ||
46 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
47 | # -------------------------------------- | |
48 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
49 | # symbols on RHS. | |
50 | m4_define([b4_rhs_value], | |
45119f04 | 51 | [semantic_stack_@<:@m4_eval([$1 - $2])@:>@m4_ifval([$3], [.$3])]) |
82b6cb3f | 52 | |
66d30cd4 | 53 | m4_define_default([b4_location_type], [Location]) |
82b6cb3f AD |
54 | |
55 | # b4_lhs_location() | |
56 | # ----------------- | |
57 | # Expansion of @$. | |
58 | m4_define([b4_lhs_location], | |
59 | [yyloc]) | |
60 | ||
61 | ||
62 | # b4_rhs_location(RULE-LENGTH, NUM) | |
63 | # --------------------------------- | |
64 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
65 | # on RHS. | |
66 | m4_define([b4_rhs_location], | |
45119f04 | 67 | [location_stack_@<:@m4_eval([$1 - $2])@:>@]) |
82b6cb3f AD |
68 | |
69 | ||
a75c057f AD |
70 | m4_define_default([b4_input_suffix], [.y]) |
71 | ||
72 | m4_define_default([b4_output_parser_suffix], | |
73 | [m4_translit(b4_input_suffix, [yY], [cC])]) | |
74 | ||
75 | m4_define_default([b4_output_parser_name], | |
76 | [b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]]) | |
77 | ||
78 | ||
79 | m4_define_default([b4_output_header_suffix], | |
80 | [m4_translit(b4_input_suffix, [yY], [hH])]) | |
81 | ||
82 | m4_define_default([b4_output_header_name], | |
83 | [b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]]) | |
84 | ||
85 | m4_define_default([b4_header_guard], | |
86 | [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name), | |
87 | [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) | |
88 | ||
af27eacb | 89 | m4_define([b4_inherit], |
0d8bed56 | 90 | [m4_ifdef([b4_root], |
af27eacb RA |
91 | [: public b4_root |
92 | ], | |
93 | [])]) | |
94 | ||
95 | m4_define([b4_param], | |
96 | [m4_ifdef([b4_root], | |
97 | [, | |
98 | const Param& param], | |
99 | [])]) | |
100 | ||
101 | m4_define([b4_constructor], | |
102 | [m4_ifdef([b4_root], | |
103 | [b4_root (param), | |
104 | ], | |
105 | [])]) | |
106 | ||
98254360 RA |
107 | |
108 | m4_divert(0)dnl | |
109 | #output "b4_output_header_name" | |
fb8135fa AD |
110 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
111 | [2002]) | |
98254360 RA |
112 | #ifndef b4_header_guard |
113 | # define b4_header_guard | |
2b548aa6 RA |
114 | |
115 | #include "stack.hh" | |
2b548aa6 RA |
116 | #include "location.hh" |
117 | ||
8d69a1a3 | 118 | #include <string> |
717be197 | 119 | #include <iostream> |
50997c6e | 120 | |
4162fa07 RA |
121 | /* Using locations. */ |
122 | #define YYLSP_NEEDED b4_locations_flag | |
123 | ||
17acead5 PE |
124 | b4_token_defines(b4_tokens) |
125 | ||
0dd1580a RA |
126 | /* Copy the first part of user declarations. */ |
127 | b4_pre_prologue | |
4162fa07 | 128 | |
e96c9728 AD |
129 | /* Line __line__ of __file__. */ |
130 | #line __oline__ "__ofile__" | |
131 | ||
69e2658b RA |
132 | /* Enabling traces. */ |
133 | #ifndef YYDEBUG | |
134 | # define YYDEBUG b4_debug | |
135 | #endif | |
136 | ||
137 | /* Enabling verbose error message. */ | |
138 | #ifndef YYERROR_VERBOSE | |
139 | # define YYERROR_VERBOSE b4_error_verbose | |
140 | #endif | |
141 | ||
98254360 | 142 | #ifndef YYSTYPE |
e9955c83 | 143 | m4_ifdef([b4_stype], |
642cb8f8 | 144 | [#line b4_stype_line "b4_filename" |
e96c9728 AD |
145 | typedef union b4_stype yystype; |
146 | /* Line __line__ of __file__. */ | |
147 | #line __oline__ "__ofile__"], | |
e9955c83 | 148 | [typedef int yystype;]) |
98254360 RA |
149 | # define YYSTYPE yystype |
150 | #endif | |
151 | ||
0dd1580a RA |
152 | /* Copy the second part of user declarations. */ |
153 | b4_post_prologue | |
154 | ||
e96c9728 | 155 | /* Line __line__ of __file__. */ |
06446ccf | 156 | #line __oline__ "__ofile__" |
374f5a14 RA |
157 | #ifndef YYLLOC_DEFAULT |
158 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
159 | Current.last_line = Rhs[[N]].last_line; \ | |
160 | Current.last_column = Rhs[[N]].last_column; | |
161 | #endif | |
162 | ||
2b548aa6 RA |
163 | namespace yy |
164 | { | |
66d30cd4 | 165 | class b4_parser_class_name; |
3f3eed27 | 166 | |
2b548aa6 RA |
167 | template < typename P > |
168 | struct Traits | |
169 | { | |
170 | }; | |
171 | ||
172 | template < > | |
66d30cd4 | 173 | struct Traits< b4_parser_class_name > |
2b548aa6 | 174 | { |
a762e609 AD |
175 | typedef b4_int_type_for([b4_translate]) TokenNumberType; |
176 | typedef b4_int_type_for([b4_rhs]) RhsNumberType; | |
50997c6e RA |
177 | typedef int StateType; |
178 | typedef yystype SemanticType; | |
66d30cd4 | 179 | typedef b4_location_type LocationType; |
2b548aa6 RA |
180 | }; |
181 | } | |
182 | ||
2b548aa6 RA |
183 | namespace yy |
184 | { | |
66d30cd4 | 185 | class b4_parser_class_name b4_inherit |
2b548aa6 RA |
186 | { |
187 | public: | |
3f3eed27 | 188 | |
66d30cd4 AD |
189 | typedef Traits< b4_parser_class_name >::TokenNumberType TokenNumberType; |
190 | typedef Traits< b4_parser_class_name >::RhsNumberType RhsNumberType; | |
191 | typedef Traits< b4_parser_class_name >::StateType StateType; | |
192 | typedef Traits< b4_parser_class_name >::SemanticType SemanticType; | |
193 | typedef Traits< b4_parser_class_name >::LocationType LocationType; | |
2b548aa6 RA |
194 | |
195 | typedef Stack< StateType > StateStack; | |
196 | typedef Stack< SemanticType > SemanticStack; | |
197 | typedef Stack< LocationType > LocationStack; | |
198 | ||
8d69a1a3 | 199 | #if YYLSP_NEEDED |
66d30cd4 | 200 | b4_parser_class_name (bool debug, |
0d8bed56 | 201 | LocationType initlocation[]b4_param) : |
af27eacb | 202 | b4_constructor[]debug_ (debug), |
717be197 | 203 | cdebug_ (std::cerr), |
af27eacb | 204 | initlocation_ (initlocation) |
8d69a1a3 | 205 | #else |
66d30cd4 | 206 | b4_parser_class_name (bool debug[]b4_param) : |
717be197 AD |
207 | b4_constructor[]debug_ (debug), |
208 | cdebug_ (std::cerr) | |
8d69a1a3 | 209 | #endif |
50997c6e | 210 | { |
50997c6e RA |
211 | } |
212 | ||
66d30cd4 | 213 | virtual ~b4_parser_class_name () |
2b548aa6 | 214 | { |
2b548aa6 RA |
215 | } |
216 | ||
217 | virtual int parse (); | |
218 | ||
219 | private: | |
3f3eed27 | 220 | |
69e2658b | 221 | virtual void lex_ (); |
4bb2bc3f | 222 | virtual void error_ (); |
4aacc3a7 | 223 | virtual void print_ (); |
4bb2bc3f | 224 | |
2b548aa6 | 225 | /* Stacks. */ |
69e2658b RA |
226 | StateStack state_stack_; |
227 | SemanticStack semantic_stack_; | |
228 | LocationStack location_stack_; | |
2b548aa6 RA |
229 | |
230 | /* Tables. */ | |
a762e609 AD |
231 | static const b4_int_type_for([b4_pact]) pact_[[]]; |
232 | static const b4_int_type_for([b4_pact]) pact_ninf_; | |
233 | static const b4_int_type_for([b4_defact]) defact_[[]]; | |
234 | static const b4_int_type_for([b4_pgoto]) pgoto_[[]]; | |
235 | static const b4_int_type_for([b4_defgoto]) defgoto_[[]]; | |
236 | static const b4_int_type_for([b4_table]) table_[[]]; | |
237 | static const b4_int_type_for([b4_table]) table_ninf_; | |
238 | static const b4_int_type_for([b4_check]) check_[[]]; | |
239 | static const b4_int_type_for([b4_r1]) r1_[[]]; | |
240 | static const b4_int_type_for([b4_r2]) r2_[[]]; | |
69e2658b RA |
241 | |
242 | #if YYDEBUG || YYERROR_VERBOSE | |
3f3eed27 | 243 | static const char* const name_[[]]; |
69e2658b | 244 | #endif |
2b548aa6 RA |
245 | |
246 | /* More tables, for debugging. */ | |
69e2658b | 247 | #if YYDEBUG |
06446ccf | 248 | static const RhsNumberType rhs_[[]]; |
a762e609 AD |
249 | static const b4_int_type_for([b4_prhs]) prhs_[[]]; |
250 | static const b4_int_type_for([b4_rline]) rline_[[]]; | |
251 | static const b4_int_type_for([b4_stos]) stos_[[]]; | |
252 | static const b4_int_type_for([b4_toknum]) token_number_[[]]; | |
69e2658b | 253 | #endif |
2b548aa6 RA |
254 | |
255 | /* Even more tables. */ | |
680e8701 | 256 | static inline TokenNumberType translate_ (int token); |
2b548aa6 | 257 | |
762a801e | 258 | /* Constants. */ |
50997c6e | 259 | static const int eof_; |
39912f52 | 260 | /* LAST_ -- Last index in TABLE_. */ |
69e2658b | 261 | static const int last_; |
69e2658b | 262 | static const int nnts_; |
50997c6e | 263 | static const int empty_; |
69e2658b | 264 | static const int final_; |
762a801e RA |
265 | static const int terror_; |
266 | static const int errcode_; | |
50997c6e | 267 | static const int ntokens_; |
69e2658b | 268 | static const int initdepth_; |
007a50a4 AD |
269 | static const unsigned user_token_number_max_; |
270 | static const TokenNumberType undef_token_; | |
2b548aa6 RA |
271 | |
272 | /* State. */ | |
69e2658b RA |
273 | int n_; |
274 | int len_; | |
69e2658b | 275 | int state_; |
4bb2bc3f | 276 | |
717be197 AD |
277 | /* Debugging. */ |
278 | int debug_; | |
279 | std::ostream &cdebug_; | |
280 | ||
69e2658b RA |
281 | /* Lookahead and lookahead in internal form. */ |
282 | int looka_; | |
283 | int ilooka_; | |
4bb2bc3f RA |
284 | |
285 | /* Message. */ | |
286 | std::string message; | |
287 | ||
374f5a14 | 288 | /* Semantic value and location of lookahead token. */ |
2b548aa6 RA |
289 | SemanticType value; |
290 | LocationType location; | |
8d69a1a3 | 291 | |
374f5a14 RA |
292 | /* @$ and $$. */ |
293 | SemanticType yyval; | |
294 | LocationType yyloc; | |
295 | ||
8d69a1a3 RA |
296 | /* Initial location. */ |
297 | LocationType initlocation_; | |
2b548aa6 RA |
298 | }; |
299 | } | |
300 | ||
98254360 | 301 | #endif /* not b4_header_guard */ |
21846f69 | 302 | dnl |
3f3eed27 | 303 | #output "b4_output_prefix[]b4_output_infix[].cc" |
fb8135fa AD |
304 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
305 | [2002]) | |
98254360 RA |
306 | |
307 | #include "b4_output_header_name" | |
50997c6e | 308 | |
2b548aa6 | 309 | /* Enable debugging if requested. */ |
50997c6e | 310 | #if YYDEBUG |
717be197 | 311 | # define YYCDEBUG if (debug_) cdebug_ |
2b548aa6 | 312 | #else /* !YYDEBUG */ |
717be197 | 313 | # define YYCDEBUG if (0) cdebug_ |
2b548aa6 RA |
314 | #endif /* !YYDEBUG */ |
315 | ||
2b548aa6 | 316 | int |
66d30cd4 | 317 | yy::b4_parser_class_name::parse () |
2b548aa6 | 318 | { |
4bb2bc3f RA |
319 | int nerrs = 0; |
320 | int errstatus = 0; | |
321 | ||
2b548aa6 | 322 | /* Initialize stack. */ |
69e2658b RA |
323 | state_stack_ = StateStack (0); |
324 | semantic_stack_ = SemanticStack (1); | |
325 | location_stack_ = LocationStack (1); | |
2b548aa6 | 326 | |
2b548aa6 | 327 | /* Start. */ |
69e2658b RA |
328 | state_ = 0; |
329 | looka_ = empty_; | |
8d69a1a3 RA |
330 | #if YYLSP_NEEDED |
331 | location = initlocation_; | |
332 | #endif | |
717be197 | 333 | YYCDEBUG << "Starting parse" << std::endl; |
2b548aa6 RA |
334 | |
335 | /* New state. */ | |
336 | yynewstate: | |
69e2658b | 337 | state_stack_.push (state_); |
717be197 | 338 | YYCDEBUG << "Entering state " << state_ << std::endl; |
50997c6e | 339 | goto yybackup; |
2b548aa6 RA |
340 | |
341 | /* Backup. */ | |
342 | yybackup: | |
343 | ||
344 | /* Try to take a decision without lookahead. */ | |
69e2658b | 345 | n_ = pact_[[state_]]; |
12b0043a | 346 | if (n_ == pact_ninf_) |
2b548aa6 RA |
347 | goto yydefault; |
348 | ||
349 | /* Read a lookahead token. */ | |
69e2658b | 350 | if (looka_ == empty_) |
2b548aa6 | 351 | { |
717be197 | 352 | YYCDEBUG << "Reading a token: "; |
69e2658b | 353 | lex_ (); |
2b548aa6 RA |
354 | } |
355 | ||
356 | /* Convert token to internal form. */ | |
69e2658b | 357 | if (looka_ <= 0) |
2b548aa6 | 358 | { |
69e2658b RA |
359 | looka_ = eof_; |
360 | ilooka_ = 0; | |
717be197 | 361 | YYCDEBUG << "Now at end of input." << std::endl; |
2b548aa6 RA |
362 | } |
363 | else | |
364 | { | |
69e2658b | 365 | ilooka_ = translate_ (looka_); |
50997c6e RA |
366 | #if YYDEBUG |
367 | if (debug_) | |
368 | { | |
717be197 AD |
369 | YYCDEBUG << "Next token is " << looka_ |
370 | << " (" << name_[[ilooka_]]; | |
4aacc3a7 | 371 | print_ (); |
717be197 | 372 | YYCDEBUG << ')' << std::endl; |
50997c6e | 373 | } |
2b548aa6 RA |
374 | #endif |
375 | } | |
376 | ||
69e2658b | 377 | n_ += ilooka_; |
39912f52 | 378 | if (n_ < 0 || last_ < n_ || check_[[n_]] != ilooka_) |
2b548aa6 RA |
379 | goto yydefault; |
380 | ||
381 | /* Reduce or error. */ | |
69e2658b RA |
382 | n_ = table_[[n_]]; |
383 | if (n_ < 0) | |
2b548aa6 | 384 | { |
12b0043a | 385 | if (n_ == table_ninf_) |
2b548aa6 RA |
386 | goto yyerrlab; |
387 | else | |
388 | { | |
69e2658b | 389 | n_ = -n_; |
2b548aa6 RA |
390 | goto yyreduce; |
391 | } | |
392 | } | |
69e2658b | 393 | else if (n_ == 0) |
2b548aa6 | 394 | goto yyerrlab; |
a75c057f | 395 | |
2b548aa6 | 396 | /* Accept? */ |
69e2658b | 397 | if (n_ == final_) |
2b548aa6 RA |
398 | goto yyacceptlab; |
399 | ||
400 | /* Shift the lookahead token. */ | |
717be197 AD |
401 | YYCDEBUG << "Shifting token " << looka_ |
402 | << " (" << name_[[ilooka_]] << "), "; | |
2b548aa6 RA |
403 | |
404 | /* Discard the token being shifted unless it is eof. */ | |
69e2658b RA |
405 | if (looka_ != eof_) |
406 | looka_ = empty_; | |
2b548aa6 | 407 | |
69e2658b RA |
408 | semantic_stack_.push (value); |
409 | location_stack_.push (location); | |
8d69a1a3 RA |
410 | |
411 | /* Count tokens shifted since error; after three, turn off error | |
412 | status. */ | |
413 | if (errstatus) | |
414 | --errstatus; | |
415 | ||
69e2658b | 416 | state_ = n_; |
2b548aa6 RA |
417 | goto yynewstate; |
418 | ||
419 | /* Default action. */ | |
420 | yydefault: | |
69e2658b RA |
421 | n_ = defact_[[state_]]; |
422 | if (n_ == 0) | |
2b548aa6 | 423 | goto yyerrlab; |
50997c6e | 424 | goto yyreduce; |
2b548aa6 RA |
425 | |
426 | /* Reduce. */ | |
427 | yyreduce: | |
69e2658b RA |
428 | len_ = r2_[[n_]]; |
429 | if (len_) | |
50997c6e | 430 | { |
45119f04 RA |
431 | yyval = semantic_stack_[[len_ - 1]]; |
432 | yyloc = location_stack_[[len_ - 1]]; | |
50997c6e RA |
433 | } |
434 | else | |
69e2658b | 435 | { |
374f5a14 RA |
436 | yyval = semantic_stack_[[0]]; |
437 | yyloc = location_stack_[[0]]; | |
50997c6e | 438 | } |
2b548aa6 | 439 | |
50997c6e RA |
440 | #if YYDEBUG |
441 | if (debug_) | |
2b548aa6 | 442 | { |
717be197 AD |
443 | YYCDEBUG << "Reducing via rule " << n_ - 1 |
444 | << " (line " << rline_[[n_]] << "), "; | |
a762e609 | 445 | for (b4_int_type_for([b4_prhs]) i = prhs_[[n_]]; |
39912f52 | 446 | 0 <= rhs_[[i]]; ++i) |
717be197 AD |
447 | YYCDEBUG << name_[[rhs_[i]]] << ' '; |
448 | YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl; | |
2b548aa6 RA |
449 | } |
450 | #endif | |
a75c057f | 451 | |
374f5a14 RA |
452 | if (len_) |
453 | { | |
454 | Slice< LocationType, LocationStack > slice (location_stack_, len_); | |
455 | YYLLOC_DEFAULT (yyloc, slice, len_); | |
456 | } | |
457 | ||
45119f04 RA |
458 | switch (n_) |
459 | { | |
460 | b4_actions | |
461 | } | |
a75c057f | 462 | |
06446ccf AD |
463 | /* Line __line__ of __file__. */ |
464 | #line __oline__ "__ofile__" | |
465 | ||
69e2658b RA |
466 | state_stack_.pop (len_); |
467 | semantic_stack_.pop (len_); | |
468 | location_stack_.pop (len_); | |
2b548aa6 | 469 | |
50997c6e RA |
470 | #if YYDEBUG |
471 | if (debug_) | |
2b548aa6 | 472 | { |
717be197 | 473 | YYCDEBUG << "state stack now"; |
a75c057f | 474 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 475 | i != state_stack_.end (); ++i) |
717be197 AD |
476 | YYCDEBUG << ' ' << *i; |
477 | YYCDEBUG << std::endl; | |
2b548aa6 RA |
478 | } |
479 | #endif | |
a75c057f | 480 | |
374f5a14 RA |
481 | semantic_stack_.push (yyval); |
482 | location_stack_.push (yyloc); | |
2b548aa6 RA |
483 | |
484 | /* Shift the result of the reduction. */ | |
69e2658b RA |
485 | n_ = r1_[[n_]]; |
486 | state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]]; | |
39912f52 | 487 | if (0 <= state_ && state_ <= last_ && check_[[state_]] == state_stack_[[0]]) |
69e2658b | 488 | state_ = table_[[state_]]; |
2b548aa6 | 489 | else |
69e2658b | 490 | state_ = defgoto_[[n_ - ntokens_]]; |
2b548aa6 RA |
491 | goto yynewstate; |
492 | ||
493 | /* Report and recover from errors. This is very incomplete. */ | |
494 | yyerrlab: | |
4bb2bc3f RA |
495 | /* If not already recovering from an error, report this error. */ |
496 | if (!errstatus) | |
497 | { | |
498 | ++nerrs; | |
a75c057f | 499 | |
69e2658b RA |
500 | #if YYERROR_VERBOSE |
501 | n_ = pact_[[state_]]; | |
12b0043a | 502 | if (pact_ninf_ < n_ && n_ < last_) |
4bb2bc3f RA |
503 | { |
504 | message = "parse error, unexpected "; | |
69e2658b | 505 | message += name_[[ilooka_]]; |
4bb2bc3f RA |
506 | { |
507 | int count = 0; | |
69e2658b | 508 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
217598da | 509 | if (check_[[x + n_]] == x && x != terror_) |
4bb2bc3f RA |
510 | ++count; |
511 | if (count < 5) | |
512 | { | |
513 | count = 0; | |
69e2658b | 514 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
217598da | 515 | if (check_[[x + n_]] == x && x != terror_) |
4bb2bc3f | 516 | { |
a75c057f | 517 | message += (!count++) ? ", expecting " : " or "; |
4bb2bc3f RA |
518 | message += name_[[x]]; |
519 | } | |
520 | } | |
521 | } | |
522 | } | |
523 | else | |
69e2658b | 524 | #endif |
4bb2bc3f | 525 | message = "parse error"; |
8d69a1a3 | 526 | error_ (); |
4bb2bc3f | 527 | } |
762a801e | 528 | goto yyerrlab1; |
a75c057f | 529 | |
762a801e RA |
530 | /* Error raised explicitly by an action. */ |
531 | yyerrlab1: | |
532 | if (errstatus == 3) | |
533 | { | |
534 | /* If just tried and failed to reuse lookahead token after an | |
535 | error, discard it. */ | |
536 | ||
537 | /* Return failure if at end of input. */ | |
69e2658b | 538 | if (looka_ == eof_) |
762a801e | 539 | goto yyabortlab; |
717be197 AD |
540 | YYCDEBUG << "Discarding token " << looka_ |
541 | << " (" << name_[[ilooka_]] << ")." << std::endl; | |
69e2658b | 542 | looka_ = empty_; |
762a801e RA |
543 | } |
544 | ||
545 | /* Else will try to reuse lookahead token after shifting the error | |
546 | token. */ | |
547 | ||
548 | errstatus = 3; | |
762a801e | 549 | |
769b430f AD |
550 | for (;;) |
551 | { | |
552 | n_ = pact_[[state_]]; | |
12b0043a | 553 | if (n_ != pact_ninf_) |
769b430f AD |
554 | { |
555 | n_ += terror_; | |
556 | if (0 <= n_ && n_ <= last_ && check_[[n_]] == terror_) | |
557 | { | |
558 | n_ = table_[[n_]]; | |
559 | if (0 < n_) | |
560 | break; | |
561 | } | |
562 | } | |
563 | ||
564 | /* Pop the current state because it cannot handle the error token. */ | |
565 | if (!state_stack_.height ()) | |
566 | goto yyabortlab; | |
762a801e RA |
567 | |
568 | #if YYDEBUG | |
769b430f AD |
569 | if (debug_) |
570 | { | |
571 | if (stos_[[state_]] < ntokens_) | |
572 | { | |
717be197 AD |
573 | YYCDEBUG << "Error: popping token " |
574 | << token_number_[[stos_[state_]]] | |
575 | << " (" << name_[[stos_[state_]]]; | |
769b430f AD |
576 | # ifdef YYPRINT |
577 | YYPRINT (stderr, token_number_[[stos_[state_]]], | |
578 | semantic_stack_.top ()); | |
579 | # endif | |
717be197 | 580 | YYCDEBUG << ')' << std::endl; |
769b430f AD |
581 | } |
582 | else | |
583 | { | |
717be197 AD |
584 | YYCDEBUG << "Error: popping nonterminal (" |
585 | << name_[[stos_[state_]]] << ')' << std::endl; | |
769b430f AD |
586 | } |
587 | } | |
762a801e RA |
588 | #endif |
589 | ||
769b430f AD |
590 | state_ = (state_stack_.pop (), state_stack_[[0]]); |
591 | semantic_stack_.pop (); | |
592 | location_stack_.pop ();; | |
762a801e | 593 | |
769b430f AD |
594 | #if YYDEBUG |
595 | if (debug_) | |
596 | { | |
717be197 | 597 | YYCDEBUG << "Error: state stack now"; |
769b430f AD |
598 | for (StateStack::ConstIterator i = state_stack_.begin (); |
599 | i != state_stack_.end (); ++i) | |
717be197 AD |
600 | YYCDEBUG << ' ' << *i; |
601 | YYCDEBUG << std::endl; | |
769b430f AD |
602 | } |
603 | #endif | |
762a801e | 604 | } |
762a801e | 605 | |
69e2658b | 606 | if (n_ == final_) |
762a801e RA |
607 | goto yyacceptlab; |
608 | ||
717be197 | 609 | YYCDEBUG << "Shifting error token, "; |
762a801e | 610 | |
69e2658b RA |
611 | semantic_stack_.push (value); |
612 | location_stack_.push (location); | |
762a801e | 613 | |
69e2658b | 614 | state_ = n_; |
762a801e RA |
615 | goto yynewstate; |
616 | ||
2b548aa6 RA |
617 | /* Accept. */ |
618 | yyacceptlab: | |
619 | return 0; | |
762a801e RA |
620 | |
621 | /* Abort. */ | |
622 | yyabortlab: | |
623 | return 1; | |
2b548aa6 RA |
624 | } |
625 | ||
69e2658b | 626 | void |
66d30cd4 | 627 | yy::b4_parser_class_name::lex_ () |
69e2658b RA |
628 | { |
629 | #if YYLSP_NEEDED | |
630 | looka_ = yylex (&value, &location); | |
631 | #else | |
632 | looka_ = yylex (&value); | |
633 | #endif | |
634 | } | |
635 | ||
6b45a3ca | 636 | /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing |
2b548aa6 | 637 | STATE-NUM. */ |
66d30cd4 | 638 | const b4_int_type_for([b4_pact]) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf; |
a762e609 | 639 | const b4_int_type_for([b4_pact]) |
66d30cd4 | 640 | yy::b4_parser_class_name::pact_[[]] = |
2b548aa6 | 641 | { |
3f3eed27 | 642 | b4_pact |
2b548aa6 RA |
643 | }; |
644 | ||
6b45a3ca | 645 | /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
646 | doesn't specify something else to do. Zero means the default is an |
647 | error. */ | |
a762e609 | 648 | const b4_int_type_for([b4_defact]) |
66d30cd4 | 649 | yy::b4_parser_class_name::defact_[[]] = |
2b548aa6 | 650 | { |
3f3eed27 | 651 | b4_defact |
2b548aa6 RA |
652 | }; |
653 | ||
6b45a3ca | 654 | /* YYPGOTO[[NTERM-NUM]]. */ |
a762e609 | 655 | const b4_int_type_for([b4_pgoto]) |
66d30cd4 | 656 | yy::b4_parser_class_name::pgoto_[[]] = |
2b548aa6 | 657 | { |
3f3eed27 | 658 | b4_pgoto |
2b548aa6 RA |
659 | }; |
660 | ||
6b45a3ca | 661 | /* YYDEFGOTO[[NTERM-NUM]]. */ |
a762e609 | 662 | const b4_int_type_for([b4_defgoto]) |
66d30cd4 | 663 | yy::b4_parser_class_name::defgoto_[[]] = |
2b548aa6 | 664 | { |
3f3eed27 | 665 | b4_defgoto |
2b548aa6 RA |
666 | }; |
667 | ||
6b45a3ca | 668 | /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
669 | positive, shift that token. If negative, reduce the rule which |
670 | number is the opposite. If zero, do what YYDEFACT says. */ | |
66d30cd4 | 671 | const b4_int_type_for([b4_table]) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf; |
a762e609 | 672 | const b4_int_type_for([b4_table]) |
66d30cd4 | 673 | yy::b4_parser_class_name::table_[[]] = |
2b548aa6 | 674 | { |
3f3eed27 | 675 | b4_table |
2b548aa6 RA |
676 | }; |
677 | ||
678 | /* YYCHECK. */ | |
a762e609 | 679 | const b4_int_type_for([b4_check]) |
66d30cd4 | 680 | yy::b4_parser_class_name::check_[[]] = |
2b548aa6 | 681 | { |
3f3eed27 | 682 | b4_check |
2b548aa6 RA |
683 | }; |
684 | ||
769b430f AD |
685 | #if YYDEBUG |
686 | /* STOS_[[STATE-NUM]] -- The (internal number of the) accessing | |
687 | symbol of state STATE-NUM. */ | |
a762e609 | 688 | const b4_int_type_for([b4_stos]) |
66d30cd4 | 689 | yy::b4_parser_class_name::stos_[[]] = |
769b430f AD |
690 | { |
691 | b4_stos | |
692 | }; | |
693 | ||
694 | /* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding | |
695 | to YYLEX-NUM. */ | |
a762e609 | 696 | const b4_int_type_for([b4_toknum]) |
66d30cd4 | 697 | yy::b4_parser_class_name::token_number_[[]] = |
769b430f AD |
698 | { |
699 | b4_toknum | |
700 | }; | |
701 | #endif | |
702 | ||
6b45a3ca | 703 | /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ |
a762e609 | 704 | const b4_int_type_for([b4_r1]) |
66d30cd4 | 705 | yy::b4_parser_class_name::r1_[[]] = |
2b548aa6 | 706 | { |
3f3eed27 | 707 | b4_r1 |
2b548aa6 RA |
708 | }; |
709 | ||
6b45a3ca | 710 | /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ |
a762e609 | 711 | const b4_int_type_for([b4_r2]) |
66d30cd4 | 712 | yy::b4_parser_class_name::r2_[[]] = |
2b548aa6 | 713 | { |
3f3eed27 | 714 | b4_r2 |
2b548aa6 RA |
715 | }; |
716 | ||
69e2658b | 717 | #if YYDEBUG || YYERROR_VERBOSE |
6b45a3ca | 718 | /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
719 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
720 | const char* | |
66d30cd4 | 721 | const yy::b4_parser_class_name::name_[[]] = |
2b548aa6 | 722 | { |
3f3eed27 | 723 | b4_tname |
2b548aa6 | 724 | }; |
69e2658b | 725 | #endif |
2b548aa6 | 726 | |
69e2658b | 727 | #if YYDEBUG |
2b548aa6 | 728 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
66d30cd4 AD |
729 | const yy::b4_parser_class_name::RhsNumberType |
730 | yy::b4_parser_class_name::rhs_[[]] = | |
2b548aa6 | 731 | { |
3f3eed27 | 732 | b4_rhs |
2b548aa6 RA |
733 | }; |
734 | ||
6b45a3ca | 735 | /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 736 | YYRHS. */ |
a762e609 | 737 | const b4_int_type_for([b4_prhs]) |
66d30cd4 | 738 | yy::b4_parser_class_name::prhs_[[]] = |
2b548aa6 | 739 | { |
3f3eed27 | 740 | b4_prhs |
2b548aa6 RA |
741 | }; |
742 | ||
69e2658b | 743 | /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ |
a762e609 | 744 | const b4_int_type_for([b4_rline]) |
66d30cd4 | 745 | yy::b4_parser_class_name::rline_[[]] = |
69e2658b RA |
746 | { |
747 | b4_rline | |
748 | }; | |
749 | #endif | |
750 | ||
2b548aa6 | 751 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
66d30cd4 AD |
752 | yy::b4_parser_class_name::TokenNumberType |
753 | yy::b4_parser_class_name::translate_ (int token) | |
2b548aa6 | 754 | { |
a75c057f | 755 | static |
680e8701 | 756 | const TokenNumberType |
3f3eed27 | 757 | translate_[[]] = |
2b548aa6 | 758 | { |
3f3eed27 | 759 | b4_translate |
2b548aa6 | 760 | }; |
007a50a4 AD |
761 | if ((unsigned) token <= user_token_number_max_) |
762 | return translate_[[token]]; | |
763 | else | |
764 | return undef_token_; | |
2b548aa6 RA |
765 | } |
766 | ||
66d30cd4 AD |
767 | const int yy::b4_parser_class_name::eof_ = 0; |
768 | const int yy::b4_parser_class_name::last_ = b4_last; | |
769 | const int yy::b4_parser_class_name::nnts_ = b4_nterms_number; | |
770 | const int yy::b4_parser_class_name::empty_ = -2; | |
771 | const int yy::b4_parser_class_name::final_ = b4_final_state_number; | |
772 | const int yy::b4_parser_class_name::terror_ = 1; | |
773 | const int yy::b4_parser_class_name::errcode_ = 256; | |
774 | const int yy::b4_parser_class_name::ntokens_ = b4_tokens_number; | |
775 | const int yy::b4_parser_class_name::initdepth_ = b4_stack_depth_init; | |
776 | ||
777 | const unsigned yy::b4_parser_class_name::user_token_number_max_ = b4_user_token_number_max; | |
778 | const yy::b4_parser_class_name::TokenNumberType yy::b4_name::undef_token_ = b4_undef_token_number; | |
2b548aa6 | 779 | |
3f3eed27 | 780 | b4_epilogue |
21846f69 | 781 | dnl |
3f3eed27 | 782 | #output "stack.hh" |
fb8135fa | 783 | b4_copyright([2002]) |
98254360 | 784 | |
2b548aa6 RA |
785 | #ifndef BISON_STACK_HH |
786 | # define BISON_STACK_HH | |
787 | ||
45119f04 | 788 | #include <deque> |
2b548aa6 RA |
789 | |
790 | namespace yy | |
791 | { | |
45119f04 | 792 | template < class T, class S = std::deque< T > > |
2b548aa6 RA |
793 | class Stack |
794 | { | |
795 | public: | |
796 | ||
797 | typedef typename S::iterator Iterator; | |
798 | typedef typename S::const_iterator ConstIterator; | |
799 | ||
800 | Stack () : seq_ () | |
801 | { | |
802 | } | |
803 | ||
804 | Stack (unsigned n) : seq_ (n) | |
805 | { | |
806 | } | |
807 | ||
808 | inline | |
809 | T& | |
45119f04 | 810 | operator [[]] (unsigned index) |
2b548aa6 | 811 | { |
45119f04 | 812 | return seq_[[index]]; |
2b548aa6 RA |
813 | } |
814 | ||
815 | inline | |
816 | const T& | |
45119f04 | 817 | operator [[]] (unsigned index) const |
2b548aa6 | 818 | { |
45119f04 | 819 | return seq_[[index]]; |
2b548aa6 RA |
820 | } |
821 | ||
822 | inline | |
823 | void | |
824 | push (const T& t) | |
825 | { | |
45119f04 | 826 | seq_.push_front (t); |
2b548aa6 RA |
827 | } |
828 | ||
829 | inline | |
830 | void | |
831 | pop (unsigned n = 1) | |
832 | { | |
833 | for (; n; --n) | |
45119f04 | 834 | seq_.pop_front (); |
2b548aa6 RA |
835 | } |
836 | ||
762a801e RA |
837 | inline |
838 | unsigned | |
839 | height () const | |
840 | { | |
841 | return seq_.size (); | |
842 | } | |
843 | ||
2b548aa6 RA |
844 | inline ConstIterator begin () const { return seq_.begin (); } |
845 | inline ConstIterator end () const { return seq_.end (); } | |
846 | ||
847 | private: | |
848 | ||
849 | S seq_; | |
850 | }; | |
374f5a14 RA |
851 | |
852 | template < class T, class S = Stack< T > > | |
853 | class Slice | |
854 | { | |
855 | public: | |
856 | ||
857 | Slice (const S& stack, | |
858 | unsigned range) : stack_ (stack), | |
859 | range_ (range) | |
860 | { | |
861 | } | |
862 | ||
863 | inline | |
864 | const T& | |
865 | operator [[]] (unsigned index) const | |
866 | { | |
45119f04 | 867 | return stack_[[range_ - index]]; |
374f5a14 RA |
868 | } |
869 | ||
870 | private: | |
871 | ||
872 | const S& stack_; | |
873 | unsigned range_; | |
874 | }; | |
2b548aa6 RA |
875 | } |
876 | ||
877 | #endif // not BISON_STACK_HH | |
21846f69 | 878 | dnl |
3f3eed27 | 879 | #output "location.hh" |
fb8135fa | 880 | b4_copyright([2002]) |
98254360 | 881 | |
2b548aa6 RA |
882 | #ifndef BISON_LOCATION_HH |
883 | # define BISON_LOCATION_HH | |
884 | ||
885 | namespace yy | |
886 | { | |
887 | struct Position | |
888 | { | |
889 | int line; | |
890 | int column; | |
891 | }; | |
892 | ||
893 | struct Location | |
894 | { | |
895 | Position first; | |
896 | Position last; | |
897 | }; | |
898 | } | |
899 | ||
900 | #endif // not BISON_LOCATION_HH |