1 #line 2 "exprscan.c"
2
3 #line 4 "exprscan.c"
4
5 #define YY_INT_ALIGNED short int
6
7 /* A lexical scanner generated by flex */
8
9 #define FLEX_SCANNER
10 #define YY_FLEX_MAJOR_VERSION 2
11 #define YY_FLEX_MINOR_VERSION 6
12 #define YY_FLEX_SUBMINOR_VERSION 4
13 #if YY_FLEX_SUBMINOR_VERSION > 0
14 #define FLEX_BETA
15 #endif
16
17 #ifdef yy_create_buffer
18 #define expr_yy_create_buffer_ALREADY_DEFINED
19 #else
20 #define yy_create_buffer expr_yy_create_buffer
21 #endif
22
23 #ifdef yy_delete_buffer
24 #define expr_yy_delete_buffer_ALREADY_DEFINED
25 #else
26 #define yy_delete_buffer expr_yy_delete_buffer
27 #endif
28
29 #ifdef yy_scan_buffer
30 #define expr_yy_scan_buffer_ALREADY_DEFINED
31 #else
32 #define yy_scan_buffer expr_yy_scan_buffer
33 #endif
34
35 #ifdef yy_scan_string
36 #define expr_yy_scan_string_ALREADY_DEFINED
37 #else
38 #define yy_scan_string expr_yy_scan_string
39 #endif
40
41 #ifdef yy_scan_bytes
42 #define expr_yy_scan_bytes_ALREADY_DEFINED
43 #else
44 #define yy_scan_bytes expr_yy_scan_bytes
45 #endif
46
47 #ifdef yy_init_buffer
48 #define expr_yy_init_buffer_ALREADY_DEFINED
49 #else
50 #define yy_init_buffer expr_yy_init_buffer
51 #endif
52
53 #ifdef yy_flush_buffer
54 #define expr_yy_flush_buffer_ALREADY_DEFINED
55 #else
56 #define yy_flush_buffer expr_yy_flush_buffer
57 #endif
58
59 #ifdef yy_load_buffer_state
60 #define expr_yy_load_buffer_state_ALREADY_DEFINED
61 #else
62 #define yy_load_buffer_state expr_yy_load_buffer_state
63 #endif
64
65 #ifdef yy_switch_to_buffer
66 #define expr_yy_switch_to_buffer_ALREADY_DEFINED
67 #else
68 #define yy_switch_to_buffer expr_yy_switch_to_buffer
69 #endif
70
71 #ifdef yypush_buffer_state
72 #define expr_yypush_buffer_state_ALREADY_DEFINED
73 #else
74 #define yypush_buffer_state expr_yypush_buffer_state
75 #endif
76
77 #ifdef yypop_buffer_state
78 #define expr_yypop_buffer_state_ALREADY_DEFINED
79 #else
80 #define yypop_buffer_state expr_yypop_buffer_state
81 #endif
82
83 #ifdef yyensure_buffer_stack
84 #define expr_yyensure_buffer_stack_ALREADY_DEFINED
85 #else
86 #define yyensure_buffer_stack expr_yyensure_buffer_stack
87 #endif
88
89 #ifdef yylex
90 #define expr_yylex_ALREADY_DEFINED
91 #else
92 #define yylex expr_yylex
93 #endif
94
95 #ifdef yyrestart
96 #define expr_yyrestart_ALREADY_DEFINED
97 #else
98 #define yyrestart expr_yyrestart
99 #endif
100
101 #ifdef yylex_init
102 #define expr_yylex_init_ALREADY_DEFINED
103 #else
104 #define yylex_init expr_yylex_init
105 #endif
106
107 #ifdef yylex_init_extra
108 #define expr_yylex_init_extra_ALREADY_DEFINED
109 #else
110 #define yylex_init_extra expr_yylex_init_extra
111 #endif
112
113 #ifdef yylex_destroy
114 #define expr_yylex_destroy_ALREADY_DEFINED
115 #else
116 #define yylex_destroy expr_yylex_destroy
117 #endif
118
119 #ifdef yyget_debug
120 #define expr_yyget_debug_ALREADY_DEFINED
121 #else
122 #define yyget_debug expr_yyget_debug
123 #endif
124
125 #ifdef yyset_debug
126 #define expr_yyset_debug_ALREADY_DEFINED
127 #else
128 #define yyset_debug expr_yyset_debug
129 #endif
130
131 #ifdef yyget_extra
132 #define expr_yyget_extra_ALREADY_DEFINED
133 #else
134 #define yyget_extra expr_yyget_extra
135 #endif
136
137 #ifdef yyset_extra
138 #define expr_yyset_extra_ALREADY_DEFINED
139 #else
140 #define yyset_extra expr_yyset_extra
141 #endif
142
143 #ifdef yyget_in
144 #define expr_yyget_in_ALREADY_DEFINED
145 #else
146 #define yyget_in expr_yyget_in
147 #endif
148
149 #ifdef yyset_in
150 #define expr_yyset_in_ALREADY_DEFINED
151 #else
152 #define yyset_in expr_yyset_in
153 #endif
154
155 #ifdef yyget_out
156 #define expr_yyget_out_ALREADY_DEFINED
157 #else
158 #define yyget_out expr_yyget_out
159 #endif
160
161 #ifdef yyset_out
162 #define expr_yyset_out_ALREADY_DEFINED
163 #else
164 #define yyset_out expr_yyset_out
165 #endif
166
167 #ifdef yyget_leng
168 #define expr_yyget_leng_ALREADY_DEFINED
169 #else
170 #define yyget_leng expr_yyget_leng
171 #endif
172
173 #ifdef yyget_text
174 #define expr_yyget_text_ALREADY_DEFINED
175 #else
176 #define yyget_text expr_yyget_text
177 #endif
178
179 #ifdef yyget_lineno
180 #define expr_yyget_lineno_ALREADY_DEFINED
181 #else
182 #define yyget_lineno expr_yyget_lineno
183 #endif
184
185 #ifdef yyset_lineno
186 #define expr_yyset_lineno_ALREADY_DEFINED
187 #else
188 #define yyset_lineno expr_yyset_lineno
189 #endif
190
191 #ifdef yyget_column
192 #define expr_yyget_column_ALREADY_DEFINED
193 #else
194 #define yyget_column expr_yyget_column
195 #endif
196
197 #ifdef yyset_column
198 #define expr_yyset_column_ALREADY_DEFINED
199 #else
200 #define yyset_column expr_yyset_column
201 #endif
202
203 #ifdef yywrap
204 #define expr_yywrap_ALREADY_DEFINED
205 #else
206 #define yywrap expr_yywrap
207 #endif
208
209 #ifdef yyget_lval
210 #define expr_yyget_lval_ALREADY_DEFINED
211 #else
212 #define yyget_lval expr_yyget_lval
213 #endif
214
215 #ifdef yyset_lval
216 #define expr_yyset_lval_ALREADY_DEFINED
217 #else
218 #define yyset_lval expr_yyset_lval
219 #endif
220
221 #ifdef yyalloc
222 #define expr_yyalloc_ALREADY_DEFINED
223 #else
224 #define yyalloc expr_yyalloc
225 #endif
226
227 #ifdef yyrealloc
228 #define expr_yyrealloc_ALREADY_DEFINED
229 #else
230 #define yyrealloc expr_yyrealloc
231 #endif
232
233 #ifdef yyfree
234 #define expr_yyfree_ALREADY_DEFINED
235 #else
236 #define yyfree expr_yyfree
237 #endif
238
239 /* First, we deal with platform-specific or compiler-specific issues. */
240
241 /* begin standard C headers. */
242 #include <stdio.h>
243 #include <string.h>
244 #include <errno.h>
245 #include <stdlib.h>
246
247 /* end standard C headers. */
248
249 /* flex integer type definitions */
250
251 #ifndef FLEXINT_H
252 #define FLEXINT_H
253
254 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
255
256 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
257
258 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
259 * if you want the limit (max/min) macros for int types.
260 */
261 #ifndef __STDC_LIMIT_MACROS
262 #define __STDC_LIMIT_MACROS 1
263 #endif
264
265 #include <inttypes.h>
266 typedef int8_t flex_int8_t;
267 typedef uint8_t flex_uint8_t;
268 typedef int16_t flex_int16_t;
269 typedef uint16_t flex_uint16_t;
270 typedef int32_t flex_int32_t;
271 typedef uint32_t flex_uint32_t;
272 #else
273 typedef signed char flex_int8_t;
274 typedef short int flex_int16_t;
275 typedef int flex_int32_t;
276 typedef unsigned char flex_uint8_t;
277 typedef unsigned short int flex_uint16_t;
278 typedef unsigned int flex_uint32_t;
279
280 /* Limits of integral types. */
281 #ifndef INT8_MIN
282 #define INT8_MIN (-128)
283 #endif
284 #ifndef INT16_MIN
285 #define INT16_MIN (-32767-1)
286 #endif
287 #ifndef INT32_MIN
288 #define INT32_MIN (-2147483647-1)
289 #endif
290 #ifndef INT8_MAX
291 #define INT8_MAX (127)
292 #endif
293 #ifndef INT16_MAX
294 #define INT16_MAX (32767)
295 #endif
296 #ifndef INT32_MAX
297 #define INT32_MAX (2147483647)
298 #endif
299 #ifndef UINT8_MAX
300 #define UINT8_MAX (255U)
301 #endif
302 #ifndef UINT16_MAX
303 #define UINT16_MAX (65535U)
304 #endif
305 #ifndef UINT32_MAX
306 #define UINT32_MAX (4294967295U)
307 #endif
308
309 #ifndef SIZE_MAX
310 #define SIZE_MAX (~(size_t)0)
311 #endif
312
313 #endif /* ! C99 */
314
315 #endif /* ! FLEXINT_H */
316
317 /* begin standard C++ headers. */
318
319 /* TODO: this is always defined, so inline it */
320 #define yyconst const
321
322 #if defined(__GNUC__) && __GNUC__ >= 3
323 #define yynoreturn __attribute__((__noreturn__))
324 #else
325 #define yynoreturn
326 #endif
327
328 /* Returned upon end-of-file. */
329 #define YY_NULL 0
330
331 /* Promotes a possibly negative, possibly signed char to an
332 * integer in range [0..255] for use as an array index.
333 */
334 #define YY_SC_TO_UI(c) ((YY_CHAR) (c))
335
336 /* An opaque pointer. */
337 #ifndef YY_TYPEDEF_YY_SCANNER_T
338 #define YY_TYPEDEF_YY_SCANNER_T
339 typedef void* yyscan_t;
340 #endif
341
342 /* For convenience, these vars (plus the bison vars far below)
343 are macros in the reentrant scanner. */
344 #define yyin yyg->yyin_r
345 #define yyout yyg->yyout_r
346 #define yyextra yyg->yyextra_r
347 #define yyleng yyg->yyleng_r
348 #define yytext yyg->yytext_r
349 #define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
350 #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
351 #define yy_flex_debug yyg->yy_flex_debug_r
352
353 /* Enter a start condition. This macro really ought to take a parameter,
354 * but we do it the disgusting crufty way forced on us by the ()-less
355 * definition of BEGIN.
356 */
357 #define BEGIN yyg->yy_start = 1 + 2 *
358 /* Translate the current start state into a value that can be later handed
359 * to BEGIN to return to the state. The YYSTATE alias is for lex
360 * compatibility.
361 */
362 #define YY_START ((yyg->yy_start - 1) / 2)
363 #define YYSTATE YY_START
364 /* Action number for EOF rule of a given start state. */
365 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
366 /* Special action meaning "start processing a new file". */
367 #define YY_NEW_FILE yyrestart( yyin , yyscanner )
368 #define YY_END_OF_BUFFER_CHAR 0
369
370 /* Size of default input buffer. */
371 #ifndef YY_BUF_SIZE
372 #ifdef __ia64__
373 /* On IA-64, the buffer size is 16k, not 8k.
374 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
375 * Ditto for the __ia64__ case accordingly.
376 */
377 #define YY_BUF_SIZE 32768
378 #else
379 #define YY_BUF_SIZE 16384
380 #endif /* __ia64__ */
381 #endif
382
383 /* The state buf must be large enough to hold one state per character in the main buffer.
384 */
385 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
386
387 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
388 #define YY_TYPEDEF_YY_BUFFER_STATE
389 typedef struct yy_buffer_state *YY_BUFFER_STATE;
390 #endif
391
392 #ifndef YY_TYPEDEF_YY_SIZE_T
393 #define YY_TYPEDEF_YY_SIZE_T
394 typedef size_t yy_size_t;
395 #endif
396
397 #define EOB_ACT_CONTINUE_SCAN 0
398 #define EOB_ACT_END_OF_FILE 1
399 #define EOB_ACT_LAST_MATCH 2
400
401 #define YY_LESS_LINENO(n)
402 #define YY_LINENO_REWIND_TO(ptr)
403
404 /* Return all but the first "n" matched characters back to the input stream. */
405 #define yyless(n) \
406 do \
407 { \
408 /* Undo effects of setting up yytext. */ \
409 int yyless_macro_arg = (n); \
410 YY_LESS_LINENO(yyless_macro_arg);\
411 *yy_cp = yyg->yy_hold_char; \
412 YY_RESTORE_YY_MORE_OFFSET \
413 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
414 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
415 } \
416 while ( 0 )
417 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
418
419 #ifndef YY_STRUCT_YY_BUFFER_STATE
420 #define YY_STRUCT_YY_BUFFER_STATE
421 struct yy_buffer_state
422 {
423 FILE *yy_input_file;
424
425 char *yy_ch_buf; /* input buffer */
426 char *yy_buf_pos; /* current position in input buffer */
427
428 /* Size of input buffer in bytes, not including room for EOB
429 * characters.
430 */
431 int yy_buf_size;
432
433 /* Number of characters read into yy_ch_buf, not including EOB
434 * characters.
435 */
436 int yy_n_chars;
437
438 /* Whether we "own" the buffer - i.e., we know we created it,
439 * and can realloc() it to grow it, and should free() it to
440 * delete it.
441 */
442 int yy_is_our_buffer;
443
444 /* Whether this is an "interactive" input source; if so, and
445 * if we're using stdio for input, then we want to use getc()
446 * instead of fread(), to make sure we stop fetching input after
447 * each newline.
448 */
449 int yy_is_interactive;
450
451 /* Whether we're considered to be at the beginning of a line.
452 * If so, '^' rules will be active on the next match, otherwise
453 * not.
454 */
455 int yy_at_bol;
456
457 int yy_bs_lineno; /**< The line count. */
458 int yy_bs_column; /**< The column count. */
459
460 /* Whether to try to fill the input buffer when we reach the
461 * end of it.
462 */
463 int yy_fill_buffer;
464
465 int yy_buffer_status;
466
467 #define YY_BUFFER_NEW 0
468 #define YY_BUFFER_NORMAL 1
469 /* When an EOF's been seen but there's still some text to process
470 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
471 * shouldn't try reading from the input source any more. We might
472 * still have a bunch of tokens to match, though, because of
473 * possible backing-up.
474 *
475 * When we actually see the EOF, we change the status to "new"
476 * (via yyrestart()), so that the user can continue scanning by
477 * just pointing yyin at a new input file.
478 */
479 #define YY_BUFFER_EOF_PENDING 2
480
481 };
482 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
483
484 /* We provide macros for accessing buffer states in case in the
485 * future we want to put the buffer states in a more general
486 * "scanner state".
487 *
488 * Returns the top of the stack, or NULL.
489 */
490 #define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
491 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
492 : NULL)
493 /* Same as previous macro, but useful when we know that the buffer stack is not
494 * NULL or when we need an lvalue. For internal use only.
495 */
496 #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
497
498 void yyrestart ( FILE *input_file , yyscan_t yyscanner );
499 void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
500 YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
501 void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
502 void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
503 void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
504 void yypop_buffer_state ( yyscan_t yyscanner );
505
506 static void yyensure_buffer_stack ( yyscan_t yyscanner );
507 static void yy_load_buffer_state ( yyscan_t yyscanner );
508 static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
509 #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner)
510
511 YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
512 YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
513 YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
514
515 void *yyalloc ( yy_size_t , yyscan_t yyscanner );
516 void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
517 void yyfree ( void * , yyscan_t yyscanner );
518
519 #define yy_new_buffer yy_create_buffer
520 #define yy_set_interactive(is_interactive) \
521 { \
522 if ( ! YY_CURRENT_BUFFER ){ \
523 yyensure_buffer_stack (yyscanner); \
524 YY_CURRENT_BUFFER_LVALUE = \
525 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
526 } \
527 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
528 }
529 #define yy_set_bol(at_bol) \
530 { \
531 if ( ! YY_CURRENT_BUFFER ){\
532 yyensure_buffer_stack (yyscanner); \
533 YY_CURRENT_BUFFER_LVALUE = \
534 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
535 } \
536 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
537 }
538 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
539
540 /* Begin user sect3 */
541
542 #define expr_yywrap(yyscanner) (/*CONSTCOND*/1)
543 #define YY_SKIP_YYWRAP
544 typedef flex_uint8_t YY_CHAR;
545
546 typedef int yy_state_type;
547
548 #define yytext_ptr yytext_r
549
550 static yy_state_type yy_get_previous_state ( yyscan_t yyscanner );
551 static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner);
552 static int yy_get_next_buffer ( yyscan_t yyscanner );
553 static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
554
555 /* Done after the current pattern has been matched and before the
556 * corresponding action - sets up yytext.
557 */
558 #define YY_DO_BEFORE_ACTION \
559 yyg->yytext_ptr = yy_bp; \
560 yyleng = (int) (yy_cp - yy_bp); \
561 yyg->yy_hold_char = *yy_cp; \
562 *yy_cp = '\0'; \
563 yyg->yy_c_buf_p = yy_cp;
564 #define YY_NUM_RULES 23
565 #define YY_END_OF_BUFFER 24
566 /* This struct is not used in this scanner,
567 but its presence is necessary. */
568 struct yy_trans_info
569 {
570 flex_int32_t yy_verify;
571 flex_int32_t yy_nxt;
572 };
573 static const flex_int16_t yy_accept[49] =
574 { 0,
575 0, 0, 0, 0, 24, 1, 3, 5, 1, 22,
576 19, 21, 10, 11, 12, 8, 6, 13, 7, 22,
577 9, 15, 22, 18, 22, 1, 1, 3, 4, 0,
578 19, 17, 16, 15, 0, 14, 18, 20, 0, 2,
579 0, 0, 16, 0, 16, 0, 17, 0
580 } ;
581
582 static const YY_CHAR yy_ec[256] =
583 { 0,
584 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
585 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
586 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
587 1, 2, 1, 1, 1, 1, 5, 1, 1, 6,
588 7, 8, 9, 10, 11, 12, 13, 14, 14, 14,
589 14, 14, 14, 14, 14, 14, 14, 15, 1, 1,
590 1, 1, 1, 1, 16, 16, 16, 16, 17, 16,
591 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
592 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
593 1, 18, 1, 1, 16, 1, 16, 16, 16, 16,
594
595 17, 16, 16, 16, 16, 16, 16, 16, 16, 16,
596 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
597 16, 16, 1, 1, 1, 1, 1, 1, 1, 1,
598 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
599 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
600 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
601 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
602 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
603 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
604 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
605
606 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
607 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
608 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
609 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
610 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
611 1, 1, 1, 1, 1
612 } ;
613
614 static const YY_CHAR yy_meta[19] =
615 { 0,
616 1, 2, 2, 2, 1, 1, 1, 1, 3, 1,
617 3, 1, 1, 4, 1, 5, 5, 1
618 } ;
619
620 static const flex_int16_t yy_base[55] =
621 { 0,
622 0, 17, 35, 0, 58, 39, 3, 110, 51, 110,
623 4, 110, 110, 110, 110, 110, 110, 110, 110, 42,
624 110, 58, 0, 0, 6, 16, 73, 9, 110, 30,
625 10, 8, 9, 0, 18, 0, 0, 110, 28, 110,
626 27, 15, 10, 14, 3, 2, 1, 110, 91, 96,
627 98, 100, 103, 105
628 } ;
629
630 static const flex_int16_t yy_def[55] =
631 { 0,
632 49, 49, 48, 3, 48, 50, 48, 48, 50, 48,
633 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
634 48, 48, 51, 52, 48, 50, 50, 48, 48, 48,
635 48, 48, 48, 22, 53, 51, 52, 48, 48, 48,
636 48, 54, 48, 48, 48, 48, 48, 0, 48, 48,
637 48, 48, 48, 48
638 } ;
639
640 static const flex_int16_t yy_nxt[129] =
641 { 0,
642 48, 7, 8, 7, 28, 31, 28, 31, 38, 39,
643 28, 31, 28, 31, 47, 47, 45, 9, 7, 8,
644 7, 32, 43, 43, 42, 35, 35, 45, 47, 40,
645 38, 45, 29, 27, 9, 10, 11, 12, 11, 13,
646 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
647 24, 24, 25, 29, 30, 32, 27, 48, 48, 48,
648 48, 48, 48, 48, 48, 48, 48, 48, 27, 33,
649 48, 34, 48, 48, 35, 40, 41, 48, 48, 48,
650 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
651 27, 6, 6, 6, 6, 6, 26, 48, 26, 26,
652
653 26, 36, 36, 37, 37, 44, 44, 46, 46, 5,
654 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
655 48, 48, 48, 48, 48, 48, 48, 48
656 } ;
657
658 static const flex_int16_t yy_chk[129] =
659 { 0,
660 0, 1, 1, 1, 7, 11, 7, 11, 25, 25,
661 28, 31, 28, 31, 47, 46, 45, 1, 2, 2,
662 2, 32, 33, 43, 32, 33, 43, 44, 42, 41,
663 39, 35, 30, 26, 2, 3, 3, 3, 3, 3,
664 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
665 3, 3, 3, 9, 9, 20, 6, 5, 0, 0,
666 0, 0, 0, 0, 0, 0, 0, 0, 9, 22,
667 0, 22, 0, 0, 22, 27, 27, 0, 0, 0,
668 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
669 27, 49, 49, 49, 49, 49, 50, 0, 50, 50,
670
671 50, 51, 51, 52, 52, 53, 53, 54, 54, 48,
672 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
673 48, 48, 48, 48, 48, 48, 48, 48
674 } ;
675
676 /* The intent behind this definition is that it'll catch
677 * any uses of REJECT which flex missed.
678 */
679 #define REJECT reject_used_but_not_detected
680 #define yymore() yymore_used_but_not_detected
681 #define YY_MORE_ADJ 0
682 #define YY_RESTORE_YY_MORE_OFFSET
683 #line 1 "exprscan.l"
684 #line 2 "exprscan.l"
685 /*-------------------------------------------------------------------------
686 *
687 * exprscan.l
688 * lexical scanner for pgbench backslash commands
689 *
690 * This lexer supports two operating modes:
691 *
692 * In INITIAL state, just parse off whitespace-separated words (this mode
693 * is basically equivalent to strtok(), which is what we used to use).
694 *
695 * In EXPR state, lex for the simple expression syntax of exprparse.y.
696 *
697 * In either mode, stop upon hitting newline or end of string.
698 *
699 * Note that this lexer operates within the framework created by psqlscan.l,
700 *
701 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
702 * Portions Copyright (c) 1994, Regents of the University of California
703 *
704 * src/bin/pgbench/exprscan.l
705 *
706 *-------------------------------------------------------------------------
707 */
708
709 #include "fe_utils/psqlscan_int.h"
710
711 /* context information for reporting errors in expressions */
712 static const char *expr_source = NULL;
713 static int expr_lineno = 0;
714 static int expr_start_offset = 0;
715 static const char *expr_command = NULL;
716
717 /* indicates whether last yylex() call read a newline */
718 static bool last_was_newline = false;
719
720 /*
721 * Work around a bug in flex 2.5.35: it emits a couple of functions that
722 * it forgets to emit declarations for. Since we use -Wmissing-prototypes,
723 * this would cause warnings. Providing our own declarations should be
724 * harmless even when the bug gets fixed.
725 */
726 extern int expr_yyget_column(yyscan_t yyscanner);
727 extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
728
729 #line 730 "exprscan.c"
730 /* Except for the prefix, these options should match psqlscan.l */
731 #define YY_NO_INPUT 1
732 /* Character classes */
733 /* {space} + {nonspace} + {newline} should cover all characters */
734 /* Line continuation marker */
735 /* Exclusive states */
736
737 #line 738 "exprscan.c"
738
739 #define INITIAL 0
740 #define EXPR 1
741
742 #ifndef YY_NO_UNISTD_H
743 /* Special case for "unistd.h", since it is non-ANSI. We include it way
744 * down here because we want the user's section 1 to have been scanned first.
745 * The user has a chance to override it with an option.
746 */
747 #include <unistd.h>
748 #endif
749
750 #ifndef YY_EXTRA_TYPE
751 #define YY_EXTRA_TYPE void *
752 #endif
753
754 /* Holds the entire state of the reentrant scanner. */
755 struct yyguts_t
756 {
757
758 /* User-defined. Not touched by flex. */
759 YY_EXTRA_TYPE yyextra_r;
760
761 /* The rest are the same as the globals declared in the non-reentrant scanner. */
762 FILE *yyin_r, *yyout_r;
763 size_t yy_buffer_stack_top; /**< index of top of stack. */
764 size_t yy_buffer_stack_max; /**< capacity of stack. */
765 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
766 char yy_hold_char;
767 int yy_n_chars;
768 int yyleng_r;
769 char *yy_c_buf_p;
770 int yy_init;
771 int yy_start;
772 int yy_did_buffer_switch_on_eof;
773 int yy_start_stack_ptr;
774 int yy_start_stack_depth;
775 int *yy_start_stack;
776 yy_state_type yy_last_accepting_state;
777 char* yy_last_accepting_cpos;
778
779 int yylineno_r;
780 int yy_flex_debug_r;
781
782 char *yytext_r;
783 int yy_more_flag;
784 int yy_more_len;
785
786 YYSTYPE * yylval_r;
787
788 }; /* end struct yyguts_t */
789
790 static int yy_init_globals ( yyscan_t yyscanner );
791
792 /* This must go here because YYSTYPE and YYLTYPE are included
793 * from bison output in section 1.*/
794 # define yylval yyg->yylval_r
795
796 int yylex_init (yyscan_t* scanner);
797
798 int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
799
800 /* Accessor methods to globals.
801 These are made visible to non-reentrant scanners for convenience. */
802
803 int yylex_destroy ( yyscan_t yyscanner );
804
805 int yyget_debug ( yyscan_t yyscanner );
806
807 void yyset_debug ( int debug_flag , yyscan_t yyscanner );
808
809 YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
810
811 void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
812
813 FILE *yyget_in ( yyscan_t yyscanner );
814
815 void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
816
817 FILE *yyget_out ( yyscan_t yyscanner );
818
819 void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
820
821 int yyget_leng ( yyscan_t yyscanner );
822
823 char *yyget_text ( yyscan_t yyscanner );
824
825 int yyget_lineno ( yyscan_t yyscanner );
826
827 void yyset_lineno ( int _line_number , yyscan_t yyscanner );
828
829 int yyget_column ( yyscan_t yyscanner );
830
831 void yyset_column ( int _column_no , yyscan_t yyscanner );
832
833 YYSTYPE * yyget_lval ( yyscan_t yyscanner );
834
835 void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner );
836
837 /* Macros after this point can all be overridden by user definitions in
838 * section 1.
839 */
840
841 #ifndef YY_SKIP_YYWRAP
842 #ifdef __cplusplus
843 extern "C" int yywrap ( yyscan_t yyscanner );
844 #else
845 extern int yywrap ( yyscan_t yyscanner );
846 #endif
847 #endif
848
849 #ifndef YY_NO_UNPUT
850
851 #endif
852
853 #ifndef yytext_ptr
854 static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
855 #endif
856
857 #ifdef YY_NEED_STRLEN
858 static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
859 #endif
860
861 #ifndef YY_NO_INPUT
862 #ifdef __cplusplus
863 static int yyinput ( yyscan_t yyscanner );
864 #else
865 static int input ( yyscan_t yyscanner );
866 #endif
867
868 #endif
869
870 /* Amount of stuff to slurp up with each read. */
871 #ifndef YY_READ_BUF_SIZE
872 #ifdef __ia64__
873 /* On IA-64, the buffer size is 16k, not 8k */
874 #define YY_READ_BUF_SIZE 16384
875 #else
876 #define YY_READ_BUF_SIZE 8192
877 #endif /* __ia64__ */
878 #endif
879
880 /* Copy whatever the last rule matched to the standard output. */
881 #ifndef ECHO
882 /* This used to be an fputs(), but since the string might contain NUL's,
883 * we now use fwrite().
884 */
885 #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
886 #endif
887
888 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
889 * is returned in "result".
890 */
891 #ifndef YY_INPUT
892 #define YY_INPUT(buf,result,max_size) \
893 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
894 { \
895 int c = '*'; \
896 int n; \
897 for ( n = 0; n < max_size && \
898 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
899 buf[n] = (char) c; \
900 if ( c == '\n' ) \
901 buf[n++] = (char) c; \
902 if ( c == EOF && ferror( yyin ) ) \
903 YY_FATAL_ERROR( "input in flex scanner failed" ); \
904 result = n; \
905 } \
906 else \
907 { \
908 errno=0; \
909 while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
910 { \
911 if( errno != EINTR) \
912 { \
913 YY_FATAL_ERROR( "input in flex scanner failed" ); \
914 break; \
915 } \
916 errno=0; \
917 clearerr(yyin); \
918 } \
919 }\
920 \
921
922 #endif
923
924 /* No semi-colon after return; correct usage is to write "yyterminate();" -
925 * we don't want an extra ';' after the "return" because that will cause
926 * some compilers to complain about unreachable statements.
927 */
928 #ifndef yyterminate
929 #define yyterminate() return YY_NULL
930 #endif
931
932 /* Number of entries by which start-condition stack grows. */
933 #ifndef YY_START_STACK_INCR
934 #define YY_START_STACK_INCR 25
935 #endif
936
937 /* Report a fatal error. */
938 #ifndef YY_FATAL_ERROR
939 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
940 #endif
941
942 /* end tables serialization structures and prototypes */
943
944 /* Default declaration of generated scanner - a define so the user can
945 * easily add parameters.
946 */
947 #ifndef YY_DECL
948 #define YY_DECL_IS_OURS 1
949
950 extern int yylex \
951 (YYSTYPE * yylval_param , yyscan_t yyscanner);
952
953 #define YY_DECL int yylex \
954 (YYSTYPE * yylval_param , yyscan_t yyscanner)
955 #endif /* !YY_DECL */
956
957 /* Code executed at the beginning of each rule, after yytext and yyleng
958 * have been set up.
959 */
960 #ifndef YY_USER_ACTION
961 #define YY_USER_ACTION
962 #endif
963
964 /* Code executed at the end of each rule. */
965 #ifndef YY_BREAK
966 #define YY_BREAK /*LINTED*/break;
967 #endif
968
969 #define YY_RULE_SETUP \
970 YY_USER_ACTION
971
972 /** The main scanner function which does all the work.
973 */
974 YY_DECL
975 {
976 yy_state_type yy_current_state;
977 char *yy_cp, *yy_bp;
978 int yy_act;
979 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
980
981 yylval = yylval_param;
982
983 if ( !yyg->yy_init )
984 {
985 yyg->yy_init = 1;
986
987 #ifdef YY_USER_INIT
988 YY_USER_INIT;
989 #endif
990
991 if ( ! yyg->yy_start )
992 yyg->yy_start = 1; /* first start state */
993
994 if ( ! yyin )
995 yyin = stdin;
996
997 if ( ! yyout )
998 yyout = stdout;
999
1000 if ( ! YY_CURRENT_BUFFER ) {
1001 yyensure_buffer_stack (yyscanner);
1002 YY_CURRENT_BUFFER_LVALUE =
1003 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1004 }
1005
1006 yy_load_buffer_state( yyscanner );
1007 }
1008
1009 {
1010 #line 75 "exprscan.l"
1011
1012
1013
1014 #line 79 "exprscan.l"
1015 /* Declare some local variables inside yylex(), for convenience */
1016 PsqlScanState cur_state = yyextra;
1017
1018 /*
1019 * Force flex into the state indicated by start_state. This has a
1020 * couple of purposes: it lets some of the functions below set a new
1021 * starting state without ugly direct access to flex variables, and it
1022 * allows us to transition from one flex lexer to another so that we
1023 * can lex different parts of the source string using separate lexers.
1024 */
1025 BEGIN(cur_state->start_state);
1026
1027 /* Reset was-newline flag */
1028 last_was_newline = false;
1029
1030
1031 /* INITIAL state */
1032
1033 #line 1034 "exprscan.c"
1034
1035 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
1036 {
1037 yy_cp = yyg->yy_c_buf_p;
1038
1039 /* Support of yytext. */
1040 *yy_cp = yyg->yy_hold_char;
1041
1042 /* yy_bp points to the position in yy_ch_buf of the start of
1043 * the current run.
1044 */
1045 yy_bp = yy_cp;
1046
1047 yy_current_state = yyg->yy_start;
1048 yy_match:
1049 do
1050 {
1051 YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1052 if ( yy_accept[yy_current_state] )
1053 {
1054 yyg->yy_last_accepting_state = yy_current_state;
1055 yyg->yy_last_accepting_cpos = yy_cp;
1056 }
1057 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1058 {
1059 yy_current_state = (int) yy_def[yy_current_state];
1060 if ( yy_current_state >= 49 )
1061 yy_c = yy_meta[yy_c];
1062 }
1063 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1064 ++yy_cp;
1065 }
1066 while ( yy_current_state != 48 );
1067 yy_cp = yyg->yy_last_accepting_cpos;
1068 yy_current_state = yyg->yy_last_accepting_state;
1069
1070 yy_find_action:
1071 yy_act = yy_accept[yy_current_state];
1072
1073 YY_DO_BEFORE_ACTION;
1074
1075 do_action: /* This label is used only to access EOF actions. */
1076
1077 switch ( yy_act )
1078 { /* beginning of action switch */
1079 case 0: /* must back up */
1080 /* undo the effects of YY_DO_BEFORE_ACTION */
1081 *yy_cp = yyg->yy_hold_char;
1082 yy_cp = yyg->yy_last_accepting_cpos;
1083 yy_current_state = yyg->yy_last_accepting_state;
1084 goto yy_find_action;
1085
1086 case 1:
1087 YY_RULE_SETUP
1088 #line 97 "exprscan.l"
1089 {
1090 /* Found a word, emit and return it */
1091 psqlscan_emit(cur_state, yytext, yyleng);
1092 return 1;
1093 }
1094 YY_BREAK
1095 /*
1096 * We need this rule to avoid returning "word\" instead of recognizing
1097 * a continuation marker just after a word:
1098 */
1099 case 2:
1100 /* rule 2 can match eol */
1101 YY_RULE_SETUP
1102 #line 107 "exprscan.l"
1103 {
1104 /* Found "word\\\r?\n", emit and return just "word" */
1105 int wordlen = yyleng - 2;
1106 if (yytext[wordlen] == '\r')
1107 wordlen--;
1108 Assert(yytext[wordlen] == '\\');
1109 psqlscan_emit(cur_state, yytext, wordlen);
1110 return 1;
1111 }
1112 YY_BREAK
1113 case 3:
1114 YY_RULE_SETUP
1115 #line 117 "exprscan.l"
1116 { /* ignore */ }
1117 YY_BREAK
1118 case 4:
1119 /* rule 4 can match eol */
1120 YY_RULE_SETUP
1121 #line 119 "exprscan.l"
1122 { /* ignore */ }
1123 YY_BREAK
1124 case 5:
1125 /* rule 5 can match eol */
1126 YY_RULE_SETUP
1127 #line 121 "exprscan.l"
1128 {
1129 /* report end of command */
1130 last_was_newline = true;
1131 return 0;
1132 }
1133 YY_BREAK
1134 /* EXPR state */
1135
1136 case 6:
1137 YY_RULE_SETUP
1138 #line 131 "exprscan.l"
1139 { return '+'; }
1140 YY_BREAK
1141 case 7:
1142 YY_RULE_SETUP
1143 #line 132 "exprscan.l"
1144 { return '-'; }
1145 YY_BREAK
1146 case 8:
1147 YY_RULE_SETUP
1148 #line 133 "exprscan.l"
1149 { return '*'; }
1150 YY_BREAK
1151 case 9:
1152 YY_RULE_SETUP
1153 #line 134 "exprscan.l"
1154 { return '/'; }
1155 YY_BREAK
1156 case 10:
1157 YY_RULE_SETUP
1158 #line 135 "exprscan.l"
1159 { return '%'; }
1160 YY_BREAK
1161 case 11:
1162 YY_RULE_SETUP
1163 #line 136 "exprscan.l"
1164 { return '('; }
1165 YY_BREAK
1166 case 12:
1167 YY_RULE_SETUP
1168 #line 137 "exprscan.l"
1169 { return ')'; }
1170 YY_BREAK
1171 case 13:
1172 YY_RULE_SETUP
1173 #line 138 "exprscan.l"
1174 { return ','; }
1175 YY_BREAK
1176 case 14:
1177 YY_RULE_SETUP
1178 #line 140 "exprscan.l"
1179 {
1180 yylval->str = pg_strdup(yytext + 1);
1181 return VARIABLE;
1182 }
1183 YY_BREAK
1184 case 15:
1185 YY_RULE_SETUP
1186 #line 144 "exprscan.l"
1187 {
1188 yylval->ival = strtoint64(yytext);
1189 return INTEGER_CONST;
1190 }
1191 YY_BREAK
1192 case 16:
1193 YY_RULE_SETUP
1194 #line 148 "exprscan.l"
1195 {
1196 yylval->dval = atof(yytext);
1197 return DOUBLE_CONST;
1198 }
1199 YY_BREAK
1200 case 17:
1201 YY_RULE_SETUP
1202 #line 152 "exprscan.l"
1203 {
1204 yylval->dval = atof(yytext);
1205 return DOUBLE_CONST;
1206 }
1207 YY_BREAK
1208 case 18:
1209 YY_RULE_SETUP
1210 #line 156 "exprscan.l"
1211 {
1212 yylval->str = pg_strdup(yytext);
1213 return FUNCTION;
1214 }
1215 YY_BREAK
1216 case 19:
1217 YY_RULE_SETUP
1218 #line 161 "exprscan.l"
1219 { /* ignore */ }
1220 YY_BREAK
1221 case 20:
1222 /* rule 20 can match eol */
1223 YY_RULE_SETUP
1224 #line 163 "exprscan.l"
1225 { /* ignore */ }
1226 YY_BREAK
1227 case 21:
1228 /* rule 21 can match eol */
1229 YY_RULE_SETUP
1230 #line 165 "exprscan.l"
1231 {
1232 /* report end of command */
1233 last_was_newline = true;
1234 return 0;
1235 }
1236 YY_BREAK
1237 case 22:
1238 YY_RULE_SETUP
1239 #line 171 "exprscan.l"
1240 {
1241 /*
1242 * must strdup yytext so that expr_yyerror_more doesn't
1243 * change it while finding end of line
1244 */
1245 expr_yyerror_more(yyscanner, "unexpected character",
1246 pg_strdup(yytext));
1247 /* NOTREACHED, syntax_error calls exit() */
1248 return 0;
1249 }
1250 YY_BREAK
1251
1252 case YY_STATE_EOF(INITIAL):
1253 case YY_STATE_EOF(EXPR):
1254 #line 184 "exprscan.l"
1255 {
1256 if (cur_state->buffer_stack == NULL)
1257 return 0; /* end of input reached */
1258
1259 /*
1260 * We were expanding a variable, so pop the inclusion
1261 * stack and keep lexing
1262 */
1263 psqlscan_pop_buffer_stack(cur_state);
1264 psqlscan_select_top_buffer(cur_state);
1265 }
1266 YY_BREAK
1267 case 23:
1268 YY_RULE_SETUP
1269 #line 196 "exprscan.l"
1270 YY_FATAL_ERROR( "flex scanner jammed" );
1271 YY_BREAK
1272 #line 1273 "exprscan.c"
1273
1274 case YY_END_OF_BUFFER:
1275 {
1276 /* Amount of text matched not including the EOB char. */
1277 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1278
1279 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1280 *yy_cp = yyg->yy_hold_char;
1281 YY_RESTORE_YY_MORE_OFFSET
1282
1283 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1284 {
1285 /* We're scanning a new file or input source. It's
1286 * possible that this happened because the user
1287 * just pointed yyin at a new source and called
1288 * yylex(). If so, then we have to assure
1289 * consistency between YY_CURRENT_BUFFER and our
1290 * globals. Here is the right place to do so, because
1291 * this is the first action (other than possibly a
1292 * back-up) that will match for the new input source.
1293 */
1294 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1295 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1296 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1297 }
1298
1299 /* Note that here we test for yy_c_buf_p "<=" to the position
1300 * of the first EOB in the buffer, since yy_c_buf_p will
1301 * already have been incremented past the NUL character
1302 * (since all states make transitions on EOB to the
1303 * end-of-buffer state). Contrast this with the test
1304 * in input().
1305 */
1306 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1307 { /* This was really a NUL. */
1308 yy_state_type yy_next_state;
1309
1310 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1311
1312 yy_current_state = yy_get_previous_state( yyscanner );
1313
1314 /* Okay, we're now positioned to make the NUL
1315 * transition. We couldn't have
1316 * yy_get_previous_state() go ahead and do it
1317 * for us because it doesn't know how to deal
1318 * with the possibility of jamming (and we don't
1319 * want to build jamming into it because then it
1320 * will run more slowly).
1321 */
1322
1323 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1324
1325 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1326
1327 if ( yy_next_state )
1328 {
1329 /* Consume the NUL. */
1330 yy_cp = ++yyg->yy_c_buf_p;
1331 yy_current_state = yy_next_state;
1332 goto yy_match;
1333 }
1334
1335 else
1336 {
1337 yy_cp = yyg->yy_last_accepting_cpos;
1338 yy_current_state = yyg->yy_last_accepting_state;
1339 goto yy_find_action;
1340 }
1341 }
1342
1343 else switch ( yy_get_next_buffer( yyscanner ) )
1344 {
1345 case EOB_ACT_END_OF_FILE:
1346 {
1347 yyg->yy_did_buffer_switch_on_eof = 0;
1348
1349 if ( yywrap( yyscanner ) )
1350 {
1351 /* Note: because we've taken care in
1352 * yy_get_next_buffer() to have set up
1353 * yytext, we can now set up
1354 * yy_c_buf_p so that if some total
1355 * hoser (like flex itself) wants to
1356 * call the scanner after we return the
1357 * YY_NULL, it'll still work - another
1358 * YY_NULL will get returned.
1359 */
1360 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1361
1362 yy_act = YY_STATE_EOF(YY_START);
1363 goto do_action;
1364 }
1365
1366 else
1367 {
1368 if ( ! yyg->yy_did_buffer_switch_on_eof )
1369 YY_NEW_FILE;
1370 }
1371 break;
1372 }
1373
1374 case EOB_ACT_CONTINUE_SCAN:
1375 yyg->yy_c_buf_p =
1376 yyg->yytext_ptr + yy_amount_of_matched_text;
1377
1378 yy_current_state = yy_get_previous_state( yyscanner );
1379
1380 yy_cp = yyg->yy_c_buf_p;
1381 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1382 goto yy_match;
1383
1384 case EOB_ACT_LAST_MATCH:
1385 yyg->yy_c_buf_p =
1386 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1387
1388 yy_current_state = yy_get_previous_state( yyscanner );
1389
1390 yy_cp = yyg->yy_c_buf_p;
1391 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1392 goto yy_find_action;
1393 }
1394 break;
1395 }
1396
1397 default:
1398 YY_FATAL_ERROR(
1399 "fatal flex scanner internal error--no action found" );
1400 } /* end of action switch */
1401 } /* end of scanning one token */
1402 } /* end of user's declarations */
1403 } /* end of yylex */
1404
1405 /* yy_get_next_buffer - try to read in a new buffer
1406 *
1407 * Returns a code representing an action:
1408 * EOB_ACT_LAST_MATCH -
1409 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1410 * EOB_ACT_END_OF_FILE - end of file
1411 */
yy_get_next_buffer(yyscan_t yyscanner)1412 static int yy_get_next_buffer (yyscan_t yyscanner)
1413 {
1414 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1415 char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1416 char *source = yyg->yytext_ptr;
1417 int number_to_move, i;
1418 int ret_val;
1419
1420 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1421 YY_FATAL_ERROR(
1422 "fatal flex scanner internal error--end of buffer missed" );
1423
1424 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1425 { /* Don't try to fill the buffer, so this is an EOF. */
1426 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1427 {
1428 /* We matched a single character, the EOB, so
1429 * treat this as a final EOF.
1430 */
1431 return EOB_ACT_END_OF_FILE;
1432 }
1433
1434 else
1435 {
1436 /* We matched some text prior to the EOB, first
1437 * process it.
1438 */
1439 return EOB_ACT_LAST_MATCH;
1440 }
1441 }
1442
1443 /* Try to read more data. */
1444
1445 /* First move last chars to start of buffer. */
1446 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
1447
1448 for ( i = 0; i < number_to_move; ++i )
1449 *(dest++) = *(source++);
1450
1451 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1452 /* don't do the read, it's not guaranteed to return an EOF,
1453 * just force an EOF
1454 */
1455 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1456
1457 else
1458 {
1459 int num_to_read =
1460 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1461
1462 while ( num_to_read <= 0 )
1463 { /* Not enough room in the buffer - grow it. */
1464
1465 /* just a shorter name for the current buffer */
1466 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1467
1468 int yy_c_buf_p_offset =
1469 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1470
1471 if ( b->yy_is_our_buffer )
1472 {
1473 int new_size = b->yy_buf_size * 2;
1474
1475 if ( new_size <= 0 )
1476 b->yy_buf_size += b->yy_buf_size / 8;
1477 else
1478 b->yy_buf_size *= 2;
1479
1480 b->yy_ch_buf = (char *)
1481 /* Include room in for 2 EOB chars. */
1482 yyrealloc( (void *) b->yy_ch_buf,
1483 (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1484 }
1485 else
1486 /* Can't grow it, we don't own it. */
1487 b->yy_ch_buf = NULL;
1488
1489 if ( ! b->yy_ch_buf )
1490 YY_FATAL_ERROR(
1491 "fatal error - scanner input buffer overflow" );
1492
1493 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1494
1495 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1496 number_to_move - 1;
1497
1498 }
1499
1500 if ( num_to_read > YY_READ_BUF_SIZE )
1501 num_to_read = YY_READ_BUF_SIZE;
1502
1503 /* Read in more data. */
1504 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1505 yyg->yy_n_chars, num_to_read );
1506
1507 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1508 }
1509
1510 if ( yyg->yy_n_chars == 0 )
1511 {
1512 if ( number_to_move == YY_MORE_ADJ )
1513 {
1514 ret_val = EOB_ACT_END_OF_FILE;
1515 yyrestart( yyin , yyscanner);
1516 }
1517
1518 else
1519 {
1520 ret_val = EOB_ACT_LAST_MATCH;
1521 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1522 YY_BUFFER_EOF_PENDING;
1523 }
1524 }
1525
1526 else
1527 ret_val = EOB_ACT_CONTINUE_SCAN;
1528
1529 if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1530 /* Extend the array by 50%, plus the number we really need. */
1531 int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1532 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1533 (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
1534 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1535 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1536 /* "- 2" to take care of EOB's */
1537 YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1538 }
1539
1540 yyg->yy_n_chars += number_to_move;
1541 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1542 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1543
1544 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1545
1546 return ret_val;
1547 }
1548
1549 /* yy_get_previous_state - get the state just before the EOB char was reached */
1550
yy_get_previous_state(yyscan_t yyscanner)1551 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1552 {
1553 yy_state_type yy_current_state;
1554 char *yy_cp;
1555 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1556
1557 yy_current_state = yyg->yy_start;
1558
1559 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1560 {
1561 YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1562 if ( yy_accept[yy_current_state] )
1563 {
1564 yyg->yy_last_accepting_state = yy_current_state;
1565 yyg->yy_last_accepting_cpos = yy_cp;
1566 }
1567 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1568 {
1569 yy_current_state = (int) yy_def[yy_current_state];
1570 if ( yy_current_state >= 49 )
1571 yy_c = yy_meta[yy_c];
1572 }
1573 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1574 }
1575
1576 return yy_current_state;
1577 }
1578
1579 /* yy_try_NUL_trans - try to make a transition on the NUL character
1580 *
1581 * synopsis
1582 * next_state = yy_try_NUL_trans( current_state );
1583 */
yy_try_NUL_trans(yy_state_type yy_current_state,yyscan_t yyscanner)1584 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
1585 {
1586 int yy_is_jam;
1587 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1588 char *yy_cp = yyg->yy_c_buf_p;
1589
1590 YY_CHAR yy_c = 1;
1591 if ( yy_accept[yy_current_state] )
1592 {
1593 yyg->yy_last_accepting_state = yy_current_state;
1594 yyg->yy_last_accepting_cpos = yy_cp;
1595 }
1596 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1597 {
1598 yy_current_state = (int) yy_def[yy_current_state];
1599 if ( yy_current_state >= 49 )
1600 yy_c = yy_meta[yy_c];
1601 }
1602 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1603 yy_is_jam = (yy_current_state == 48);
1604
1605 (void)yyg;
1606 return yy_is_jam ? 0 : yy_current_state;
1607 }
1608
1609 #ifndef YY_NO_UNPUT
1610
1611 #endif
1612
1613 #ifndef YY_NO_INPUT
1614 #ifdef __cplusplus
yyinput(yyscan_t yyscanner)1615 static int yyinput (yyscan_t yyscanner)
1616 #else
1617 static int input (yyscan_t yyscanner)
1618 #endif
1619
1620 {
1621 int c;
1622 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1623
1624 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1625
1626 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1627 {
1628 /* yy_c_buf_p now points to the character we want to return.
1629 * If this occurs *before* the EOB characters, then it's a
1630 * valid NUL; if not, then we've hit the end of the buffer.
1631 */
1632 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1633 /* This was really a NUL. */
1634 *yyg->yy_c_buf_p = '\0';
1635
1636 else
1637 { /* need more input */
1638 int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
1639 ++yyg->yy_c_buf_p;
1640
1641 switch ( yy_get_next_buffer( yyscanner ) )
1642 {
1643 case EOB_ACT_LAST_MATCH:
1644 /* This happens because yy_g_n_b()
1645 * sees that we've accumulated a
1646 * token and flags that we need to
1647 * try matching the token before
1648 * proceeding. But for input(),
1649 * there's no matching to consider.
1650 * So convert the EOB_ACT_LAST_MATCH
1651 * to EOB_ACT_END_OF_FILE.
1652 */
1653
1654 /* Reset buffer status. */
1655 yyrestart( yyin , yyscanner);
1656
1657 /*FALLTHROUGH*/
1658
1659 case EOB_ACT_END_OF_FILE:
1660 {
1661 if ( yywrap( yyscanner ) )
1662 return 0;
1663
1664 if ( ! yyg->yy_did_buffer_switch_on_eof )
1665 YY_NEW_FILE;
1666 #ifdef __cplusplus
1667 return yyinput(yyscanner);
1668 #else
1669 return input(yyscanner);
1670 #endif
1671 }
1672
1673 case EOB_ACT_CONTINUE_SCAN:
1674 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1675 break;
1676 }
1677 }
1678 }
1679
1680 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
1681 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
1682 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
1683
1684 return c;
1685 }
1686 #endif /* ifndef YY_NO_INPUT */
1687
1688 /** Immediately switch to a different input stream.
1689 * @param input_file A readable stream.
1690 * @param yyscanner The scanner object.
1691 * @note This function does not reset the start condition to @c INITIAL .
1692 */
yyrestart(FILE * input_file,yyscan_t yyscanner)1693 void yyrestart (FILE * input_file , yyscan_t yyscanner)
1694 {
1695 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1696
1697 if ( ! YY_CURRENT_BUFFER ){
1698 yyensure_buffer_stack (yyscanner);
1699 YY_CURRENT_BUFFER_LVALUE =
1700 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1701 }
1702
1703 yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
1704 yy_load_buffer_state( yyscanner );
1705 }
1706
1707 /** Switch to a different input buffer.
1708 * @param new_buffer The new input buffer.
1709 * @param yyscanner The scanner object.
1710 */
yy_switch_to_buffer(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)1711 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1712 {
1713 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1714
1715 /* TODO. We should be able to replace this entire function body
1716 * with
1717 * yypop_buffer_state();
1718 * yypush_buffer_state(new_buffer);
1719 */
1720 yyensure_buffer_stack (yyscanner);
1721 if ( YY_CURRENT_BUFFER == new_buffer )
1722 return;
1723
1724 if ( YY_CURRENT_BUFFER )
1725 {
1726 /* Flush out information for old buffer. */
1727 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1728 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1729 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1730 }
1731
1732 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1733 yy_load_buffer_state( yyscanner );
1734
1735 /* We don't actually know whether we did this switch during
1736 * EOF (yywrap()) processing, but the only time this flag
1737 * is looked at is after yywrap() is called, so it's safe
1738 * to go ahead and always set it.
1739 */
1740 yyg->yy_did_buffer_switch_on_eof = 1;
1741 }
1742
yy_load_buffer_state(yyscan_t yyscanner)1743 static void yy_load_buffer_state (yyscan_t yyscanner)
1744 {
1745 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1746 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1747 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1748 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1749 yyg->yy_hold_char = *yyg->yy_c_buf_p;
1750 }
1751
1752 /** Allocate and initialize an input buffer state.
1753 * @param file A readable stream.
1754 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1755 * @param yyscanner The scanner object.
1756 * @return the allocated buffer state.
1757 */
yy_create_buffer(FILE * file,int size,yyscan_t yyscanner)1758 YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
1759 {
1760 YY_BUFFER_STATE b;
1761
1762 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
1763 if ( ! b )
1764 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1765
1766 b->yy_buf_size = size;
1767
1768 /* yy_ch_buf has to be 2 characters longer than the size given because
1769 * we need to put in 2 end-of-buffer characters.
1770 */
1771 b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1772 if ( ! b->yy_ch_buf )
1773 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1774
1775 b->yy_is_our_buffer = 1;
1776
1777 yy_init_buffer( b, file , yyscanner);
1778
1779 return b;
1780 }
1781
1782 /** Destroy the buffer.
1783 * @param b a buffer created with yy_create_buffer()
1784 * @param yyscanner The scanner object.
1785 */
yy_delete_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)1786 void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1787 {
1788 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1789
1790 if ( ! b )
1791 return;
1792
1793 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1794 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1795
1796 if ( b->yy_is_our_buffer )
1797 yyfree( (void *) b->yy_ch_buf , yyscanner );
1798
1799 yyfree( (void *) b , yyscanner );
1800 }
1801
1802 /* Initializes or reinitializes a buffer.
1803 * This function is sometimes called more than once on the same buffer,
1804 * such as during a yyrestart() or at EOF.
1805 */
yy_init_buffer(YY_BUFFER_STATE b,FILE * file,yyscan_t yyscanner)1806 static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
1807
1808 {
1809 int oerrno = errno;
1810 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1811
1812 yy_flush_buffer( b , yyscanner);
1813
1814 b->yy_input_file = file;
1815 b->yy_fill_buffer = 1;
1816
1817 /* If b is the current buffer, then yy_init_buffer was _probably_
1818 * called from yyrestart() or through yy_get_next_buffer.
1819 * In that case, we don't want to reset the lineno or column.
1820 */
1821 if (b != YY_CURRENT_BUFFER){
1822 b->yy_bs_lineno = 1;
1823 b->yy_bs_column = 0;
1824 }
1825
1826 b->yy_is_interactive = 0;
1827
1828 errno = oerrno;
1829 }
1830
1831 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1832 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1833 * @param yyscanner The scanner object.
1834 */
yy_flush_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)1835 void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1836 {
1837 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1838 if ( ! b )
1839 return;
1840
1841 b->yy_n_chars = 0;
1842
1843 /* We always need two end-of-buffer characters. The first causes
1844 * a transition to the end-of-buffer state. The second causes
1845 * a jam in that state.
1846 */
1847 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1848 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1849
1850 b->yy_buf_pos = &b->yy_ch_buf[0];
1851
1852 b->yy_at_bol = 1;
1853 b->yy_buffer_status = YY_BUFFER_NEW;
1854
1855 if ( b == YY_CURRENT_BUFFER )
1856 yy_load_buffer_state( yyscanner );
1857 }
1858
1859 /** Pushes the new state onto the stack. The new state becomes
1860 * the current state. This function will allocate the stack
1861 * if necessary.
1862 * @param new_buffer The new state.
1863 * @param yyscanner The scanner object.
1864 */
yypush_buffer_state(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)1865 void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1866 {
1867 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1868 if (new_buffer == NULL)
1869 return;
1870
1871 yyensure_buffer_stack(yyscanner);
1872
1873 /* This block is copied from yy_switch_to_buffer. */
1874 if ( YY_CURRENT_BUFFER )
1875 {
1876 /* Flush out information for old buffer. */
1877 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1878 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1879 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1880 }
1881
1882 /* Only push if top exists. Otherwise, replace top. */
1883 if (YY_CURRENT_BUFFER)
1884 yyg->yy_buffer_stack_top++;
1885 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1886
1887 /* copied from yy_switch_to_buffer. */
1888 yy_load_buffer_state( yyscanner );
1889 yyg->yy_did_buffer_switch_on_eof = 1;
1890 }
1891
1892 /** Removes and deletes the top of the stack, if present.
1893 * The next element becomes the new top.
1894 * @param yyscanner The scanner object.
1895 */
yypop_buffer_state(yyscan_t yyscanner)1896 void yypop_buffer_state (yyscan_t yyscanner)
1897 {
1898 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1899 if (!YY_CURRENT_BUFFER)
1900 return;
1901
1902 yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner);
1903 YY_CURRENT_BUFFER_LVALUE = NULL;
1904 if (yyg->yy_buffer_stack_top > 0)
1905 --yyg->yy_buffer_stack_top;
1906
1907 if (YY_CURRENT_BUFFER) {
1908 yy_load_buffer_state( yyscanner );
1909 yyg->yy_did_buffer_switch_on_eof = 1;
1910 }
1911 }
1912
1913 /* Allocates the stack if it does not exist.
1914 * Guarantees space for at least one push.
1915 */
yyensure_buffer_stack(yyscan_t yyscanner)1916 static void yyensure_buffer_stack (yyscan_t yyscanner)
1917 {
1918 yy_size_t num_to_alloc;
1919 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1920
1921 if (!yyg->yy_buffer_stack) {
1922
1923 /* First allocation is just for 2 elements, since we don't know if this
1924 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1925 * immediate realloc on the next call.
1926 */
1927 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1928 yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
1929 (num_to_alloc * sizeof(struct yy_buffer_state*)
1930 , yyscanner);
1931 if ( ! yyg->yy_buffer_stack )
1932 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1933
1934 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1935
1936 yyg->yy_buffer_stack_max = num_to_alloc;
1937 yyg->yy_buffer_stack_top = 0;
1938 return;
1939 }
1940
1941 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
1942
1943 /* Increase the buffer to prepare for a possible push. */
1944 yy_size_t grow_size = 8 /* arbitrary grow size */;
1945
1946 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
1947 yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
1948 (yyg->yy_buffer_stack,
1949 num_to_alloc * sizeof(struct yy_buffer_state*)
1950 , yyscanner);
1951 if ( ! yyg->yy_buffer_stack )
1952 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1953
1954 /* zero only the new slots.*/
1955 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
1956 yyg->yy_buffer_stack_max = num_to_alloc;
1957 }
1958 }
1959
1960 /** Setup the input buffer state to scan directly from a user-specified character buffer.
1961 * @param base the character buffer
1962 * @param size the size in bytes of the character buffer
1963 * @param yyscanner The scanner object.
1964 * @return the newly allocated buffer state object.
1965 */
yy_scan_buffer(char * base,yy_size_t size,yyscan_t yyscanner)1966 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
1967 {
1968 YY_BUFFER_STATE b;
1969
1970 if ( size < 2 ||
1971 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1972 base[size-1] != YY_END_OF_BUFFER_CHAR )
1973 /* They forgot to leave room for the EOB's. */
1974 return NULL;
1975
1976 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
1977 if ( ! b )
1978 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1979
1980 b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
1981 b->yy_buf_pos = b->yy_ch_buf = base;
1982 b->yy_is_our_buffer = 0;
1983 b->yy_input_file = NULL;
1984 b->yy_n_chars = b->yy_buf_size;
1985 b->yy_is_interactive = 0;
1986 b->yy_at_bol = 1;
1987 b->yy_fill_buffer = 0;
1988 b->yy_buffer_status = YY_BUFFER_NEW;
1989
1990 yy_switch_to_buffer( b , yyscanner );
1991
1992 return b;
1993 }
1994
1995 /** Setup the input buffer state to scan a string. The next call to yylex() will
1996 * scan from a @e copy of @a str.
1997 * @param yystr a NUL-terminated string to scan
1998 * @param yyscanner The scanner object.
1999 * @return the newly allocated buffer state object.
2000 * @note If you want to scan bytes that may contain NUL values, then use
2001 * yy_scan_bytes() instead.
2002 */
yy_scan_string(const char * yystr,yyscan_t yyscanner)2003 YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
2004 {
2005
2006 return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2007 }
2008
2009 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2010 * scan from a @e copy of @a bytes.
2011 * @param yybytes the byte buffer to scan
2012 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2013 * @param yyscanner The scanner object.
2014 * @return the newly allocated buffer state object.
2015 */
yy_scan_bytes(const char * yybytes,int _yybytes_len,yyscan_t yyscanner)2016 YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
2017 {
2018 YY_BUFFER_STATE b;
2019 char *buf;
2020 yy_size_t n;
2021 int i;
2022
2023 /* Get memory for full buffer, including space for trailing EOB's. */
2024 n = (yy_size_t) (_yybytes_len + 2);
2025 buf = (char *) yyalloc( n , yyscanner );
2026 if ( ! buf )
2027 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2028
2029 for ( i = 0; i < _yybytes_len; ++i )
2030 buf[i] = yybytes[i];
2031
2032 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2033
2034 b = yy_scan_buffer( buf, n , yyscanner);
2035 if ( ! b )
2036 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2037
2038 /* It's okay to grow etc. this buffer, and we should throw it
2039 * away when we're done.
2040 */
2041 b->yy_is_our_buffer = 1;
2042
2043 return b;
2044 }
2045
2046 #ifndef YY_EXIT_FAILURE
2047 #define YY_EXIT_FAILURE 2
2048 #endif
2049
yy_fatal_error(const char * msg,yyscan_t yyscanner)2050 static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
2051 {
2052 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2053 (void)yyg;
2054 fprintf( stderr, "%s\n", msg );
2055 exit( YY_EXIT_FAILURE );
2056 }
2057
2058 /* Redefine yyless() so it works in section 3 code. */
2059
2060 #undef yyless
2061 #define yyless(n) \
2062 do \
2063 { \
2064 /* Undo effects of setting up yytext. */ \
2065 int yyless_macro_arg = (n); \
2066 YY_LESS_LINENO(yyless_macro_arg);\
2067 yytext[yyleng] = yyg->yy_hold_char; \
2068 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2069 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2070 *yyg->yy_c_buf_p = '\0'; \
2071 yyleng = yyless_macro_arg; \
2072 } \
2073 while ( 0 )
2074
2075 /* Accessor methods (get/set functions) to struct members. */
2076
2077 /** Get the user-defined data for this scanner.
2078 * @param yyscanner The scanner object.
2079 */
yyget_extra(yyscan_t yyscanner)2080 YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
2081 {
2082 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2083 return yyextra;
2084 }
2085
2086 /** Get the current line number.
2087 * @param yyscanner The scanner object.
2088 */
yyget_lineno(yyscan_t yyscanner)2089 int yyget_lineno (yyscan_t yyscanner)
2090 {
2091 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2092
2093 if (! YY_CURRENT_BUFFER)
2094 return 0;
2095
2096 return yylineno;
2097 }
2098
2099 /** Get the current column number.
2100 * @param yyscanner The scanner object.
2101 */
yyget_column(yyscan_t yyscanner)2102 int yyget_column (yyscan_t yyscanner)
2103 {
2104 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2105
2106 if (! YY_CURRENT_BUFFER)
2107 return 0;
2108
2109 return yycolumn;
2110 }
2111
2112 /** Get the input stream.
2113 * @param yyscanner The scanner object.
2114 */
yyget_in(yyscan_t yyscanner)2115 FILE *yyget_in (yyscan_t yyscanner)
2116 {
2117 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2118 return yyin;
2119 }
2120
2121 /** Get the output stream.
2122 * @param yyscanner The scanner object.
2123 */
yyget_out(yyscan_t yyscanner)2124 FILE *yyget_out (yyscan_t yyscanner)
2125 {
2126 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2127 return yyout;
2128 }
2129
2130 /** Get the length of the current token.
2131 * @param yyscanner The scanner object.
2132 */
yyget_leng(yyscan_t yyscanner)2133 int yyget_leng (yyscan_t yyscanner)
2134 {
2135 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2136 return yyleng;
2137 }
2138
2139 /** Get the current token.
2140 * @param yyscanner The scanner object.
2141 */
2142
yyget_text(yyscan_t yyscanner)2143 char *yyget_text (yyscan_t yyscanner)
2144 {
2145 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2146 return yytext;
2147 }
2148
2149 /** Set the user-defined data. This data is never touched by the scanner.
2150 * @param user_defined The data to be associated with this scanner.
2151 * @param yyscanner The scanner object.
2152 */
yyset_extra(YY_EXTRA_TYPE user_defined,yyscan_t yyscanner)2153 void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
2154 {
2155 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2156 yyextra = user_defined ;
2157 }
2158
2159 /** Set the current line number.
2160 * @param _line_number line number
2161 * @param yyscanner The scanner object.
2162 */
yyset_lineno(int _line_number,yyscan_t yyscanner)2163 void yyset_lineno (int _line_number , yyscan_t yyscanner)
2164 {
2165 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2166
2167 /* lineno is only valid if an input buffer exists. */
2168 if (! YY_CURRENT_BUFFER )
2169 YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
2170
2171 yylineno = _line_number;
2172 }
2173
2174 /** Set the current column.
2175 * @param _column_no column number
2176 * @param yyscanner The scanner object.
2177 */
yyset_column(int _column_no,yyscan_t yyscanner)2178 void yyset_column (int _column_no , yyscan_t yyscanner)
2179 {
2180 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2181
2182 /* column is only valid if an input buffer exists. */
2183 if (! YY_CURRENT_BUFFER )
2184 YY_FATAL_ERROR( "yyset_column called with no buffer" );
2185
2186 yycolumn = _column_no;
2187 }
2188
2189 /** Set the input stream. This does not discard the current
2190 * input buffer.
2191 * @param _in_str A readable stream.
2192 * @param yyscanner The scanner object.
2193 * @see yy_switch_to_buffer
2194 */
yyset_in(FILE * _in_str,yyscan_t yyscanner)2195 void yyset_in (FILE * _in_str , yyscan_t yyscanner)
2196 {
2197 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2198 yyin = _in_str ;
2199 }
2200
yyset_out(FILE * _out_str,yyscan_t yyscanner)2201 void yyset_out (FILE * _out_str , yyscan_t yyscanner)
2202 {
2203 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2204 yyout = _out_str ;
2205 }
2206
yyget_debug(yyscan_t yyscanner)2207 int yyget_debug (yyscan_t yyscanner)
2208 {
2209 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2210 return yy_flex_debug;
2211 }
2212
yyset_debug(int _bdebug,yyscan_t yyscanner)2213 void yyset_debug (int _bdebug , yyscan_t yyscanner)
2214 {
2215 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2216 yy_flex_debug = _bdebug ;
2217 }
2218
2219 /* Accessor methods for yylval and yylloc */
2220
yyget_lval(yyscan_t yyscanner)2221 YYSTYPE * yyget_lval (yyscan_t yyscanner)
2222 {
2223 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2224 return yylval;
2225 }
2226
yyset_lval(YYSTYPE * yylval_param,yyscan_t yyscanner)2227 void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
2228 {
2229 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2230 yylval = yylval_param;
2231 }
2232
2233 /* User-visible API */
2234
2235 /* yylex_init is special because it creates the scanner itself, so it is
2236 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2237 * That's why we explicitly handle the declaration, instead of using our macros.
2238 */
yylex_init(yyscan_t * ptr_yy_globals)2239 int yylex_init(yyscan_t* ptr_yy_globals)
2240 {
2241 if (ptr_yy_globals == NULL){
2242 errno = EINVAL;
2243 return 1;
2244 }
2245
2246 *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2247
2248 if (*ptr_yy_globals == NULL){
2249 errno = ENOMEM;
2250 return 1;
2251 }
2252
2253 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2254 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2255
2256 return yy_init_globals ( *ptr_yy_globals );
2257 }
2258
2259 /* yylex_init_extra has the same functionality as yylex_init, but follows the
2260 * convention of taking the scanner as the last argument. Note however, that
2261 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2262 * is the reason, too, why this function also must handle its own declaration).
2263 * The user defined value in the first argument will be available to yyalloc in
2264 * the yyextra field.
2265 */
yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t * ptr_yy_globals)2266 int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
2267 {
2268 struct yyguts_t dummy_yyguts;
2269
2270 yyset_extra (yy_user_defined, &dummy_yyguts);
2271
2272 if (ptr_yy_globals == NULL){
2273 errno = EINVAL;
2274 return 1;
2275 }
2276
2277 *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2278
2279 if (*ptr_yy_globals == NULL){
2280 errno = ENOMEM;
2281 return 1;
2282 }
2283
2284 /* By setting to 0xAA, we expose bugs in
2285 yy_init_globals. Leave at 0x00 for releases. */
2286 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2287
2288 yyset_extra (yy_user_defined, *ptr_yy_globals);
2289
2290 return yy_init_globals ( *ptr_yy_globals );
2291 }
2292
yy_init_globals(yyscan_t yyscanner)2293 static int yy_init_globals (yyscan_t yyscanner)
2294 {
2295 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2296 /* Initialization is the same as for the non-reentrant scanner.
2297 * This function is called from yylex_destroy(), so don't allocate here.
2298 */
2299
2300 yyg->yy_buffer_stack = NULL;
2301 yyg->yy_buffer_stack_top = 0;
2302 yyg->yy_buffer_stack_max = 0;
2303 yyg->yy_c_buf_p = NULL;
2304 yyg->yy_init = 0;
2305 yyg->yy_start = 0;
2306
2307 yyg->yy_start_stack_ptr = 0;
2308 yyg->yy_start_stack_depth = 0;
2309 yyg->yy_start_stack = NULL;
2310
2311 /* Defined in main.c */
2312 #ifdef YY_STDINIT
2313 yyin = stdin;
2314 yyout = stdout;
2315 #else
2316 yyin = NULL;
2317 yyout = NULL;
2318 #endif
2319
2320 /* For future reference: Set errno on error, since we are called by
2321 * yylex_init()
2322 */
2323 return 0;
2324 }
2325
2326 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
yylex_destroy(yyscan_t yyscanner)2327 int yylex_destroy (yyscan_t yyscanner)
2328 {
2329 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2330
2331 /* Pop the buffer stack, destroying each element. */
2332 while(YY_CURRENT_BUFFER){
2333 yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
2334 YY_CURRENT_BUFFER_LVALUE = NULL;
2335 yypop_buffer_state(yyscanner);
2336 }
2337
2338 /* Destroy the stack itself. */
2339 yyfree(yyg->yy_buffer_stack , yyscanner);
2340 yyg->yy_buffer_stack = NULL;
2341
2342 /* Destroy the start condition stack. */
2343 yyfree( yyg->yy_start_stack , yyscanner );
2344 yyg->yy_start_stack = NULL;
2345
2346 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2347 * yylex() is called, initialization will occur. */
2348 yy_init_globals( yyscanner);
2349
2350 /* Destroy the main struct (reentrant only). */
2351 yyfree ( yyscanner , yyscanner );
2352 yyscanner = NULL;
2353 return 0;
2354 }
2355
2356 /*
2357 * Internal utility routines.
2358 */
2359
2360 #ifndef yytext_ptr
yy_flex_strncpy(char * s1,const char * s2,int n,yyscan_t yyscanner)2361 static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
2362 {
2363 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2364 (void)yyg;
2365
2366 int i;
2367 for ( i = 0; i < n; ++i )
2368 s1[i] = s2[i];
2369 }
2370 #endif
2371
2372 #ifdef YY_NEED_STRLEN
yy_flex_strlen(const char * s,yyscan_t yyscanner)2373 static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
2374 {
2375 int n;
2376 for ( n = 0; s[n]; ++n )
2377 ;
2378
2379 return n;
2380 }
2381 #endif
2382
yyalloc(yy_size_t size,yyscan_t yyscanner)2383 void *yyalloc (yy_size_t size , yyscan_t yyscanner)
2384 {
2385 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2386 (void)yyg;
2387 return malloc(size);
2388 }
2389
yyrealloc(void * ptr,yy_size_t size,yyscan_t yyscanner)2390 void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
2391 {
2392 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2393 (void)yyg;
2394
2395 /* The cast to (char *) in the following accommodates both
2396 * implementations that use char* generic pointers, and those
2397 * that use void* generic pointers. It works with the latter
2398 * because both ANSI C and C++ allow castless assignment from
2399 * any pointer type to void*, and deal with argument conversions
2400 * as though doing an assignment.
2401 */
2402 return realloc(ptr, size);
2403 }
2404
yyfree(void * ptr,yyscan_t yyscanner)2405 void yyfree (void * ptr , yyscan_t yyscanner)
2406 {
2407 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2408 (void)yyg;
2409 free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2410 }
2411
2412 #define YYTABLES_NAME "yytables"
2413
2414 #line 196 "exprscan.l"
2415
2416
2417 void
expr_yyerror_more(yyscan_t yyscanner,const char * message,const char * more)2418 expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
2419 {
2420 PsqlScanState state = yyget_extra(yyscanner);
2421 int error_detection_offset = expr_scanner_offset(state) - 1;
2422 YYSTYPE lval;
2423 char *full_line;
2424 size_t l;
2425
2426 /*
2427 * While parsing an expression, we may not have collected the whole line
2428 * yet from the input source. Lex till EOL so we can report whole line.
2429 * (If we're at EOF, it's okay to call yylex() an extra time.)
2430 */
2431 if (!last_was_newline)
2432 {
2433 while (yylex(&lval, yyscanner))
2434 /* skip */ ;
2435 }
2436
2437 full_line = expr_scanner_get_substring(state,
2438 expr_start_offset,
2439 expr_scanner_offset(state));
2440 /* Trim trailing newline if any */
2441 l = strlen(full_line);
2442 while (l > 0 && full_line[l - 1] == '\n')
2443 full_line[--l] = '\0';
2444
2445 syntax_error(expr_source, expr_lineno, full_line, expr_command,
2446 message, more, error_detection_offset - expr_start_offset);
2447 }
2448
2449 void
expr_yyerror(yyscan_t yyscanner,const char * message)2450 expr_yyerror(yyscan_t yyscanner, const char *message)
2451 {
2452 expr_yyerror_more(yyscanner, message, NULL);
2453 }
2454
2455 /*
2456 * Collect a space-separated word from a backslash command and return it
2457 * in word_buf, along with its starting string offset in *offset.
2458 * Returns true if successful, false if at end of command.
2459 */
2460 bool
expr_lex_one_word(PsqlScanState state,PQExpBuffer word_buf,int * offset)2461 expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, int *offset)
2462 {
2463 int lexresult;
2464 YYSTYPE lval;
2465
2466 /* Must be scanning already */
2467 Assert(state->scanbufhandle != NULL);
2468
2469 /* Set current output target */
2470 state->output_buf = word_buf;
2471 resetPQExpBuffer(word_buf);
2472
2473 /* Set input source */
2474 if (state->buffer_stack != NULL)
2475 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
2476 else
2477 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
2478
2479 /* Set start state */
2480 state->start_state = INITIAL;
2481
2482 /* And lex. */
2483 lexresult = yylex(&lval, state->scanner);
2484
2485 /*
2486 * Save start offset of word, if any. We could do this more efficiently,
2487 * but for now this seems fine.
2488 */
2489 if (lexresult)
2490 *offset = expr_scanner_offset(state) - word_buf->len;
2491 else
2492 *offset = -1;
2493
2494 /*
2495 * In case the caller returns to using the regular SQL lexer, reselect the
2496 * appropriate initial state.
2497 */
2498 psql_scan_reselect_sql_lexer(state);
2499
2500 return (bool) lexresult;
2501 }
2502
2503 /*
2504 * Prepare to lex an expression via expr_yyparse().
2505 *
2506 * Returns the yyscan_t that is to be passed to expr_yyparse().
2507 * (This is just state->scanner, but callers don't need to know that.)
2508 */
2509 yyscan_t
expr_scanner_init(PsqlScanState state,const char * source,int lineno,int start_offset,const char * command)2510 expr_scanner_init(PsqlScanState state,
2511 const char *source, int lineno, int start_offset,
2512 const char *command)
2513 {
2514 /* Save error context info */
2515 expr_source = source;
2516 expr_lineno = lineno;
2517 expr_start_offset = start_offset;
2518 expr_command = command;
2519
2520 /* Must be scanning already */
2521 Assert(state->scanbufhandle != NULL);
2522
2523 /* Set current output target */
2524 state->output_buf = NULL;
2525
2526 /* Set input source */
2527 if (state->buffer_stack != NULL)
2528 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
2529 else
2530 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
2531
2532 /* Set start state */
2533 state->start_state = EXPR;
2534
2535 return state->scanner;
2536 }
2537
2538 /*
2539 * Finish lexing an expression.
2540 */
2541 void
expr_scanner_finish(yyscan_t yyscanner)2542 expr_scanner_finish(yyscan_t yyscanner)
2543 {
2544 PsqlScanState state = yyget_extra(yyscanner);
2545
2546 /*
2547 * Reselect appropriate initial state for SQL lexer.
2548 */
2549 psql_scan_reselect_sql_lexer(state);
2550 }
2551
2552 /*
2553 * Get offset from start of string to end of current lexer token.
2554 *
2555 * We rely on the knowledge that flex modifies the scan buffer by storing
2556 * a NUL at the end of the current token (yytext). Note that this might
2557 * not work quite right if we were parsing a sub-buffer, but since pgbench
2558 * never invokes that functionality, it doesn't matter.
2559 */
2560 int
expr_scanner_offset(PsqlScanState state)2561 expr_scanner_offset(PsqlScanState state)
2562 {
2563 return strlen(state->scanbuf);
2564 }
2565
2566 /*
2567 * Get a malloc'd copy of the lexer input string from start_offset
2568 * to just before end_offset.
2569 */
2570 char *
expr_scanner_get_substring(PsqlScanState state,int start_offset,int end_offset)2571 expr_scanner_get_substring(PsqlScanState state,
2572 int start_offset, int end_offset)
2573 {
2574 char *result;
2575 int slen = end_offset - start_offset;
2576
2577 Assert(slen >= 0);
2578 Assert(end_offset <= strlen(state->scanbuf));
2579 result = (char *) pg_malloc(slen + 1);
2580 memcpy(result, state->scanbuf + start_offset, slen);
2581 result[slen] = '\0';
2582
2583 return result;
2584 }
2585
2586 /*
2587 * Get the line number associated with the given string offset
2588 * (which must not be past the end of where we've lexed to).
2589 */
2590 int
expr_scanner_get_lineno(PsqlScanState state,int offset)2591 expr_scanner_get_lineno(PsqlScanState state, int offset)
2592 {
2593 int lineno = 1;
2594 const char *p = state->scanbuf;
2595
2596 while (*p && offset > 0)
2597 {
2598 if (*p == '\n')
2599 lineno++;
2600 p++, offset--;
2601 }
2602 return lineno;
2603 }
2604
2605