]>
Commit | Line | Data |
---|---|---|
1 | m4_divert(-1) | |
2 | ||
3 | # C++ skeleton for Bison | |
4 | ||
5 | # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | |
6 | ||
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | ||
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | ||
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program; if not, write to the Free Software | |
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
20 | # 02110-1301 USA | |
21 | ||
22 | m4_include(b4_pkgdatadir/[c++.m4]) | |
23 | ||
24 | # We do want M4 expansion after # for CPP macros. | |
25 | m4_changecom() | |
26 | m4_divert(0)dnl | |
27 | m4_if(b4_defines_flag, 0, [], | |
28 | [@output @output_header_name@ | |
29 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], | |
30 | [2002, 2003, 2004, 2005]) | |
31 | dnl FIXME: This is wrong, we want computed header guards. | |
32 | dnl FIXME: I don\'t know why the macros are missing now. :( | |
33 | [ | |
34 | #ifndef PARSER_HEADER_H | |
35 | # define PARSER_HEADER_H | |
36 | ||
37 | #include <string> | |
38 | #include <iostream> | |
39 | #include "stack.hh" | |
40 | #include "location.hh" | |
41 | ||
42 | /* Using locations. */ | |
43 | #define YYLSP_NEEDED ]b4_locations_flag[ | |
44 | ||
45 | /* First part of user declarations. */ | |
46 | ]b4_pre_prologue[ | |
47 | ||
48 | ]/* Line __line__ of lalr1.cc. */ | |
49 | b4_syncline([@oline@], [@ofile@])[ | |
50 | ||
51 | /* Enabling traces. */ | |
52 | #ifndef YYDEBUG | |
53 | # define YYDEBUG ]b4_debug[ | |
54 | #endif | |
55 | ||
56 | /* Enabling verbose error messages. */ | |
57 | #ifdef YYERROR_VERBOSE | |
58 | # undef YYERROR_VERBOSE | |
59 | # define YYERROR_VERBOSE 1 | |
60 | #else | |
61 | # define YYERROR_VERBOSE ]b4_error_verbose[ | |
62 | #endif | |
63 | ||
64 | /* Enabling the token table. */ | |
65 | #ifndef YYTOKEN_TABLE | |
66 | # define YYTOKEN_TABLE ]b4_token_table[ | |
67 | #endif | |
68 | ||
69 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
70 | If N is 0, then set CURRENT to the empty location which ends | |
71 | the previous symbol: RHS[0] (always defined). */ | |
72 | ||
73 | #ifndef YYLLOC_DEFAULT | |
74 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
75 | do { \ | |
76 | if (N) \ | |
77 | { \ | |
78 | (Current).begin = (Rhs)[1].begin; \ | |
79 | (Current).end = (Rhs)[N].end; \ | |
80 | } \ | |
81 | else \ | |
82 | { \ | |
83 | (Current).begin = (Current).end = (Rhs)[0].end; \ | |
84 | } \ | |
85 | } while (0) | |
86 | #endif | |
87 | ||
88 | namespace yy | |
89 | { | |
90 | ||
91 | /// A Bison parser. | |
92 | class ]b4_parser_class_name[ | |
93 | { | |
94 | public: | |
95 | /// Symbol semantic values. | |
96 | #if ! defined (YYSTYPE) | |
97 | ]m4_ifdef([b4_stype], | |
98 | [b4_syncline([b4_stype_line], [b4_file_name]) | |
99 | union semantic_type b4_stype; | |
100 | /* Line __line__ of lalr1.cc. */ | |
101 | b4_syncline([@oline@], [@ofile@])], | |
102 | [ typedef int semantic_type;])[ | |
103 | #else | |
104 | typedef YYSTYPE semantic_type; | |
105 | #endif | |
106 | /// Symbol locations. | |
107 | typedef ]b4_location_type[ location_type; | |
108 | /// Tokens. | |
109 | struct token | |
110 | { | |
111 | ]b4_token_enums(b4_tokens)[ | |
112 | }; | |
113 | ||
114 | /// Build a parser object. | |
115 | ]b4_parser_class_name[ (]b4_parse_param_decl[) : | |
116 | yydebug_ (false), | |
117 | yycdebug_ (&std::cerr)]b4_parse_param_cons[ | |
118 | { | |
119 | } | |
120 | ||
121 | virtual ~]b4_parser_class_name[ () | |
122 | { | |
123 | } | |
124 | ||
125 | /// Parse. | |
126 | /// \returns 0 iff parsing succeeded. | |
127 | virtual int parse (); | |
128 | ||
129 | /// The current debugging stream. | |
130 | std::ostream& debug_stream () const; | |
131 | /// Set the current debugging stream. | |
132 | void set_debug_stream (std::ostream &); | |
133 | ||
134 | /// Type for debugging levels. | |
135 | typedef int debug_level_type; | |
136 | /// The current debugging level. | |
137 | debug_level_type debug_level () const; | |
138 | /// Set the current debugging level. | |
139 | void set_debug_level (debug_level_type l); | |
140 | ||
141 | private: | |
142 | /// Report a syntax error. | |
143 | /// \param loc where the syntax error is found. | |
144 | /// \param msg a description of the syntax error. | |
145 | virtual void error (const location_type& loc, const std::string& msg); | |
146 | ||
147 | /// Generate an error message. | |
148 | /// \param state the state where the error occurred. | |
149 | /// \param tok the look-ahead token. | |
150 | virtual std::string yysyntax_error_ (int yystate]dnl | |
151 | b4_error_verbose_if([, int tok])[); | |
152 | ||
153 | #if YYDEBUG | |
154 | /// \brief Report a symbol on the debug stream. | |
155 | /// \param yytype The token type. | |
156 | /// \param yyvaluep Its semantic value. | |
157 | /// \param yylocationp Its location. | |
158 | virtual void yysymprint_ (int yytype, | |
159 | const semantic_type* yyvaluep, | |
160 | const location_type* yylocationp); | |
161 | #endif /* ! YYDEBUG */ | |
162 | ||
163 | ||
164 | /// State numbers. | |
165 | typedef int state_type; | |
166 | /// State stack type. | |
167 | typedef stack<state_type> state_stack_type; | |
168 | /// Semantic value stack type. | |
169 | typedef stack<semantic_type> semantic_stack_type; | |
170 | /// location stack type. | |
171 | typedef stack<location_type> location_stack_type; | |
172 | ||
173 | /// The state stack. | |
174 | state_stack_type yystate_stack_; | |
175 | /// The semantic value stack. | |
176 | semantic_stack_type yysemantic_stack_; | |
177 | /// The location stack. | |
178 | location_stack_type yylocation_stack_; | |
179 | ||
180 | /// Internal symbol numbers. | |
181 | typedef ]b4_int_type_for([b4_translate])[ token_number_type; | |
182 | /* Tables. */ | |
183 | /// For a state, the index in \a yytable_ of its portion. | |
184 | static const ]b4_int_type_for([b4_pact])[ yypact_[]; | |
185 | static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; | |
186 | ||
187 | /// For a state, default rule to reduce. | |
188 | /// Unless\a yytable_ specifies something else to do. | |
189 | /// Zero means the default is an error. | |
190 | static const ]b4_int_type_for([b4_defact])[ yydefact_[]; | |
191 | ||
192 | static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[]; | |
193 | static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[]; | |
194 | ||
195 | /// What to do in a state. | |
196 | /// \a yytable_[yypact_[s]]: what to do in state \a s. | |
197 | /// - if positive, shift that token. | |
198 | /// - if negative, reduce the rule which number is the opposite. | |
199 | /// - if zero, do what YYDEFACT says. | |
200 | static const ]b4_int_type_for([b4_table])[ yytable_[]; | |
201 | static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; | |
202 | ||
203 | static const ]b4_int_type_for([b4_check])[ yycheck_[]; | |
204 | ||
205 | /// For a state, its accessing symbol. | |
206 | static const ]b4_int_type_for([b4_stos])[ yystos_[]; | |
207 | ||
208 | /// For a rule, its LHS. | |
209 | static const ]b4_int_type_for([b4_r1])[ yyr1_[]; | |
210 | /// For a rule, its RHS length. | |
211 | static const ]b4_int_type_for([b4_r2])[ yyr2_[]; | |
212 | ||
213 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE | |
214 | /// For a symbol, its name in clear. | |
215 | static const char* const yytname_[]; | |
216 | #endif | |
217 | ||
218 | #if YYERROR_VERBOSE | |
219 | /// Convert the symbol name \a n to a form suitable for a diagnostic. | |
220 | virtual std::string yytnamerr_ (const char *n); | |
221 | #endif | |
222 | ||
223 | #if YYDEBUG | |
224 | /// A type to store symbol numbers and -1. | |
225 | typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type; | |
226 | /// A `-1'-separated list of the rules' RHS. | |
227 | static const rhs_number_type yyrhs_[]; | |
228 | /// For each rule, the index of the first RHS symbol in \a yyrhs_. | |
229 | static const ]b4_int_type_for([b4_prhs])[ yyprhs_[]; | |
230 | /// For each rule, its source line number. | |
231 | static const ]b4_int_type_for([b4_rline])[ yyrline_[]; | |
232 | /// For each scanner token number, its symbol number. | |
233 | static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; | |
234 | /// Report on the debug stream that the rule \a r is going to be reduced. | |
235 | virtual void yyreduce_print_ (int r); | |
236 | /// Print the state stack on the debug stream. | |
237 | virtual void yystack_print_ (); | |
238 | #endif | |
239 | ||
240 | /// Convert a scanner token number to a symbol number. | |
241 | inline token_number_type yytranslate_ (int token); | |
242 | ||
243 | /// \brief Reclaim the memory associated to a symbol. | |
244 | /// \param yymsg Why this token is reclaimed. | |
245 | /// \param yytype The symbol type. | |
246 | /// \param yyvaluep Its semantic value. | |
247 | /// \param yylocationp Its location. | |
248 | inline void yydestruct_ (const char* yymsg, | |
249 | int yytype, | |
250 | semantic_type* yyvaluep, | |
251 | location_type* yylocationp); | |
252 | ||
253 | /// Pop \a n symbols the three stacks. | |
254 | inline void yypop_ (unsigned int n = 1); | |
255 | ||
256 | /* Constants. */ | |
257 | static const int yyeof_; | |
258 | /* LAST_ -- Last index in TABLE_. */ | |
259 | static const int yylast_; | |
260 | static const int yynnts_; | |
261 | static const int yyempty_; | |
262 | static const int yyfinal_; | |
263 | static const int yyterror_; | |
264 | static const int yyerrcode_; | |
265 | static const int yyntokens_; | |
266 | static const unsigned int yyuser_token_number_max_; | |
267 | static const token_number_type yyundef_token_; | |
268 | ||
269 | /* Debugging. */ | |
270 | int yydebug_; | |
271 | std::ostream* yycdebug_; | |
272 | ||
273 | ]b4_parse_param_vars[ | |
274 | }; | |
275 | } | |
276 | ||
277 | ]m4_ifset([b4_global_tokens_and_yystype], | |
278 | [b4_token_defines(b4_tokens) | |
279 | ||
280 | #ifndef YYSTYPE | |
281 | /* Redirection for backward compatibility. */ | |
282 | # define YYSTYPE yy::b4_parser_class_name::semantic_type | |
283 | #endif | |
284 | ])[ | |
285 | #endif /* ! defined PARSER_HEADER_H */] | |
286 | ])dnl | |
287 | @output @output_parser_name@ | |
288 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], | |
289 | [2002, 2003, 2004, 2005]) | |
290 | m4_if(b4_prefix[], [yy], [], | |
291 | [ | |
292 | // Take the name prefix into account. | |
293 | #define yylex b4_prefix[]lex]) | |
294 | m4_if(b4_defines_flag, 0, [], | |
295 | [ | |
296 | #include @output_header_name@])[ | |
297 | ||
298 | /* User implementation prologue. */ | |
299 | ]b4_post_prologue[ | |
300 | ||
301 | ]/* Line __line__ of lalr1.cc. */ | |
302 | b4_syncline([@oline@], [@ofile@])[ | |
303 | ||
304 | #ifndef YY_ | |
305 | # if YYENABLE_NLS | |
306 | # if ENABLE_NLS | |
307 | # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */ | |
308 | # define YY_(msgid) dgettext ("bison-runtime", msgid) | |
309 | # endif | |
310 | # endif | |
311 | # ifndef YY_ | |
312 | # define YY_(msgid) msgid | |
313 | # endif | |
314 | #endif | |
315 | ||
316 | /* A pseudo ostream that takes yydebug_ into account. */ | |
317 | # define YYCDEBUG \ | |
318 | for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ | |
319 | (*yycdebug_) | |
320 | ||
321 | /* Enable debugging if requested. */ | |
322 | #if YYDEBUG | |
323 | ||
324 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ | |
325 | do { \ | |
326 | if (yydebug_) \ | |
327 | { \ | |
328 | *yycdebug_ << (Title) << ' '; \ | |
329 | yysymprint_ ((Type), (Value), (Location)); \ | |
330 | *yycdebug_ << std::endl; \ | |
331 | } \ | |
332 | } while (0) | |
333 | ||
334 | # define YY_REDUCE_PRINT(Rule) \ | |
335 | do { \ | |
336 | if (yydebug_) \ | |
337 | yyreduce_print_ (Rule); \ | |
338 | } while (0) | |
339 | ||
340 | # define YY_STACK_PRINT() \ | |
341 | do { \ | |
342 | if (yydebug_) \ | |
343 | yystack_print_ (); \ | |
344 | } while (0) | |
345 | ||
346 | #else /* !YYDEBUG */ | |
347 | ||
348 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) | |
349 | # define YY_REDUCE_PRINT(Rule) | |
350 | # define YY_STACK_PRINT() | |
351 | ||
352 | #endif /* !YYDEBUG */ | |
353 | ||
354 | #define YYACCEPT goto yyacceptlab | |
355 | #define YYABORT goto yyabortlab | |
356 | #define YYERROR goto yyerrorlab | |
357 | ||
358 | #if YYERROR_VERBOSE | |
359 | ||
360 | /* Return YYSTR after stripping away unnecessary quotes and | |
361 | backslashes, so that it's suitable for yyerror. The heuristic is | |
362 | that double-quoting is unnecessary unless the string contains an | |
363 | apostrophe, a comma, or backslash (other than backslash-backslash). | |
364 | YYSTR is taken from yytname. */ | |
365 | std::string | |
366 | yy::]b4_parser_class_name[::yytnamerr_ (const char *yystr) | |
367 | { | |
368 | if (*yystr == '"') | |
369 | { | |
370 | std::string yyr = ""; | |
371 | char const *yyp = yystr; | |
372 | ||
373 | for (;;) | |
374 | switch (*++yyp) | |
375 | { | |
376 | case '\'': | |
377 | case ',': | |
378 | goto do_not_strip_quotes; | |
379 | ||
380 | case '\\': | |
381 | if (*++yyp != '\\') | |
382 | goto do_not_strip_quotes; | |
383 | /* Fall through. */ | |
384 | default: | |
385 | yyr += *yyp; | |
386 | break; | |
387 | ||
388 | case '"': | |
389 | return yyr; | |
390 | } | |
391 | do_not_strip_quotes: ; | |
392 | } | |
393 | ||
394 | return yystr; | |
395 | } | |
396 | ||
397 | #endif | |
398 | ||
399 | #if YYDEBUG | |
400 | /*--------------------------------. | |
401 | | Print this symbol on YYOUTPUT. | | |
402 | `--------------------------------*/ | |
403 | ||
404 | void | |
405 | yy::]b4_parser_class_name[::yysymprint_ (int yytype, | |
406 | const semantic_type* yyvaluep, const location_type* yylocationp) | |
407 | { | |
408 | /* Pacify ``unused variable'' warnings. */ | |
409 | (void) yyvaluep; | |
410 | (void) yylocationp; | |
411 | /* Backward compatibility, but should be removed eventually. */ | |
412 | std::ostream& cdebug_ = *yycdebug_; | |
413 | (void) cdebug_; | |
414 | ||
415 | *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") | |
416 | << ' ' << yytname_[yytype] << " (" | |
417 | << *yylocationp << ": "; | |
418 | switch (yytype) | |
419 | { | |
420 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl | |
421 | [ default: | |
422 | break; | |
423 | } | |
424 | *yycdebug_ << ')'; | |
425 | } | |
426 | #endif /* ! YYDEBUG */ | |
427 | ||
428 | void | |
429 | yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg, | |
430 | int yytype, semantic_type* yyvaluep, location_type* yylocationp) | |
431 | { | |
432 | /* Pacify ``unused variable'' warnings. */ | |
433 | (void) yymsg; | |
434 | (void) yyvaluep; | |
435 | (void) yylocationp; | |
436 | ||
437 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
438 | ||
439 | switch (yytype) | |
440 | { | |
441 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
442 | default: | |
443 | break; | |
444 | } | |
445 | } | |
446 | ||
447 | void | |
448 | yy::]b4_parser_class_name[::yypop_ (unsigned int n) | |
449 | { | |
450 | yystate_stack_.pop (n); | |
451 | yysemantic_stack_.pop (n); | |
452 | yylocation_stack_.pop (n); | |
453 | } | |
454 | ||
455 | std::ostream& | |
456 | yy::]b4_parser_class_name[::debug_stream () const | |
457 | { | |
458 | return *yycdebug_; | |
459 | } | |
460 | ||
461 | void | |
462 | yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o) | |
463 | { | |
464 | yycdebug_ = &o; | |
465 | } | |
466 | ||
467 | ||
468 | yy::]b4_parser_class_name[::debug_level_type | |
469 | yy::]b4_parser_class_name[::debug_level () const | |
470 | { | |
471 | return yydebug_; | |
472 | } | |
473 | ||
474 | void | |
475 | yy::]b4_parser_class_name[::set_debug_level (debug_level_type l) | |
476 | { | |
477 | yydebug_ = l; | |
478 | } | |
479 | ||
480 | ||
481 | int | |
482 | yy::]b4_parser_class_name[::parse () | |
483 | { | |
484 | /// Look-ahead and look-ahead in internal form. | |
485 | int yychar = yyempty_; | |
486 | int yytoken = 0; | |
487 | ||
488 | /* State. */ | |
489 | int yyn; | |
490 | int yylen; | |
491 | int yystate = 0; | |
492 | ||
493 | /* Error handling. */ | |
494 | int yynerrs_ = 0; | |
495 | int yyerrstatus_ = 0; | |
496 | ||
497 | /// Semantic value of the look-ahead. | |
498 | semantic_type yylval; | |
499 | /// Location of the look-ahead. | |
500 | location_type yylloc; | |
501 | /// The locations where the error started and ended. | |
502 | location yyerror_range[2]; | |
503 | ||
504 | /// $$. | |
505 | semantic_type yyval; | |
506 | /// @@$. | |
507 | location_type yyloc; | |
508 | ||
509 | int yyresult_; | |
510 | ||
511 | YYCDEBUG << "Starting parse" << std::endl; | |
512 | ||
513 | ]m4_ifdef([b4_initial_action], [ | |
514 | m4_pushdef([b4_at_dollar], [yylloc])dnl | |
515 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
516 | /* User initialization code. */ | |
517 | b4_initial_action | |
518 | m4_popdef([b4_dollar_dollar])dnl | |
519 | m4_popdef([b4_at_dollar])dnl | |
520 | /* Line __line__ of yacc.c. */ | |
521 | b4_syncline([@oline@], [@ofile@])])dnl | |
522 | ||
523 | [ /* Initialize the stacks. The initial state will be pushed in | |
524 | yynewstate, since the latter expects the semantical and the | |
525 | location values to have been already stored, initialize these | |
526 | stacks with a primary value. */ | |
527 | yystate_stack_ = state_stack_type (0); | |
528 | yysemantic_stack_ = semantic_stack_type (0); | |
529 | yylocation_stack_ = location_stack_type (0); | |
530 | yysemantic_stack_.push (yylval); | |
531 | yylocation_stack_.push (yylloc); | |
532 | ||
533 | /* New state. */ | |
534 | yynewstate: | |
535 | yystate_stack_.push (yystate); | |
536 | YYCDEBUG << "Entering state " << yystate << std::endl; | |
537 | goto yybackup; | |
538 | ||
539 | /* Backup. */ | |
540 | yybackup: | |
541 | ||
542 | /* Try to take a decision without look-ahead. */ | |
543 | yyn = yypact_[yystate]; | |
544 | if (yyn == yypact_ninf_) | |
545 | goto yydefault; | |
546 | ||
547 | /* Read a look-ahead token. */ | |
548 | if (yychar == yyempty_) | |
549 | { | |
550 | YYCDEBUG << "Reading a token: "; | |
551 | yychar = ]b4_c_function_call([yylex], [int], | |
552 | [[YYSTYPE*], [&yylval]][]dnl | |
553 | b4_location_if([, [[location*], [&yylloc]]])dnl | |
554 | m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; | |
555 | } | |
556 | ||
557 | ||
558 | /* Convert token to internal form. */ | |
559 | if (yychar <= yyeof_) | |
560 | { | |
561 | yychar = yytoken = yyeof_; | |
562 | YYCDEBUG << "Now at end of input." << std::endl; | |
563 | } | |
564 | else | |
565 | { | |
566 | yytoken = yytranslate_ (yychar); | |
567 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); | |
568 | } | |
569 | ||
570 | /* If the proper action on seeing token YYTOKEN is to reduce or to | |
571 | detect an error, take that action. */ | |
572 | yyn += yytoken; | |
573 | if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) | |
574 | goto yydefault; | |
575 | ||
576 | /* Reduce or error. */ | |
577 | yyn = yytable_[yyn]; | |
578 | if (yyn <= 0) | |
579 | { | |
580 | if (yyn == 0 || yyn == yytable_ninf_) | |
581 | goto yyerrlab; | |
582 | yyn = -yyn; | |
583 | goto yyreduce; | |
584 | } | |
585 | ||
586 | /* Accept? */ | |
587 | if (yyn == yyfinal_) | |
588 | goto yyacceptlab; | |
589 | ||
590 | /* Shift the look-ahead token. */ | |
591 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); | |
592 | ||
593 | /* Discard the token being shifted unless it is eof. */ | |
594 | if (yychar != yyeof_) | |
595 | yychar = yyempty_; | |
596 | ||
597 | yysemantic_stack_.push (yylval); | |
598 | yylocation_stack_.push (yylloc); | |
599 | ||
600 | /* Count tokens shifted since error; after three, turn off error | |
601 | status. */ | |
602 | if (yyerrstatus_) | |
603 | --yyerrstatus_; | |
604 | ||
605 | yystate = yyn; | |
606 | goto yynewstate; | |
607 | ||
608 | /*-----------------------------------------------------------. | |
609 | | yydefault -- do the default action for the current state. | | |
610 | `-----------------------------------------------------------*/ | |
611 | yydefault: | |
612 | yyn = yydefact_[yystate]; | |
613 | if (yyn == 0) | |
614 | goto yyerrlab; | |
615 | goto yyreduce; | |
616 | ||
617 | /*-----------------------------. | |
618 | | yyreduce -- Do a reduction. | | |
619 | `-----------------------------*/ | |
620 | yyreduce: | |
621 | yylen = yyr2_[yyn]; | |
622 | /* If LEN_ is nonzero, implement the default value of the action: | |
623 | `$$ = $1'. Otherwise, use the top of the stack. | |
624 | ||
625 | Otherwise, the following line sets YYVAL to garbage. | |
626 | This behavior is undocumented and Bison | |
627 | users should not rely upon it. */ | |
628 | if (yylen) | |
629 | yyval = yysemantic_stack_[yylen - 1]; | |
630 | else | |
631 | yyval = yysemantic_stack_[0]; | |
632 | ||
633 | { | |
634 | slice<location_type, location_stack_type> slice (yylocation_stack_, yylen); | |
635 | YYLLOC_DEFAULT (yyloc, slice, yylen); | |
636 | } | |
637 | YY_REDUCE_PRINT (yyn); | |
638 | switch (yyn) | |
639 | { | |
640 | ]b4_actions[ | |
641 | default: break; | |
642 | } | |
643 | ||
644 | ]/* Line __line__ of lalr1.cc. */ | |
645 | b4_syncline([@oline@], [@ofile@])[ | |
646 | ||
647 | yypop_ (yylen); | |
648 | ||
649 | YY_STACK_PRINT (); | |
650 | ||
651 | yysemantic_stack_.push (yyval); | |
652 | yylocation_stack_.push (yyloc); | |
653 | ||
654 | /* Shift the result of the reduction. */ | |
655 | yyn = yyr1_[yyn]; | |
656 | yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0]; | |
657 | if (0 <= yystate && yystate <= yylast_ | |
658 | && yycheck_[yystate] == yystate_stack_[0]) | |
659 | yystate = yytable_[yystate]; | |
660 | else | |
661 | yystate = yydefgoto_[yyn - yyntokens_]; | |
662 | goto yynewstate; | |
663 | ||
664 | /*------------------------------------. | |
665 | | yyerrlab -- here on detecting error | | |
666 | `------------------------------------*/ | |
667 | yyerrlab: | |
668 | /* If not already recovering from an error, report this error. */ | |
669 | if (!yyerrstatus_) | |
670 | { | |
671 | ++yynerrs_; | |
672 | error (yylloc, yysyntax_error_ (yystate]dnl | |
673 | b4_error_verbose_if([, yytoken])[)); | |
674 | } | |
675 | ||
676 | yyerror_range[0] = yylloc; | |
677 | if (yyerrstatus_ == 3) | |
678 | { | |
679 | /* If just tried and failed to reuse look-ahead token after an | |
680 | error, discard it. */ | |
681 | ||
682 | if (yychar <= yyeof_) | |
683 | { | |
684 | /* Return failure if at end of input. */ | |
685 | if (yychar == yyeof_) | |
686 | YYABORT; | |
687 | } | |
688 | else | |
689 | { | |
690 | yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); | |
691 | yychar = yyempty_; | |
692 | } | |
693 | } | |
694 | ||
695 | /* Else will try to reuse look-ahead token after shifting the error | |
696 | token. */ | |
697 | goto yyerrlab1; | |
698 | ||
699 | ||
700 | /*---------------------------------------------------. | |
701 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
702 | `---------------------------------------------------*/ | |
703 | yyerrorlab: | |
704 | ||
705 | /* Pacify compilers like GCC when the user code never invokes | |
706 | YYERROR and the label yyerrorlab therefore never appears in user | |
707 | code. */ | |
708 | if (false) | |
709 | goto yyerrorlab; | |
710 | ||
711 | yyerror_range[0] = yylocation_stack_[yylen - 1]; | |
712 | yypop_ (yylen); | |
713 | yystate = yystate_stack_[0]; | |
714 | goto yyerrlab1; | |
715 | ||
716 | /*-------------------------------------------------------------. | |
717 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
718 | `-------------------------------------------------------------*/ | |
719 | yyerrlab1: | |
720 | yyerrstatus_ = 3; /* Each real token shifted decrements this. */ | |
721 | ||
722 | for (;;) | |
723 | { | |
724 | yyn = yypact_[yystate]; | |
725 | if (yyn != yypact_ninf_) | |
726 | { | |
727 | yyn += yyterror_; | |
728 | if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) | |
729 | { | |
730 | yyn = yytable_[yyn]; | |
731 | if (0 < yyn) | |
732 | break; | |
733 | } | |
734 | } | |
735 | ||
736 | /* Pop the current state because it cannot handle the error token. */ | |
737 | if (yystate_stack_.height () == 1) | |
738 | YYABORT; | |
739 | ||
740 | yyerror_range[0] = yylocation_stack_[0]; | |
741 | yydestruct_ ("Error: popping", | |
742 | yystos_[yystate], | |
743 | &yysemantic_stack_[0], &yylocation_stack_[0]); | |
744 | yypop_ (); | |
745 | yystate = yystate_stack_[0]; | |
746 | YY_STACK_PRINT (); | |
747 | } | |
748 | ||
749 | if (yyn == yyfinal_) | |
750 | goto yyacceptlab; | |
751 | ||
752 | yyerror_range[1] = yylloc; | |
753 | // Using YYLLOC is tempting, but would change the location of | |
754 | // the look-ahead. YYLOC is available though. | |
755 | YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2); | |
756 | yysemantic_stack_.push (yylval); | |
757 | yylocation_stack_.push (yyloc); | |
758 | ||
759 | /* Shift the error token. */ | |
760 | YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], | |
761 | &yysemantic_stack_[0], &yylocation_stack_[0]); | |
762 | ||
763 | yystate = yyn; | |
764 | goto yynewstate; | |
765 | ||
766 | /* Accept. */ | |
767 | yyacceptlab: | |
768 | yyresult_ = 0; | |
769 | goto yyreturn; | |
770 | ||
771 | /* Abort. */ | |
772 | yyabortlab: | |
773 | yyresult_ = 1; | |
774 | goto yyreturn; | |
775 | ||
776 | yyreturn: | |
777 | if (yychar != yyeof_ && yychar != yyempty_) | |
778 | yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); | |
779 | ||
780 | while (yystate_stack_.height () != 1) | |
781 | { | |
782 | yydestruct_ ("Cleanup: popping", | |
783 | yystos_[yystate_stack_[0]], | |
784 | &yysemantic_stack_[0], | |
785 | &yylocation_stack_[0]); | |
786 | yypop_ (); | |
787 | } | |
788 | ||
789 | return yyresult_; | |
790 | } | |
791 | ||
792 | // Generate an error message. | |
793 | std::string | |
794 | yy::]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl | |
795 | b4_error_verbose_if([, int tok])[) | |
796 | { | |
797 | std::string res; | |
798 | #if YYERROR_VERBOSE | |
799 | int yyn = yypact_[yystate]; | |
800 | if (yypact_ninf_ < yyn && yyn < yylast_) | |
801 | { | |
802 | /* Start YYX at -YYN if negative to avoid negative indexes in | |
803 | YYCHECK. */ | |
804 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
805 | ||
806 | /* Stay within bounds of both yycheck and yytname. */ | |
807 | int yychecklim = yylast_ - yyn; | |
808 | int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; | |
809 | int count = 0; | |
810 | for (int x = yyxbegin; x < yyxend; ++x) | |
811 | if (yycheck_[x + yyn] == x && x != yyterror_) | |
812 | ++count; | |
813 | ||
814 | // FIXME: This method of building the message is not compatible | |
815 | // with internationalization. It should work like yacc.c does it. | |
816 | // That is, first build a string that looks like this: | |
817 | // "syntax error, unexpected %s or %s or %s" | |
818 | // Then, invoke YY_ on this string. | |
819 | // Finally, use the string as a format to output | |
820 | // yytname_[tok], etc. | |
821 | // Until this gets fixed, this message appears in English only. | |
822 | res = "syntax error, unexpected "; | |
823 | res += yytnamerr_ (yytname_[tok]); | |
824 | if (count < 5) | |
825 | { | |
826 | count = 0; | |
827 | for (int x = yyxbegin; x < yyxend; ++x) | |
828 | if (yycheck_[x + yyn] == x && x != yyterror_) | |
829 | { | |
830 | res += (!count++) ? ", expecting " : " or "; | |
831 | res += yytnamerr_ (yytname_[x]); | |
832 | } | |
833 | } | |
834 | } | |
835 | else | |
836 | #endif | |
837 | res = YY_("syntax error"); | |
838 | return res; | |
839 | } | |
840 | ||
841 | ||
842 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
843 | STATE-NUM. */ | |
844 | const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[; | |
845 | const ]b4_int_type_for([b4_pact])[ | |
846 | yy::]b4_parser_class_name[::yypact_[] = | |
847 | { | |
848 | ]b4_pact[ | |
849 | }; | |
850 | ||
851 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE | |
852 | doesn't specify something else to do. Zero means the default is an | |
853 | error. */ | |
854 | const ]b4_int_type_for([b4_defact])[ | |
855 | yy::]b4_parser_class_name[::yydefact_[] = | |
856 | { | |
857 | ]b4_defact[ | |
858 | }; | |
859 | ||
860 | /* YYPGOTO[NTERM-NUM]. */ | |
861 | const ]b4_int_type_for([b4_pgoto])[ | |
862 | yy::]b4_parser_class_name[::yypgoto_[] = | |
863 | { | |
864 | ]b4_pgoto[ | |
865 | }; | |
866 | ||
867 | /* YYDEFGOTO[NTERM-NUM]. */ | |
868 | const ]b4_int_type_for([b4_defgoto])[ | |
869 | yy::]b4_parser_class_name[::yydefgoto_[] = | |
870 | { | |
871 | ]b4_defgoto[ | |
872 | }; | |
873 | ||
874 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If | |
875 | positive, shift that token. If negative, reduce the rule which | |
876 | number is the opposite. If zero, do what YYDEFACT says. */ | |
877 | const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[; | |
878 | const ]b4_int_type_for([b4_table])[ | |
879 | yy::]b4_parser_class_name[::yytable_[] = | |
880 | { | |
881 | ]b4_table[ | |
882 | }; | |
883 | ||
884 | /* YYCHECK. */ | |
885 | const ]b4_int_type_for([b4_check])[ | |
886 | yy::]b4_parser_class_name[::yycheck_[] = | |
887 | { | |
888 | ]b4_check[ | |
889 | }; | |
890 | ||
891 | /* STOS_[STATE-NUM] -- The (internal number of the) accessing | |
892 | symbol of state STATE-NUM. */ | |
893 | const ]b4_int_type_for([b4_stos])[ | |
894 | yy::]b4_parser_class_name[::yystos_[] = | |
895 | { | |
896 | ]b4_stos[ | |
897 | }; | |
898 | ||
899 | #if YYDEBUG | |
900 | /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding | |
901 | to YYLEX-NUM. */ | |
902 | const ]b4_int_type_for([b4_toknum])[ | |
903 | yy::]b4_parser_class_name[::yytoken_number_[] = | |
904 | { | |
905 | ]b4_toknum[ | |
906 | }; | |
907 | #endif | |
908 | ||
909 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ | |
910 | const ]b4_int_type_for([b4_r1])[ | |
911 | yy::]b4_parser_class_name[::yyr1_[] = | |
912 | { | |
913 | ]b4_r1[ | |
914 | }; | |
915 | ||
916 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ | |
917 | const ]b4_int_type_for([b4_r2])[ | |
918 | yy::]b4_parser_class_name[::yyr2_[] = | |
919 | { | |
920 | ]b4_r2[ | |
921 | }; | |
922 | ||
923 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE | |
924 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
925 | First, the terminals, then, starting at \a yyntokens_, nonterminals. */ | |
926 | const char* | |
927 | const yy::]b4_parser_class_name[::yytname_[] = | |
928 | { | |
929 | ]b4_tname[ | |
930 | }; | |
931 | #endif | |
932 | ||
933 | #if YYDEBUG | |
934 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ | |
935 | const yy::]b4_parser_class_name[::rhs_number_type | |
936 | yy::]b4_parser_class_name[::yyrhs_[] = | |
937 | { | |
938 | ]b4_rhs[ | |
939 | }; | |
940 | ||
941 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in | |
942 | YYRHS. */ | |
943 | const ]b4_int_type_for([b4_prhs])[ | |
944 | yy::]b4_parser_class_name[::yyprhs_[] = | |
945 | { | |
946 | ]b4_prhs[ | |
947 | }; | |
948 | ||
949 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ | |
950 | const ]b4_int_type_for([b4_rline])[ | |
951 | yy::]b4_parser_class_name[::yyrline_[] = | |
952 | { | |
953 | ]b4_rline[ | |
954 | }; | |
955 | ||
956 | // Print the state stack on the debug stream. | |
957 | void | |
958 | yy::]b4_parser_class_name[::yystack_print_ () | |
959 | { | |
960 | *yycdebug_ << "Stack now"; | |
961 | for (state_stack_type::const_iterator i = yystate_stack_.begin (); | |
962 | i != yystate_stack_.end (); ++i) | |
963 | *yycdebug_ << ' ' << *i; | |
964 | *yycdebug_ << std::endl; | |
965 | } | |
966 | ||
967 | // Report on the debug stream that the rule \a yyrule is going to be reduced. | |
968 | void | |
969 | yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule) | |
970 | { | |
971 | unsigned int yylno = yyrline_[yyrule]; | |
972 | /* Print the symbols being reduced, and their result. */ | |
973 | *yycdebug_ << "Reducing stack by rule " << yyrule - 1 | |
974 | << " (line " << yylno << "), "; | |
975 | for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule]; | |
976 | 0 <= yyrhs_[i]; ++i) | |
977 | *yycdebug_ << yytname_[yyrhs_[i]] << ' '; | |
978 | *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl; | |
979 | } | |
980 | #endif // YYDEBUG | |
981 | ||
982 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ | |
983 | yy::]b4_parser_class_name[::token_number_type | |
984 | yy::]b4_parser_class_name[::yytranslate_ (int token) | |
985 | { | |
986 | static | |
987 | const token_number_type | |
988 | translate_table[] = | |
989 | { | |
990 | ]b4_translate[ | |
991 | }; | |
992 | if ((unsigned int) token <= yyuser_token_number_max_) | |
993 | return translate_table[token]; | |
994 | else | |
995 | return yyundef_token_; | |
996 | } | |
997 | ||
998 | const int yy::]b4_parser_class_name[::yyeof_ = 0; | |
999 | const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[; | |
1000 | const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[; | |
1001 | const int yy::]b4_parser_class_name[::yyempty_ = -2; | |
1002 | const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[; | |
1003 | const int yy::]b4_parser_class_name[::yyterror_ = 1; | |
1004 | const int yy::]b4_parser_class_name[::yyerrcode_ = 256; | |
1005 | const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[; | |
1006 | ||
1007 | const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[; | |
1008 | const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[; | |
1009 | ||
1010 | ]b4_epilogue | |
1011 | dnl | |
1012 | @output stack.hh | |
1013 | b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[ | |
1014 | ||
1015 | #ifndef BISON_STACK_HH | |
1016 | # define BISON_STACK_HH | |
1017 | ||
1018 | #include <deque> | |
1019 | ||
1020 | namespace yy | |
1021 | { | |
1022 | template <class T, class S = std::deque<T> > | |
1023 | class stack | |
1024 | { | |
1025 | public: | |
1026 | ||
1027 | // Hide our reversed order. | |
1028 | typedef typename S::reverse_iterator iterator; | |
1029 | typedef typename S::const_reverse_iterator const_iterator; | |
1030 | ||
1031 | stack () : seq_ () | |
1032 | { | |
1033 | } | |
1034 | ||
1035 | stack (unsigned int n) : seq_ (n) | |
1036 | { | |
1037 | } | |
1038 | ||
1039 | inline | |
1040 | T& | |
1041 | operator [] (unsigned int i) | |
1042 | { | |
1043 | return seq_[i]; | |
1044 | } | |
1045 | ||
1046 | inline | |
1047 | const T& | |
1048 | operator [] (unsigned int i) const | |
1049 | { | |
1050 | return seq_[i]; | |
1051 | } | |
1052 | ||
1053 | inline | |
1054 | void | |
1055 | push (const T& t) | |
1056 | { | |
1057 | seq_.push_front (t); | |
1058 | } | |
1059 | ||
1060 | inline | |
1061 | void | |
1062 | pop (unsigned int n = 1) | |
1063 | { | |
1064 | for (; n; --n) | |
1065 | seq_.pop_front (); | |
1066 | } | |
1067 | ||
1068 | inline | |
1069 | unsigned int | |
1070 | height () const | |
1071 | { | |
1072 | return seq_.size (); | |
1073 | } | |
1074 | ||
1075 | inline const_iterator begin () const { return seq_.rbegin (); } | |
1076 | inline const_iterator end () const { return seq_.rend (); } | |
1077 | ||
1078 | private: | |
1079 | ||
1080 | S seq_; | |
1081 | }; | |
1082 | ||
1083 | /// Present a slice of the top of a stack. | |
1084 | template <class T, class S = stack<T> > | |
1085 | class slice | |
1086 | { | |
1087 | public: | |
1088 | ||
1089 | slice (const S& stack, | |
1090 | unsigned int range) : stack_ (stack), | |
1091 | range_ (range) | |
1092 | { | |
1093 | } | |
1094 | ||
1095 | inline | |
1096 | const T& | |
1097 | operator [] (unsigned int i) const | |
1098 | { | |
1099 | return stack_[range_ - i]; | |
1100 | } | |
1101 | ||
1102 | private: | |
1103 | ||
1104 | const S& stack_; | |
1105 | unsigned int range_; | |
1106 | }; | |
1107 | } | |
1108 | ||
1109 | #endif // not BISON_STACK_HH] | |
1110 | dnl | |
1111 | @output position.hh | |
1112 | b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004, 2005])[ | |
1113 | ||
1114 | /** | |
1115 | ** \file position.hh | |
1116 | ** Define the position class. | |
1117 | */ | |
1118 | ||
1119 | #ifndef BISON_POSITION_HH | |
1120 | # define BISON_POSITION_HH | |
1121 | ||
1122 | # include <iostream> | |
1123 | # include <string> | |
1124 | ||
1125 | namespace yy | |
1126 | { | |
1127 | /// Abstract a position. | |
1128 | class position | |
1129 | { | |
1130 | public: | |
1131 | /// Initial column number. | |
1132 | static const unsigned int initial_column = 0; | |
1133 | /// Initial line number. | |
1134 | static const unsigned int initial_line = 1; | |
1135 | ||
1136 | /** \name Ctor & dtor. | |
1137 | ** \{ */ | |
1138 | public: | |
1139 | /// Construct a position. | |
1140 | position () : | |
1141 | filename (0), | |
1142 | line (initial_line), | |
1143 | column (initial_column) | |
1144 | { | |
1145 | } | |
1146 | /** \} */ | |
1147 | ||
1148 | ||
1149 | /** \name Line and Column related manipulators | |
1150 | ** \{ */ | |
1151 | public: | |
1152 | /// (line related) Advance to the COUNT next lines. | |
1153 | inline void lines (int count = 1) | |
1154 | { | |
1155 | column = initial_column; | |
1156 | line += count; | |
1157 | } | |
1158 | ||
1159 | /// (column related) Advance to the COUNT next columns. | |
1160 | inline void columns (int count = 1) | |
1161 | { | |
1162 | int leftmost = initial_column; | |
1163 | int current = column; | |
1164 | if (leftmost <= current + count) | |
1165 | column += count; | |
1166 | else | |
1167 | column = initial_column; | |
1168 | } | |
1169 | /** \} */ | |
1170 | ||
1171 | public: | |
1172 | /// File name to which this position refers. | |
1173 | ]b4_filename_type[* filename; | |
1174 | /// Current line number. | |
1175 | unsigned int line; | |
1176 | /// Current column number. | |
1177 | unsigned int column; | |
1178 | }; | |
1179 | ||
1180 | /// Add and assign a position. | |
1181 | inline const position& | |
1182 | operator+= (position& res, const int width) | |
1183 | { | |
1184 | res.columns (width); | |
1185 | return res; | |
1186 | } | |
1187 | ||
1188 | /// Add two position objects. | |
1189 | inline const position | |
1190 | operator+ (const position& begin, const int width) | |
1191 | { | |
1192 | position res = begin; | |
1193 | return res += width; | |
1194 | } | |
1195 | ||
1196 | /// Add and assign a position. | |
1197 | inline const position& | |
1198 | operator-= (position& res, const int width) | |
1199 | { | |
1200 | return res += -width; | |
1201 | } | |
1202 | ||
1203 | /// Add two position objects. | |
1204 | inline const position | |
1205 | operator- (const position& begin, const int width) | |
1206 | { | |
1207 | return begin + -width; | |
1208 | } | |
1209 | ||
1210 | /** \brief Intercept output stream redirection. | |
1211 | ** \param ostr the destination output stream | |
1212 | ** \param pos a reference to the position to redirect | |
1213 | */ | |
1214 | inline std::ostream& | |
1215 | operator<< (std::ostream& ostr, const position& pos) | |
1216 | { | |
1217 | if (pos.filename) | |
1218 | ostr << *pos.filename << ':'; | |
1219 | return ostr << pos.line << '.' << pos.column; | |
1220 | } | |
1221 | ||
1222 | } | |
1223 | #endif // not BISON_POSITION_HH] | |
1224 | @output location.hh | |
1225 | b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004, 2005])[ | |
1226 | ||
1227 | /** | |
1228 | ** \file location.hh | |
1229 | ** Define the location class. | |
1230 | */ | |
1231 | ||
1232 | #ifndef BISON_LOCATION_HH | |
1233 | # define BISON_LOCATION_HH | |
1234 | ||
1235 | # include <iostream> | |
1236 | # include <string> | |
1237 | # include "position.hh" | |
1238 | ||
1239 | namespace yy | |
1240 | { | |
1241 | ||
1242 | /// Abstract a location. | |
1243 | class location | |
1244 | { | |
1245 | /** \name Ctor & dtor. | |
1246 | ** \{ */ | |
1247 | public: | |
1248 | /// Construct a location. | |
1249 | location () : | |
1250 | begin (), | |
1251 | end () | |
1252 | { | |
1253 | } | |
1254 | /** \} */ | |
1255 | ||
1256 | ||
1257 | /** \name Line and Column related manipulators | |
1258 | ** \{ */ | |
1259 | public: | |
1260 | /// Reset initial location to final location. | |
1261 | inline void step () | |
1262 | { | |
1263 | begin = end; | |
1264 | } | |
1265 | ||
1266 | /// Extend the current location to the COUNT next columns. | |
1267 | inline void columns (unsigned int count = 1) | |
1268 | { | |
1269 | end += count; | |
1270 | } | |
1271 | ||
1272 | /// Extend the current location to the COUNT next lines. | |
1273 | inline void lines (unsigned int count = 1) | |
1274 | { | |
1275 | end.lines (count); | |
1276 | } | |
1277 | /** \} */ | |
1278 | ||
1279 | ||
1280 | public: | |
1281 | /// Beginning of the located region. | |
1282 | position begin; | |
1283 | /// End of the located region. | |
1284 | position end; | |
1285 | }; | |
1286 | ||
1287 | /// Join two location objects to create a location. | |
1288 | inline const location operator+ (const location& begin, const location& end) | |
1289 | { | |
1290 | location res = begin; | |
1291 | res.end = end.end; | |
1292 | return res; | |
1293 | } | |
1294 | ||
1295 | /// Add two location objects. | |
1296 | inline const location operator+ (const location& begin, unsigned int width) | |
1297 | { | |
1298 | location res = begin; | |
1299 | res.columns (width); | |
1300 | return res; | |
1301 | } | |
1302 | ||
1303 | /// Add and assign a location. | |
1304 | inline location& operator+= (location& res, unsigned int width) | |
1305 | { | |
1306 | res.columns (width); | |
1307 | return res; | |
1308 | } | |
1309 | ||
1310 | /** \brief Intercept output stream redirection. | |
1311 | ** \param ostr the destination output stream | |
1312 | ** \param loc a reference to the location to redirect | |
1313 | ** | |
1314 | ** Avoid duplicate information. | |
1315 | */ | |
1316 | inline std::ostream& operator<< (std::ostream& ostr, const location& loc) | |
1317 | { | |
1318 | position last = loc.end - 1; | |
1319 | ostr << loc.begin; | |
1320 | if (last.filename | |
1321 | && (!loc.begin.filename | |
1322 | || *loc.begin.filename != *last.filename)) | |
1323 | ostr << '-' << last; | |
1324 | else if (loc.begin.line != last.line) | |
1325 | ostr << '-' << last.line << '.' << last.column; | |
1326 | else if (loc.begin.column != last.column) | |
1327 | ostr << '-' << last.column; | |
1328 | return ostr; | |
1329 | } | |
1330 | ||
1331 | } | |
1332 | ||
1333 | #endif // not BISON_LOCATION_HH] |