]>
Commit | Line | Data |
---|---|---|
a75c057f | 1 | m4_divert(-1) |
60491a94 | 2 | # C++ skeleton for Bison |
b61c6978 | 3 | # Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
60491a94 AD |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 2 of the License, or | |
8 | # (at your option) any later version. | |
9 | ||
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | ||
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | # 02111-1307 USA | |
19 | ||
66d30cd4 AD |
20 | ## ---------------- ## |
21 | ## Default values. ## | |
22 | ## ---------------- ## | |
23 | ||
66d30cd4 AD |
24 | # Default Parser class name. |
25 | m4_define_default([b4_parser_class_name], [Parser]) | |
26 | ||
27 | ||
28 | ||
29 | ## ----------------- ## | |
30 | ## Semantic Values. ## | |
31 | ## ----------------- ## | |
32 | ||
33 | ||
82b6cb3f AD |
34 | # b4_lhs_value([TYPE]) |
35 | # -------------------- | |
36 | # Expansion of $<TYPE>$. | |
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], | |
6ad762a8 | 46 | [semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])]) |
82b6cb3f | 47 | |
66d30cd4 | 48 | m4_define_default([b4_location_type], [Location]) |
82b6cb3f AD |
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], | |
6ad762a8 | 62 | [location_stack_@{m4_eval([$1 - $2])@}]) |
82b6cb3f AD |
63 | |
64 | ||
af27eacb | 65 | m4_define([b4_inherit], |
0d8bed56 | 66 | [m4_ifdef([b4_root], |
af27eacb RA |
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 | ||
98254360 | 83 | |
b526ee61 AD |
84 | # We do want M4 expansion after # for CPP macros. |
85 | m4_changecom() | |
98254360 | 86 | m4_divert(0)dnl |
b61c6978 PE |
87 | m4_if(b4_defines_flag, 0, [], |
88 | [@output @output_header_name@ | |
fb8135fa | 89 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
b61c6978 | 90 | [2002, 2003])[ |
c5e3e510 AD |
91 | /* FIXME: This is wrong, we want computed header guards. |
92 | I don't know why the macros are missing now. :( */ | |
93 | #ifndef PARSER_HEADER_H | |
94 | # define PARSER_HEADER_H | |
2b548aa6 RA |
95 | |
96 | #include "stack.hh" | |
2b548aa6 RA |
97 | #include "location.hh" |
98 | ||
8d69a1a3 | 99 | #include <string> |
717be197 | 100 | #include <iostream> |
50997c6e | 101 | |
4162fa07 | 102 | /* Using locations. */ |
c5e3e510 | 103 | #define YYLSP_NEEDED ]b4_locations_flag[ |
4162fa07 | 104 | |
c5e3e510 | 105 | ]b4_token_defines(b4_tokens)[ |
17acead5 | 106 | |
0dd1580a | 107 | /* Copy the first part of user declarations. */ |
c5e3e510 | 108 | ]b4_pre_prologue[ |
4162fa07 | 109 | |
996b1c7e | 110 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 111 | b4_syncline([@oline@], [@ofile@])[ |
e96c9728 | 112 | |
69e2658b RA |
113 | /* Enabling traces. */ |
114 | #ifndef YYDEBUG | |
c5e3e510 | 115 | # define YYDEBUG ]b4_debug[ |
69e2658b RA |
116 | #endif |
117 | ||
118 | /* Enabling verbose error message. */ | |
119 | #ifndef YYERROR_VERBOSE | |
c5e3e510 | 120 | # define YYERROR_VERBOSE ]b4_error_verbose[ |
69e2658b RA |
121 | #endif |
122 | ||
98254360 | 123 | #ifndef YYSTYPE |
c5e3e510 | 124 | ]m4_ifdef([b4_stype], |
437c2d80 | 125 | [b4_syncline([b4_stype_line], [b4_filename]) |
e96c9728 | 126 | typedef union b4_stype yystype; |
996b1c7e | 127 | /* Line __line__ of lalr1.cc. */ |
6ad762a8 | 128 | b4_syncline([@oline@], [@ofile@])], |
c5e3e510 | 129 | [typedef int yystype;])[ |
98254360 RA |
130 | # define YYSTYPE yystype |
131 | #endif | |
132 | ||
0dd1580a | 133 | /* Copy the second part of user declarations. */ |
c5e3e510 | 134 | ]b4_post_prologue[ |
0dd1580a | 135 | |
996b1c7e | 136 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 137 | b4_syncline([@oline@], [@ofile@])[ |
374f5a14 RA |
138 | #ifndef YYLLOC_DEFAULT |
139 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
7548fed2 | 140 | Current.end = Rhs[N].end; |
374f5a14 RA |
141 | #endif |
142 | ||
2b548aa6 RA |
143 | namespace yy |
144 | { | |
c5e3e510 | 145 | class ]b4_parser_class_name[; |
3f3eed27 | 146 | |
2b548aa6 RA |
147 | template < typename P > |
148 | struct Traits | |
149 | { | |
150 | }; | |
151 | ||
152 | template < > | |
c5e3e510 | 153 | struct Traits< ]b4_parser_class_name[ > |
2b548aa6 | 154 | { |
c5e3e510 AD |
155 | typedef ]b4_int_type_for([b4_translate])[ TokenNumberType; |
156 | typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType; | |
50997c6e RA |
157 | typedef int StateType; |
158 | typedef yystype SemanticType; | |
c5e3e510 | 159 | typedef ]b4_location_type[ LocationType; |
2b548aa6 RA |
160 | }; |
161 | } | |
162 | ||
2b548aa6 RA |
163 | namespace yy |
164 | { | |
c5e3e510 | 165 | class ]b4_parser_class_name b4_inherit[ |
2b548aa6 RA |
166 | { |
167 | public: | |
3f3eed27 | 168 | |
c5e3e510 AD |
169 | typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType; |
170 | typedef Traits< ]b4_parser_class_name[ >::RhsNumberType RhsNumberType; | |
171 | typedef Traits< ]b4_parser_class_name[ >::StateType StateType; | |
172 | typedef Traits< ]b4_parser_class_name[ >::SemanticType SemanticType; | |
173 | typedef Traits< ]b4_parser_class_name[ >::LocationType LocationType; | |
2b548aa6 RA |
174 | |
175 | typedef Stack< StateType > StateStack; | |
176 | typedef Stack< SemanticType > SemanticStack; | |
177 | typedef Stack< LocationType > LocationStack; | |
178 | ||
8d69a1a3 | 179 | #if YYLSP_NEEDED |
c5e3e510 AD |
180 | ]b4_parser_class_name[ (bool debug, |
181 | LocationType initlocation][]b4_param[) : | |
182 | ]b4_constructor[][debug_ (debug), | |
717be197 | 183 | cdebug_ (std::cerr), |
af27eacb | 184 | initlocation_ (initlocation) |
8d69a1a3 | 185 | #else |
c5e3e510 AD |
186 | ]b4_parser_class_name[ (bool debug][]b4_param[) : |
187 | ]b4_constructor[][debug_ (debug), | |
717be197 | 188 | cdebug_ (std::cerr) |
8d69a1a3 | 189 | #endif |
50997c6e | 190 | { |
50997c6e RA |
191 | } |
192 | ||
c5e3e510 | 193 | virtual ~]b4_parser_class_name[ () |
2b548aa6 | 194 | { |
2b548aa6 RA |
195 | } |
196 | ||
197 | virtual int parse (); | |
198 | ||
199 | private: | |
3f3eed27 | 200 | |
69e2658b | 201 | virtual void lex_ (); |
4bb2bc3f | 202 | virtual void error_ (); |
4aacc3a7 | 203 | virtual void print_ (); |
4bb2bc3f | 204 | |
2b548aa6 | 205 | /* Stacks. */ |
69e2658b RA |
206 | StateStack state_stack_; |
207 | SemanticStack semantic_stack_; | |
208 | LocationStack location_stack_; | |
2b548aa6 RA |
209 | |
210 | /* Tables. */ | |
c5e3e510 AD |
211 | static const ]b4_int_type_for([b4_pact])[ pact_[]; |
212 | static const ]b4_int_type_for([b4_pact])[ pact_ninf_; | |
213 | static const ]b4_int_type_for([b4_defact])[ defact_[]; | |
214 | static const ]b4_int_type_for([b4_pgoto])[ pgoto_[]; | |
215 | static const ]b4_int_type_for([b4_defgoto])[ defgoto_[]; | |
216 | static const ]b4_int_type_for([b4_table])[ table_[]; | |
217 | static const ]b4_int_type_for([b4_table])[ table_ninf_; | |
218 | static const ]b4_int_type_for([b4_check])[ check_[]; | |
219 | static const ]b4_int_type_for([b4_r1])[ r1_[]; | |
220 | static const ]b4_int_type_for([b4_r2])[ r2_[]; | |
69e2658b RA |
221 | |
222 | #if YYDEBUG || YYERROR_VERBOSE | |
c5e3e510 | 223 | static const char* const name_[]; |
69e2658b | 224 | #endif |
2b548aa6 RA |
225 | |
226 | /* More tables, for debugging. */ | |
69e2658b | 227 | #if YYDEBUG |
c5e3e510 AD |
228 | static const RhsNumberType rhs_[]; |
229 | static const ]b4_int_type_for([b4_prhs])[ prhs_[]; | |
230 | static const ]b4_int_type_for([b4_rline])[ rline_[]; | |
231 | static const ]b4_int_type_for([b4_stos])[ stos_[]; | |
232 | static const ]b4_int_type_for([b4_toknum])[ token_number_[]; | |
69e2658b | 233 | #endif |
2b548aa6 RA |
234 | |
235 | /* Even more tables. */ | |
680e8701 | 236 | static inline TokenNumberType translate_ (int token); |
2b548aa6 | 237 | |
762a801e | 238 | /* Constants. */ |
50997c6e | 239 | static const int eof_; |
39912f52 | 240 | /* LAST_ -- Last index in TABLE_. */ |
69e2658b | 241 | static const int last_; |
69e2658b | 242 | static const int nnts_; |
50997c6e | 243 | static const int empty_; |
69e2658b | 244 | static const int final_; |
762a801e RA |
245 | static const int terror_; |
246 | static const int errcode_; | |
50997c6e | 247 | static const int ntokens_; |
007a50a4 AD |
248 | static const unsigned user_token_number_max_; |
249 | static const TokenNumberType undef_token_; | |
2b548aa6 RA |
250 | |
251 | /* State. */ | |
69e2658b RA |
252 | int n_; |
253 | int len_; | |
69e2658b | 254 | int state_; |
4bb2bc3f | 255 | |
717be197 AD |
256 | /* Debugging. */ |
257 | int debug_; | |
258 | std::ostream &cdebug_; | |
259 | ||
69e2658b RA |
260 | /* Lookahead and lookahead in internal form. */ |
261 | int looka_; | |
262 | int ilooka_; | |
4bb2bc3f RA |
263 | |
264 | /* Message. */ | |
265 | std::string message; | |
266 | ||
374f5a14 | 267 | /* Semantic value and location of lookahead token. */ |
2b548aa6 RA |
268 | SemanticType value; |
269 | LocationType location; | |
8d69a1a3 | 270 | |
6ad762a8 | 271 | /* @@$ and $$. */ |
374f5a14 RA |
272 | SemanticType yyval; |
273 | LocationType yyloc; | |
274 | ||
8d69a1a3 RA |
275 | /* Initial location. */ |
276 | LocationType initlocation_; | |
2b548aa6 RA |
277 | }; |
278 | } | |
279 | ||
c5e3e510 | 280 | #endif /* ! defined PARSER_HEADER_H */] |
b61c6978 | 281 | ])dnl |
6ad762a8 | 282 | @output @output_parser_name@ |
fb8135fa | 283 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
b61c6978 | 284 | [2002, 2003]) |
98254360 | 285 | |
b61c6978 | 286 | m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ |
50997c6e | 287 | |
2b548aa6 | 288 | /* Enable debugging if requested. */ |
50997c6e | 289 | #if YYDEBUG |
717be197 | 290 | # define YYCDEBUG if (debug_) cdebug_ |
2b548aa6 | 291 | #else /* !YYDEBUG */ |
717be197 | 292 | # define YYCDEBUG if (0) cdebug_ |
2b548aa6 RA |
293 | #endif /* !YYDEBUG */ |
294 | ||
60a777aa AD |
295 | #define YYACCEPT goto yyacceptlab |
296 | #define YYABORT goto yyabortlab | |
297 | #define YYERROR goto yyerrlab1 | |
298 | ||
299 | ||
2b548aa6 | 300 | int |
c5e3e510 | 301 | yy::]b4_parser_class_name[::parse () |
2b548aa6 | 302 | { |
4bb2bc3f RA |
303 | int nerrs = 0; |
304 | int errstatus = 0; | |
305 | ||
3ae831b4 AD |
306 | /* Initialize the stacks. The initial state will be pushed in |
307 | yynewstate, since the latter expects the semantical and the | |
308 | location values to have been already stored, initialize these | |
309 | stacks with a primary value. */ | |
69e2658b RA |
310 | state_stack_ = StateStack (0); |
311 | semantic_stack_ = SemanticStack (1); | |
312 | location_stack_ = LocationStack (1); | |
2b548aa6 | 313 | |
2b548aa6 | 314 | /* Start. */ |
69e2658b RA |
315 | state_ = 0; |
316 | looka_ = empty_; | |
8d69a1a3 RA |
317 | #if YYLSP_NEEDED |
318 | location = initlocation_; | |
319 | #endif | |
717be197 | 320 | YYCDEBUG << "Starting parse" << std::endl; |
2b548aa6 RA |
321 | |
322 | /* New state. */ | |
323 | yynewstate: | |
69e2658b | 324 | state_stack_.push (state_); |
717be197 | 325 | YYCDEBUG << "Entering state " << state_ << std::endl; |
50997c6e | 326 | goto yybackup; |
2b548aa6 RA |
327 | |
328 | /* Backup. */ | |
329 | yybackup: | |
330 | ||
331 | /* Try to take a decision without lookahead. */ | |
c5e3e510 | 332 | n_ = pact_[state_]; |
12b0043a | 333 | if (n_ == pact_ninf_) |
2b548aa6 RA |
334 | goto yydefault; |
335 | ||
336 | /* Read a lookahead token. */ | |
69e2658b | 337 | if (looka_ == empty_) |
2b548aa6 | 338 | { |
717be197 | 339 | YYCDEBUG << "Reading a token: "; |
69e2658b | 340 | lex_ (); |
2b548aa6 RA |
341 | } |
342 | ||
343 | /* Convert token to internal form. */ | |
69e2658b | 344 | if (looka_ <= 0) |
2b548aa6 | 345 | { |
69e2658b RA |
346 | looka_ = eof_; |
347 | ilooka_ = 0; | |
717be197 | 348 | YYCDEBUG << "Now at end of input." << std::endl; |
2b548aa6 RA |
349 | } |
350 | else | |
351 | { | |
69e2658b | 352 | ilooka_ = translate_ (looka_); |
50997c6e RA |
353 | #if YYDEBUG |
354 | if (debug_) | |
355 | { | |
717be197 | 356 | YYCDEBUG << "Next token is " << looka_ |
c5e3e510 | 357 | << " (" << name_[ilooka_]; |
4aacc3a7 | 358 | print_ (); |
717be197 | 359 | YYCDEBUG << ')' << std::endl; |
50997c6e | 360 | } |
2b548aa6 RA |
361 | #endif |
362 | } | |
363 | ||
69e2658b | 364 | n_ += ilooka_; |
c5e3e510 | 365 | if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_) |
2b548aa6 RA |
366 | goto yydefault; |
367 | ||
368 | /* Reduce or error. */ | |
c5e3e510 | 369 | n_ = table_[n_]; |
69e2658b | 370 | if (n_ < 0) |
2b548aa6 | 371 | { |
12b0043a | 372 | if (n_ == table_ninf_) |
2b548aa6 RA |
373 | goto yyerrlab; |
374 | else | |
375 | { | |
69e2658b | 376 | n_ = -n_; |
2b548aa6 RA |
377 | goto yyreduce; |
378 | } | |
379 | } | |
69e2658b | 380 | else if (n_ == 0) |
2b548aa6 | 381 | goto yyerrlab; |
a75c057f | 382 | |
2b548aa6 | 383 | /* Accept? */ |
69e2658b | 384 | if (n_ == final_) |
2b548aa6 RA |
385 | goto yyacceptlab; |
386 | ||
387 | /* Shift the lookahead token. */ | |
fc049e9c | 388 | #if YYDEBUG |
717be197 | 389 | YYCDEBUG << "Shifting token " << looka_ |
fc049e9c AD |
390 | << " (" << name_[ilooka_] << "), "; |
391 | #endif | |
2b548aa6 RA |
392 | |
393 | /* Discard the token being shifted unless it is eof. */ | |
69e2658b RA |
394 | if (looka_ != eof_) |
395 | looka_ = empty_; | |
2b548aa6 | 396 | |
69e2658b RA |
397 | semantic_stack_.push (value); |
398 | location_stack_.push (location); | |
8d69a1a3 RA |
399 | |
400 | /* Count tokens shifted since error; after three, turn off error | |
401 | status. */ | |
402 | if (errstatus) | |
403 | --errstatus; | |
404 | ||
69e2658b | 405 | state_ = n_; |
2b548aa6 RA |
406 | goto yynewstate; |
407 | ||
408 | /* Default action. */ | |
409 | yydefault: | |
c5e3e510 | 410 | n_ = defact_[state_]; |
69e2658b | 411 | if (n_ == 0) |
2b548aa6 | 412 | goto yyerrlab; |
50997c6e | 413 | goto yyreduce; |
2b548aa6 RA |
414 | |
415 | /* Reduce. */ | |
416 | yyreduce: | |
c5e3e510 | 417 | len_ = r2_[n_]; |
69e2658b | 418 | if (len_) |
50997c6e | 419 | { |
c5e3e510 AD |
420 | yyval = semantic_stack_[len_ - 1]; |
421 | yyloc = location_stack_[len_ - 1]; | |
50997c6e RA |
422 | } |
423 | else | |
69e2658b | 424 | { |
c5e3e510 AD |
425 | yyval = semantic_stack_[0]; |
426 | yyloc = location_stack_[0]; | |
50997c6e | 427 | } |
2b548aa6 | 428 | |
50997c6e RA |
429 | #if YYDEBUG |
430 | if (debug_) | |
2b548aa6 | 431 | { |
0d1c3a04 AD |
432 | // Short files will use "unsigned char" for line numbers, |
433 | // in which case they will be output as character litterals | |
434 | // by "<<". | |
f939fc12 | 435 | unsigned yylineno = rline_[n_]; |
717be197 | 436 | YYCDEBUG << "Reducing via rule " << n_ - 1 |
f939fc12 | 437 | << " (line " << yylineno << "), "; |
c5e3e510 AD |
438 | for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; |
439 | 0 <= rhs_[i]; ++i) | |
440 | YYCDEBUG << name_[rhs_[i]] << ' '; | |
441 | YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl; | |
2b548aa6 RA |
442 | } |
443 | #endif | |
a75c057f | 444 | |
374f5a14 RA |
445 | if (len_) |
446 | { | |
447 | Slice< LocationType, LocationStack > slice (location_stack_, len_); | |
448 | YYLLOC_DEFAULT (yyloc, slice, len_); | |
449 | } | |
450 | ||
45119f04 RA |
451 | switch (n_) |
452 | { | |
c5e3e510 | 453 | ]b4_actions[ |
45119f04 | 454 | } |
a75c057f | 455 | |
996b1c7e | 456 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 457 | b4_syncline([@oline@], [@ofile@])[ |
06446ccf | 458 | |
69e2658b RA |
459 | state_stack_.pop (len_); |
460 | semantic_stack_.pop (len_); | |
461 | location_stack_.pop (len_); | |
2b548aa6 | 462 | |
50997c6e RA |
463 | #if YYDEBUG |
464 | if (debug_) | |
2b548aa6 | 465 | { |
717be197 | 466 | YYCDEBUG << "state stack now"; |
a75c057f | 467 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 468 | i != state_stack_.end (); ++i) |
717be197 AD |
469 | YYCDEBUG << ' ' << *i; |
470 | YYCDEBUG << std::endl; | |
2b548aa6 RA |
471 | } |
472 | #endif | |
a75c057f | 473 | |
374f5a14 RA |
474 | semantic_stack_.push (yyval); |
475 | location_stack_.push (yyloc); | |
2b548aa6 RA |
476 | |
477 | /* Shift the result of the reduction. */ | |
c5e3e510 AD |
478 | n_ = r1_[n_]; |
479 | state_ = pgoto_[n_ - ntokens_] + state_stack_[0]; | |
480 | if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0]) | |
481 | state_ = table_[state_]; | |
2b548aa6 | 482 | else |
c5e3e510 | 483 | state_ = defgoto_[n_ - ntokens_]; |
2b548aa6 RA |
484 | goto yynewstate; |
485 | ||
486 | /* Report and recover from errors. This is very incomplete. */ | |
487 | yyerrlab: | |
4bb2bc3f RA |
488 | /* If not already recovering from an error, report this error. */ |
489 | if (!errstatus) | |
490 | { | |
491 | ++nerrs; | |
a75c057f | 492 | |
69e2658b | 493 | #if YYERROR_VERBOSE |
c5e3e510 | 494 | n_ = pact_[state_]; |
12b0043a | 495 | if (pact_ninf_ < n_ && n_ < last_) |
4bb2bc3f | 496 | { |
6e649e65 | 497 | message = "syntax error, unexpected "; |
c5e3e510 | 498 | message += name_[ilooka_]; |
4bb2bc3f RA |
499 | { |
500 | int count = 0; | |
69e2658b | 501 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
c5e3e510 | 502 | if (check_[x + n_] == x && x != terror_) |
4bb2bc3f RA |
503 | ++count; |
504 | if (count < 5) | |
505 | { | |
506 | count = 0; | |
69e2658b | 507 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
c5e3e510 | 508 | if (check_[x + n_] == x && x != terror_) |
4bb2bc3f | 509 | { |
a75c057f | 510 | message += (!count++) ? ", expecting " : " or "; |
c5e3e510 | 511 | message += name_[x]; |
4bb2bc3f RA |
512 | } |
513 | } | |
514 | } | |
515 | } | |
516 | else | |
69e2658b | 517 | #endif |
6e649e65 | 518 | message = "syntax error"; |
8d69a1a3 | 519 | error_ (); |
4bb2bc3f | 520 | } |
762a801e | 521 | goto yyerrlab1; |
a75c057f | 522 | |
60a777aa AD |
523 | |
524 | /*----------------------------------------------------. | |
525 | | yyerrlab1 -- error raised explicitly by an action. | | |
526 | `----------------------------------------------------*/ | |
762a801e RA |
527 | yyerrlab1: |
528 | if (errstatus == 3) | |
529 | { | |
530 | /* If just tried and failed to reuse lookahead token after an | |
531 | error, discard it. */ | |
532 | ||
533 | /* Return failure if at end of input. */ | |
69e2658b | 534 | if (looka_ == eof_) |
762a801e | 535 | goto yyabortlab; |
7548fed2 | 536 | #if YYDEBUG |
717be197 | 537 | YYCDEBUG << "Discarding token " << looka_ |
7548fed2 AD |
538 | << " (" << name_[ilooka_] << ")." << std::endl; |
539 | #endif | |
69e2658b | 540 | looka_ = empty_; |
762a801e RA |
541 | } |
542 | ||
543 | /* Else will try to reuse lookahead token after shifting the error | |
544 | token. */ | |
545 | ||
546 | errstatus = 3; | |
762a801e | 547 | |
769b430f AD |
548 | for (;;) |
549 | { | |
c5e3e510 | 550 | n_ = pact_[state_]; |
12b0043a | 551 | if (n_ != pact_ninf_) |
769b430f AD |
552 | { |
553 | n_ += terror_; | |
c5e3e510 | 554 | if (0 <= n_ && n_ <= last_ && check_[n_] == terror_) |
769b430f | 555 | { |
c5e3e510 | 556 | n_ = table_[n_]; |
769b430f AD |
557 | if (0 < n_) |
558 | break; | |
559 | } | |
560 | } | |
561 | ||
562 | /* Pop the current state because it cannot handle the error token. */ | |
3ae831b4 | 563 | if (state_stack_.height () == 1) |
769b430f | 564 | goto yyabortlab; |
762a801e RA |
565 | |
566 | #if YYDEBUG | |
769b430f AD |
567 | if (debug_) |
568 | { | |
c5e3e510 | 569 | if (stos_[state_] < ntokens_) |
769b430f | 570 | { |
717be197 | 571 | YYCDEBUG << "Error: popping token " |
c5e3e510 AD |
572 | << token_number_[stos_[state_]] |
573 | << " (" << name_[stos_[state_]]; | |
769b430f | 574 | # ifdef YYPRINT |
c5e3e510 | 575 | YYPRINT (stderr, token_number_[stos_[state_]], |
769b430f AD |
576 | semantic_stack_.top ()); |
577 | # endif | |
717be197 | 578 | YYCDEBUG << ')' << std::endl; |
769b430f AD |
579 | } |
580 | else | |
581 | { | |
717be197 | 582 | YYCDEBUG << "Error: popping nonterminal (" |
c5e3e510 | 583 | << name_[stos_[state_]] << ')' << std::endl; |
769b430f AD |
584 | } |
585 | } | |
762a801e RA |
586 | #endif |
587 | ||
c5e3e510 | 588 | state_ = (state_stack_.pop (), state_stack_[0]); |
769b430f AD |
589 | semantic_stack_.pop (); |
590 | location_stack_.pop ();; | |
762a801e | 591 | |
769b430f AD |
592 | #if YYDEBUG |
593 | if (debug_) | |
594 | { | |
717be197 | 595 | YYCDEBUG << "Error: state stack now"; |
769b430f AD |
596 | for (StateStack::ConstIterator i = state_stack_.begin (); |
597 | i != state_stack_.end (); ++i) | |
717be197 AD |
598 | YYCDEBUG << ' ' << *i; |
599 | YYCDEBUG << std::endl; | |
769b430f AD |
600 | } |
601 | #endif | |
762a801e | 602 | } |
762a801e | 603 | |
69e2658b | 604 | if (n_ == final_) |
762a801e RA |
605 | goto yyacceptlab; |
606 | ||
717be197 | 607 | YYCDEBUG << "Shifting error token, "; |
762a801e | 608 | |
69e2658b RA |
609 | semantic_stack_.push (value); |
610 | location_stack_.push (location); | |
762a801e | 611 | |
69e2658b | 612 | state_ = n_; |
762a801e RA |
613 | goto yynewstate; |
614 | ||
2b548aa6 RA |
615 | /* Accept. */ |
616 | yyacceptlab: | |
617 | return 0; | |
762a801e RA |
618 | |
619 | /* Abort. */ | |
620 | yyabortlab: | |
621 | return 1; | |
2b548aa6 RA |
622 | } |
623 | ||
69e2658b | 624 | void |
c5e3e510 | 625 | yy::]b4_parser_class_name[::lex_ () |
69e2658b RA |
626 | { |
627 | #if YYLSP_NEEDED | |
628 | looka_ = yylex (&value, &location); | |
629 | #else | |
630 | looka_ = yylex (&value); | |
631 | #endif | |
632 | } | |
633 | ||
c5e3e510 | 634 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
2b548aa6 | 635 | STATE-NUM. */ |
c5e3e510 AD |
636 | const ]b4_int_type_for([b4_pact]) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[; |
637 | const ]b4_int_type_for([b4_pact])[ | |
638 | yy::]b4_parser_class_name[::pact_[] = | |
2b548aa6 | 639 | { |
c5e3e510 | 640 | ]b4_pact[ |
2b548aa6 RA |
641 | }; |
642 | ||
c5e3e510 | 643 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
644 | doesn't specify something else to do. Zero means the default is an |
645 | error. */ | |
c5e3e510 AD |
646 | const ]b4_int_type_for([b4_defact])[ |
647 | yy::]b4_parser_class_name[::defact_[] = | |
2b548aa6 | 648 | { |
c5e3e510 | 649 | ]b4_defact[ |
2b548aa6 RA |
650 | }; |
651 | ||
c5e3e510 AD |
652 | /* YYPGOTO[NTERM-NUM]. */ |
653 | const ]b4_int_type_for([b4_pgoto])[ | |
654 | yy::]b4_parser_class_name[::pgoto_[] = | |
2b548aa6 | 655 | { |
c5e3e510 | 656 | ]b4_pgoto[ |
2b548aa6 RA |
657 | }; |
658 | ||
c5e3e510 AD |
659 | /* YYDEFGOTO[NTERM-NUM]. */ |
660 | const ]b4_int_type_for([b4_defgoto])[ | |
661 | yy::]b4_parser_class_name[::defgoto_[] = | |
2b548aa6 | 662 | { |
c5e3e510 | 663 | ]b4_defgoto[ |
2b548aa6 RA |
664 | }; |
665 | ||
c5e3e510 | 666 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
667 | positive, shift that token. If negative, reduce the rule which |
668 | number is the opposite. If zero, do what YYDEFACT says. */ | |
c5e3e510 AD |
669 | const ]b4_int_type_for([b4_table]) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[; |
670 | const ]b4_int_type_for([b4_table])[ | |
671 | yy::]b4_parser_class_name[::table_[] = | |
2b548aa6 | 672 | { |
c5e3e510 | 673 | ]b4_table[ |
2b548aa6 RA |
674 | }; |
675 | ||
676 | /* YYCHECK. */ | |
c5e3e510 AD |
677 | const ]b4_int_type_for([b4_check])[ |
678 | yy::]b4_parser_class_name[::check_[] = | |
2b548aa6 | 679 | { |
c5e3e510 | 680 | ]b4_check[ |
2b548aa6 RA |
681 | }; |
682 | ||
769b430f | 683 | #if YYDEBUG |
c5e3e510 | 684 | /* STOS_[STATE-NUM] -- The (internal number of the) accessing |
769b430f | 685 | symbol of state STATE-NUM. */ |
c5e3e510 AD |
686 | const ]b4_int_type_for([b4_stos])[ |
687 | yy::]b4_parser_class_name[::stos_[] = | |
769b430f | 688 | { |
c5e3e510 | 689 | ]b4_stos[ |
769b430f AD |
690 | }; |
691 | ||
c5e3e510 | 692 | /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding |
769b430f | 693 | to YYLEX-NUM. */ |
c5e3e510 AD |
694 | const ]b4_int_type_for([b4_toknum])[ |
695 | yy::]b4_parser_class_name[::token_number_[] = | |
769b430f | 696 | { |
c5e3e510 | 697 | ]b4_toknum[ |
769b430f AD |
698 | }; |
699 | #endif | |
700 | ||
c5e3e510 AD |
701 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
702 | const ]b4_int_type_for([b4_r1])[ | |
703 | yy::]b4_parser_class_name[::r1_[] = | |
2b548aa6 | 704 | { |
c5e3e510 | 705 | ]b4_r1[ |
2b548aa6 RA |
706 | }; |
707 | ||
c5e3e510 AD |
708 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
709 | const ]b4_int_type_for([b4_r2])[ | |
710 | yy::]b4_parser_class_name[::r2_[] = | |
2b548aa6 | 711 | { |
c5e3e510 | 712 | ]b4_r2[ |
2b548aa6 RA |
713 | }; |
714 | ||
69e2658b | 715 | #if YYDEBUG || YYERROR_VERBOSE |
c5e3e510 | 716 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
717 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
718 | const char* | |
c5e3e510 | 719 | const yy::]b4_parser_class_name[::name_[] = |
2b548aa6 | 720 | { |
c5e3e510 | 721 | ]b4_tname[ |
2b548aa6 | 722 | }; |
69e2658b | 723 | #endif |
2b548aa6 | 724 | |
69e2658b | 725 | #if YYDEBUG |
2b548aa6 | 726 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
c5e3e510 AD |
727 | const yy::]b4_parser_class_name[::RhsNumberType |
728 | yy::]b4_parser_class_name[::rhs_[] = | |
2b548aa6 | 729 | { |
c5e3e510 | 730 | ]b4_rhs[ |
2b548aa6 RA |
731 | }; |
732 | ||
c5e3e510 | 733 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 734 | YYRHS. */ |
c5e3e510 AD |
735 | const ]b4_int_type_for([b4_prhs])[ |
736 | yy::]b4_parser_class_name[::prhs_[] = | |
2b548aa6 | 737 | { |
c5e3e510 | 738 | ]b4_prhs[ |
2b548aa6 RA |
739 | }; |
740 | ||
c5e3e510 AD |
741 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ |
742 | const ]b4_int_type_for([b4_rline])[ | |
743 | yy::]b4_parser_class_name[::rline_[] = | |
69e2658b | 744 | { |
c5e3e510 | 745 | ]b4_rline[ |
69e2658b RA |
746 | }; |
747 | #endif | |
748 | ||
2b548aa6 | 749 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
c5e3e510 AD |
750 | yy::]b4_parser_class_name[::TokenNumberType |
751 | yy::]b4_parser_class_name[::translate_ (int token) | |
2b548aa6 | 752 | { |
a75c057f | 753 | static |
680e8701 | 754 | const TokenNumberType |
c5e3e510 | 755 | translate_[] = |
2b548aa6 | 756 | { |
c5e3e510 | 757 | ]b4_translate[ |
2b548aa6 | 758 | }; |
007a50a4 | 759 | if ((unsigned) token <= user_token_number_max_) |
c5e3e510 | 760 | return translate_[token]; |
007a50a4 AD |
761 | else |
762 | return undef_token_; | |
2b548aa6 RA |
763 | } |
764 | ||
c5e3e510 AD |
765 | const int yy::]b4_parser_class_name[::eof_ = 0; |
766 | const int yy::]b4_parser_class_name[::last_ = ]b4_last[; | |
767 | const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[; | |
768 | const int yy::]b4_parser_class_name[::empty_ = -2; | |
769 | const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[; | |
770 | const int yy::]b4_parser_class_name[::terror_ = 1; | |
771 | const int yy::]b4_parser_class_name[::errcode_ = 256; | |
772 | const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[; | |
66d30cd4 | 773 | |
c5e3e510 AD |
774 | const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[; |
775 | const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[; | |
2b548aa6 | 776 | |
c5e3e510 | 777 | ]b4_epilogue |
21846f69 | 778 | dnl |
6ad762a8 | 779 | @output stack.hh |
7548fed2 | 780 | b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[ |
98254360 | 781 | |
2b548aa6 RA |
782 | #ifndef BISON_STACK_HH |
783 | # define BISON_STACK_HH | |
784 | ||
45119f04 | 785 | #include <deque> |
2b548aa6 RA |
786 | |
787 | namespace yy | |
788 | { | |
45119f04 | 789 | template < class T, class S = std::deque< T > > |
2b548aa6 RA |
790 | class Stack |
791 | { | |
792 | public: | |
793 | ||
794 | typedef typename S::iterator Iterator; | |
795 | typedef typename S::const_iterator ConstIterator; | |
796 | ||
797 | Stack () : seq_ () | |
798 | { | |
799 | } | |
800 | ||
801 | Stack (unsigned n) : seq_ (n) | |
802 | { | |
803 | } | |
804 | ||
805 | inline | |
806 | T& | |
c5e3e510 | 807 | operator [] (unsigned index) |
2b548aa6 | 808 | { |
c5e3e510 | 809 | return seq_[index]; |
2b548aa6 RA |
810 | } |
811 | ||
812 | inline | |
813 | const T& | |
c5e3e510 | 814 | operator [] (unsigned index) const |
2b548aa6 | 815 | { |
c5e3e510 | 816 | return seq_[index]; |
2b548aa6 RA |
817 | } |
818 | ||
819 | inline | |
820 | void | |
821 | push (const T& t) | |
822 | { | |
45119f04 | 823 | seq_.push_front (t); |
2b548aa6 RA |
824 | } |
825 | ||
826 | inline | |
827 | void | |
828 | pop (unsigned n = 1) | |
829 | { | |
830 | for (; n; --n) | |
45119f04 | 831 | seq_.pop_front (); |
2b548aa6 RA |
832 | } |
833 | ||
762a801e RA |
834 | inline |
835 | unsigned | |
836 | height () const | |
837 | { | |
838 | return seq_.size (); | |
839 | } | |
840 | ||
2b548aa6 RA |
841 | inline ConstIterator begin () const { return seq_.begin (); } |
842 | inline ConstIterator end () const { return seq_.end (); } | |
843 | ||
844 | private: | |
845 | ||
846 | S seq_; | |
847 | }; | |
374f5a14 RA |
848 | |
849 | template < class T, class S = Stack< T > > | |
850 | class Slice | |
851 | { | |
852 | public: | |
853 | ||
854 | Slice (const S& stack, | |
855 | unsigned range) : stack_ (stack), | |
856 | range_ (range) | |
857 | { | |
858 | } | |
859 | ||
860 | inline | |
861 | const T& | |
c5e3e510 | 862 | operator [] (unsigned index) const |
374f5a14 | 863 | { |
c5e3e510 | 864 | return stack_[range_ - index]; |
374f5a14 RA |
865 | } |
866 | ||
867 | private: | |
868 | ||
869 | const S& stack_; | |
870 | unsigned range_; | |
871 | }; | |
2b548aa6 RA |
872 | } |
873 | ||
c5e3e510 | 874 | #endif // not BISON_STACK_HH] |
21846f69 | 875 | dnl |
5d003116 AD |
876 | @output position.hh |
877 | b4_copyright([Position class for Bison C++ parsers], [2002, 2003])[ | |
98254360 | 878 | |
5d003116 AD |
879 | /** |
880 | ** \file position.hh | |
881 | ** Define the Location class. | |
882 | */ | |
883 | ||
884 | #ifndef BISON_POSITION_HH | |
885 | # define BISON_POSITION_HH | |
2b548aa6 | 886 | |
7548fed2 AD |
887 | # include <iostream> |
888 | # include <string> | |
889 | ||
2b548aa6 RA |
890 | namespace yy |
891 | { | |
5d003116 | 892 | /** \brief Abstract a Position. */ |
7548fed2 | 893 | class Position |
2b548aa6 | 894 | { |
7548fed2 | 895 | public: |
5d003116 AD |
896 | /** \brief Initial column number. */ |
897 | static const unsigned int initial_column = 0; | |
898 | /** \brief Initial line number. */ | |
899 | static const unsigned int initial_line = 1; | |
900 | ||
901 | /** \name Ctor & dtor. | |
902 | ** \{ */ | |
903 | public: | |
904 | /** \brief Construct a Position. */ | |
905 | Position () : | |
906 | filename (), | |
907 | line (initial_line), | |
908 | column (initial_column) | |
909 | { | |
910 | } | |
911 | /** \} */ | |
912 | ||
7548fed2 | 913 | |
5d003116 AD |
914 | /** \name Line and Column related manipulators |
915 | ** \{ */ | |
916 | public: | |
917 | /** \brief (line related) Advance to the LINES next lines. */ | |
918 | inline void lines (int lines = 1) | |
919 | { | |
920 | column = initial_column; | |
921 | line += lines; | |
922 | } | |
923 | ||
924 | /** \brief (column related) Advance to the COLUMNS next columns. */ | |
925 | inline void columns (int columns = 1) | |
926 | { | |
f939fc12 AD |
927 | int leftmost = initial_column; |
928 | int current = column; | |
929 | if (leftmost <= current + columns) | |
2cdc240e AD |
930 | column += columns; |
931 | else | |
932 | column = initial_column; | |
5d003116 AD |
933 | } |
934 | /** \} */ | |
935 | ||
936 | public: | |
937 | /** \brief File name to which this position refers. */ | |
7548fed2 | 938 | std::string filename; |
5d003116 AD |
939 | /** \brief Current line number. */ |
940 | unsigned int line; | |
941 | /** \brief Current column number. */ | |
942 | unsigned int column; | |
2b548aa6 RA |
943 | }; |
944 | ||
5d003116 AD |
945 | /** \brief Add and assign a Position. */ |
946 | inline const Position& | |
947 | operator+= (Position& res, const int width) | |
948 | { | |
949 | res.columns (width); | |
950 | return res; | |
951 | } | |
952 | ||
953 | /** \brief Add two Position objects. */ | |
954 | inline const Position | |
955 | operator+ (const Position& begin, const int width) | |
956 | { | |
957 | Position res = begin; | |
958 | return res += width; | |
959 | } | |
960 | ||
961 | /** \brief Add and assign a Position. */ | |
962 | inline const Position& | |
963 | operator-= (Position& res, const int width) | |
964 | { | |
965 | return res += -width; | |
966 | } | |
967 | ||
968 | /** \brief Add two Position objects. */ | |
969 | inline const Position | |
970 | operator- (const Position& begin, const int width) | |
971 | { | |
972 | return begin + -width; | |
973 | } | |
974 | ||
975 | /** \brief Intercept output stream redirection. | |
976 | ** \param ostr the destination output stream | |
977 | ** \param pos a reference to the Position to redirect | |
978 | */ | |
7548fed2 AD |
979 | inline std::ostream& |
980 | operator<< (std::ostream& ostr, const Position& pos) | |
981 | { | |
982 | if (pos.filename != "") | |
983 | ostr << pos.filename << ':'; | |
5d003116 | 984 | return ostr << pos.line << '.' << pos.column; |
7548fed2 AD |
985 | } |
986 | ||
5d003116 AD |
987 | } |
988 | #endif // not BISON_POSITION_HH] | |
989 | @output location.hh | |
990 | b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[ | |
7548fed2 | 991 | |
5d003116 AD |
992 | /** |
993 | ** \file location.hh | |
994 | ** Define the Location class. | |
995 | */ | |
7548fed2 | 996 | |
5d003116 AD |
997 | #ifndef BISON_LOCATION_HH |
998 | # define BISON_LOCATION_HH | |
999 | ||
1000 | # include <iostream> | |
1001 | # include <string> | |
1002 | # include "position.hh" | |
1003 | ||
1004 | namespace yy | |
1005 | { | |
1006 | ||
1007 | /** \brief Abstract a Location. */ | |
7548fed2 | 1008 | class Location |
2b548aa6 | 1009 | { |
5d003116 AD |
1010 | /** \name Ctor & dtor. |
1011 | ** \{ */ | |
7548fed2 | 1012 | public: |
5d003116 AD |
1013 | /** \brief Construct a Location. */ |
1014 | Location (void) : | |
1015 | begin (), | |
1016 | end () | |
1017 | { | |
1018 | } | |
1019 | /** \} */ | |
1020 | ||
1021 | ||
1022 | /** \name Line and Column related manipulators | |
1023 | ** \{ */ | |
1024 | public: | |
1025 | /** \brief Reset initial location to final location. */ | |
1026 | inline void step (void) | |
1027 | { | |
1028 | begin = end; | |
1029 | } | |
1030 | ||
1031 | /** \brief Extend the current location to the COLUMNS next columns. */ | |
1032 | inline void columns (unsigned columns = 1) | |
1033 | { | |
1034 | end += columns; | |
1035 | } | |
1036 | ||
1037 | /** \brief Extend the current location to the LINES next lines. */ | |
1038 | inline void lines (unsigned lines = 1) | |
1039 | { | |
1040 | end.lines (lines); | |
1041 | } | |
1042 | /** \} */ | |
1043 | ||
1044 | ||
1045 | public: | |
1046 | /** \brief Beginning of the located region. */ | |
7548fed2 | 1047 | Position begin; |
5d003116 | 1048 | /** \brief End of the located region. */ |
7548fed2 | 1049 | Position end; |
2b548aa6 | 1050 | }; |
7548fed2 | 1051 | |
5d003116 AD |
1052 | /** \brief Join two Location objects to create a Location. */ |
1053 | inline const Location operator+ (const Location& begin, const Location& end) | |
1054 | { | |
1055 | Location res = begin; | |
1056 | res.end = end.end; | |
1057 | return res; | |
1058 | } | |
1059 | ||
1060 | /** \brief Add two Location objects */ | |
1061 | inline const Location operator+ (const Location& begin, unsigned width) | |
1062 | { | |
1063 | Location res = begin; | |
1064 | res.columns (width); | |
1065 | return res; | |
1066 | } | |
7548fed2 | 1067 | |
5d003116 AD |
1068 | /** \brief Add and assign a Location */ |
1069 | inline Location &operator+= (Location& res, unsigned width) | |
1070 | { | |
1071 | res.columns (width); | |
1072 | return res; | |
1073 | } | |
1074 | ||
1075 | /** \brief Intercept output stream redirection. | |
1076 | ** \param ostr the destination output stream | |
2cdc240e | 1077 | ** \param loc a reference to the Location to redirect |
5d003116 | 1078 | ** |
2cdc240e | 1079 | ** Avoid duplicate information. |
5d003116 | 1080 | */ |
2cdc240e | 1081 | inline std::ostream& operator<< (std::ostream& ostr, const Location& loc) |
7548fed2 | 1082 | { |
2cdc240e AD |
1083 | Position last = loc.end - 1; |
1084 | ostr << loc.begin; | |
1085 | if (loc.begin.filename != last.filename) | |
1086 | ostr << '-' << last; | |
1087 | else if (loc.begin.line != last.line) | |
1088 | ostr << '-' << last.line << '.' << last.column; | |
1089 | else if (loc.begin.column != last.column) | |
1090 | ostr << '-' << last.column; | |
7548fed2 AD |
1091 | return ostr; |
1092 | } | |
1093 | ||
2b548aa6 RA |
1094 | } |
1095 | ||
c5e3e510 | 1096 | #endif // not BISON_LOCATION_HH] |