calclex.c revision 1.1.1.2 1
2 #line 3 "calclex.c"
3
4 #define YY_INT_ALIGNED short int
5
6 /* A lexical scanner generated by flex */
7
8 #define FLEX_SCANNER
9 #define YY_FLEX_MAJOR_VERSION 2
10 #define YY_FLEX_MINOR_VERSION 5
11 #define YY_FLEX_SUBMINOR_VERSION 37
12 #if YY_FLEX_SUBMINOR_VERSION > 0
13 #define FLEX_BETA
14 #endif
15
16 /* First, we deal with platform-specific or compiler-specific issues. */
17
18 /* begin standard C headers. */
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <stdlib.h>
23
24 /* end standard C headers. */
25
26 /* flex integer type definitions */
27
28 #ifndef FLEXINT_H
29 #define FLEXINT_H
30
31 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
32
33 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
34
35 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
36 * if you want the limit (max/min) macros for int types.
37 */
38 #ifndef __STDC_LIMIT_MACROS
39 #define __STDC_LIMIT_MACROS 1
40 #endif
41
42 #include <inttypes.h>
43 typedef int8_t flex_int8_t;
44 typedef uint8_t flex_uint8_t;
45 typedef int16_t flex_int16_t;
46 typedef uint16_t flex_uint16_t;
47 typedef int32_t flex_int32_t;
48 typedef uint32_t flex_uint32_t;
49 #else
50 typedef signed char flex_int8_t;
51 typedef short int flex_int16_t;
52 typedef int flex_int32_t;
53 typedef unsigned char flex_uint8_t;
54 typedef unsigned short int flex_uint16_t;
55 typedef unsigned int flex_uint32_t;
56
57 /* Limits of integral types. */
58 #ifndef INT8_MIN
59 #define INT8_MIN (-128)
60 #endif
61 #ifndef INT16_MIN
62 #define INT16_MIN (-32767-1)
63 #endif
64 #ifndef INT32_MIN
65 #define INT32_MIN (-2147483647-1)
66 #endif
67 #ifndef INT8_MAX
68 #define INT8_MAX (127)
69 #endif
70 #ifndef INT16_MAX
71 #define INT16_MAX (32767)
72 #endif
73 #ifndef INT32_MAX
74 #define INT32_MAX (2147483647)
75 #endif
76 #ifndef UINT8_MAX
77 #define UINT8_MAX (255U)
78 #endif
79 #ifndef UINT16_MAX
80 #define UINT16_MAX (65535U)
81 #endif
82 #ifndef UINT32_MAX
83 #define UINT32_MAX (4294967295U)
84 #endif
85
86 #endif /* ! C99 */
87
88 #endif /* ! FLEXINT_H */
89
90 #ifdef __cplusplus
91
92 /* The "const" storage-class-modifier is valid. */
93 #define YY_USE_CONST
94
95 #else /* ! __cplusplus */
96
97 /* C99 requires __STDC__ to be defined as 1. */
98 #if defined (__STDC__)
99
100 #define YY_USE_CONST
101
102 #endif /* defined (__STDC__) */
103 #endif /* ! __cplusplus */
104
105 #ifdef YY_USE_CONST
106 #define yyconst const
107 #else
108 #define yyconst
109 #endif
110
111 /* Returned upon end-of-file. */
112 #define YY_NULL 0
113
114 /* Promotes a possibly negative, possibly signed char to an unsigned
115 * integer for use as an array index. If the signed char is negative,
116 * we want to instead treat it as an 8-bit unsigned char, hence the
117 * double cast.
118 */
119 #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
120
121 /* Enter a start condition. This macro really ought to take a parameter,
122 * but we do it the disgusting crufty way forced on us by the ()-less
123 * definition of BEGIN.
124 */
125 #define BEGIN (yy_start) = 1 + 2 *
126
127 /* Translate the current start state into a value that can be later handed
128 * to BEGIN to return to the state. The YYSTATE alias is for lex
129 * compatibility.
130 */
131 #define YY_START (((yy_start) - 1) / 2)
132 #define YYSTATE YY_START
133
134 /* Action number for EOF rule of a given start state. */
135 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
136
137 /* Special action meaning "start processing a new file". */
138 #define YY_NEW_FILE yyrestart(yyin )
139
140 #define YY_END_OF_BUFFER_CHAR 0
141
142 /* Size of default input buffer. */
143 #ifndef YY_BUF_SIZE
144 #define YY_BUF_SIZE 16384
145 #endif
146
147 /* The state buf must be large enough to hold one state per character in the main buffer.
148 */
149 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
150
151 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
152 #define YY_TYPEDEF_YY_BUFFER_STATE
153 typedef struct yy_buffer_state *YY_BUFFER_STATE;
154 #endif
155
156 #ifndef YY_TYPEDEF_YY_SIZE_T
157 #define YY_TYPEDEF_YY_SIZE_T
158 typedef size_t yy_size_t;
159 #endif
160
161 extern yy_size_t yyleng;
162
163 extern FILE *yyin, *yyout;
164
165 #define EOB_ACT_CONTINUE_SCAN 0
166 #define EOB_ACT_END_OF_FILE 1
167 #define EOB_ACT_LAST_MATCH 2
168
169 #define YY_LESS_LINENO(n)
170
171 /* Return all but the first "n" matched characters back to the input stream. */
172 #define yyless(n) \
173 do \
174 { \
175 /* Undo effects of setting up yytext. */ \
176 int yyless_macro_arg = (n); \
177 YY_LESS_LINENO(yyless_macro_arg);\
178 *yy_cp = (yy_hold_char); \
179 YY_RESTORE_YY_MORE_OFFSET \
180 (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
181 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
182 } \
183 while ( 0 )
184
185 #define unput(c) yyunput( c, (yytext_ptr) )
186
187 #ifndef YY_STRUCT_YY_BUFFER_STATE
188 #define YY_STRUCT_YY_BUFFER_STATE
189 struct yy_buffer_state
190 {
191 FILE *yy_input_file;
192
193 char *yy_ch_buf; /* input buffer */
194 char *yy_buf_pos; /* current position in input buffer */
195
196 /* Size of input buffer in bytes, not including room for EOB
197 * characters.
198 */
199 yy_size_t yy_buf_size;
200
201 /* Number of characters read into yy_ch_buf, not including EOB
202 * characters.
203 */
204 yy_size_t yy_n_chars;
205
206 /* Whether we "own" the buffer - i.e., we know we created it,
207 * and can realloc() it to grow it, and should free() it to
208 * delete it.
209 */
210 int yy_is_our_buffer;
211
212 /* Whether this is an "interactive" input source; if so, and
213 * if we're using stdio for input, then we want to use getc()
214 * instead of fread(), to make sure we stop fetching input after
215 * each newline.
216 */
217 int yy_is_interactive;
218
219 /* Whether we're considered to be at the beginning of a line.
220 * If so, '^' rules will be active on the next match, otherwise
221 * not.
222 */
223 int yy_at_bol;
224
225 int yy_bs_lineno; /**< The line count. */
226 int yy_bs_column; /**< The column count. */
227
228 /* Whether to try to fill the input buffer when we reach the
229 * end of it.
230 */
231 int yy_fill_buffer;
232
233 int yy_buffer_status;
234
235 #define YY_BUFFER_NEW 0
236 #define YY_BUFFER_NORMAL 1
237 /* When an EOF's been seen but there's still some text to process
238 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
239 * shouldn't try reading from the input source any more. We might
240 * still have a bunch of tokens to match, though, because of
241 * possible backing-up.
242 *
243 * When we actually see the EOF, we change the status to "new"
244 * (via yyrestart()), so that the user can continue scanning by
245 * just pointing yyin at a new input file.
246 */
247 #define YY_BUFFER_EOF_PENDING 2
248
249 };
250 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
251
252 /* Stack of input buffers. */
253 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
254 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
255 static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
256
257 /* We provide macros for accessing buffer states in case in the
258 * future we want to put the buffer states in a more general
259 * "scanner state".
260 *
261 * Returns the top of the stack, or NULL.
262 */
263 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
264 ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
265 : NULL)
266
267 /* Same as previous macro, but useful when we know that the buffer stack is not
268 * NULL or when we need an lvalue. For internal use only.
269 */
270 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
271
272 /* yy_hold_char holds the character lost when yytext is formed. */
273 static char yy_hold_char;
274 static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
275 yy_size_t yyleng;
276
277 /* Points to current character in buffer. */
278 static char *yy_c_buf_p = (char *) 0;
279 static int yy_init = 0; /* whether we need to initialize */
280 static int yy_start = 0; /* start state number */
281
282 /* Flag which is used to allow yywrap()'s to do buffer switches
283 * instead of setting up a fresh yyin. A bit of a hack ...
284 */
285 static int yy_did_buffer_switch_on_eof;
286
287 void yyrestart (FILE *input_file );
288 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer );
289 YY_BUFFER_STATE yy_create_buffer (FILE *file,int size );
290 void yy_delete_buffer (YY_BUFFER_STATE b );
291 void yy_flush_buffer (YY_BUFFER_STATE b );
292 void yypush_buffer_state (YY_BUFFER_STATE new_buffer );
293 void yypop_buffer_state (void );
294
295 static void yyensure_buffer_stack (void );
296 static void yy_load_buffer_state (void );
297 static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
298
299 #define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )
300
301 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
302 YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
303 YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len );
304
305 void *yyalloc (yy_size_t );
306 void *yyrealloc (void *,yy_size_t );
307 void yyfree (void * );
308
309 #define yy_new_buffer yy_create_buffer
310
311 #define yy_set_interactive(is_interactive) \
312 { \
313 if ( ! YY_CURRENT_BUFFER ){ \
314 yyensure_buffer_stack (); \
315 YY_CURRENT_BUFFER_LVALUE = \
316 yy_create_buffer(yyin,YY_BUF_SIZE ); \
317 } \
318 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
319 }
320
321 #define yy_set_bol(at_bol) \
322 { \
323 if ( ! YY_CURRENT_BUFFER ){\
324 yyensure_buffer_stack (); \
325 YY_CURRENT_BUFFER_LVALUE = \
326 yy_create_buffer(yyin,YY_BUF_SIZE ); \
327 } \
328 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
329 }
330
331 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
332
333 /* Begin user sect3 */
334
335 typedef unsigned char YY_CHAR;
336
337 FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
338
339 typedef int yy_state_type;
340
341 extern int yylineno;
342
343 int yylineno = 1;
344
345 extern char *yytext;
346 #define yytext_ptr yytext
347
348 static yy_state_type yy_get_previous_state (void );
349 static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
350 static int yy_get_next_buffer (void );
351 static void yy_fatal_error (yyconst char msg[] );
352
353 /* Done after the current pattern has been matched and before the
354 * corresponding action - sets up yytext.
355 */
356 #define YY_DO_BEFORE_ACTION \
357 (yytext_ptr) = yy_bp; \
358 yyleng = (size_t) (yy_cp - yy_bp); \
359 (yy_hold_char) = *yy_cp; \
360 *yy_cp = '\0'; \
361 (yy_c_buf_p) = yy_cp;
362
363 #define YY_NUM_RULES 19
364 #define YY_END_OF_BUFFER 20
365 /* This struct is not used in this scanner,
366 but its presence is necessary. */
367 struct yy_trans_info
368 {
369 flex_int32_t yy_verify;
370 flex_int32_t yy_nxt;
371 };
372 static yyconst flex_int16_t yy_accept[39] =
373 { 0,
374 0, 0, 20, 18, 1, 2, 7, 6, 7, 18,
375 16, 16, 2, 7, 7, 7, 16, 17, 18, 18,
376 11, 6, 5, 6, 14, 16, 0, 12, 8, 10,
377 9, 13, 16, 17, 3, 15, 4, 0
378 } ;
379
380 static yyconst flex_int32_t yy_ec[256] =
381 { 0,
382 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
383 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
384 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
385 1, 2, 4, 1, 5, 1, 6, 7, 1, 6,
386 6, 6, 6, 6, 6, 1, 6, 8, 9, 9,
387 9, 9, 9, 9, 9, 9, 9, 1, 10, 11,
388 12, 13, 1, 1, 14, 14, 14, 14, 14, 14,
389 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
390 15, 15, 15, 15, 15, 15, 15, 16, 15, 15,
391 1, 17, 1, 6, 1, 1, 15, 15, 15, 15,
392
393 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
394 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
395 15, 15, 1, 18, 1, 1, 1, 1, 1, 1,
396 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
397 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
398 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
399 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
400 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
401 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
402 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
403
404 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
405 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
406 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
407 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
408 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
409 1, 1, 1, 1, 1
410 } ;
411
412 static yyconst flex_int32_t yy_meta[19] =
413 { 0,
414 1, 1, 1, 1, 1, 1, 1, 2, 2, 1,
415 1, 1, 1, 2, 3, 2, 1, 1
416 } ;
417
418 static yyconst flex_int16_t yy_base[43] =
419 { 0,
420 0, 0, 39, 49, 49, 49, 26, 16, 49, 30,
421 20, 19, 49, 9, 22, 10, 9, 0, 29, 13,
422 49, 23, 49, 24, 49, 0, 0, 49, 49, 49,
423 49, 49, 13, 0, 49, 49, 49, 49, 41, 28,
424 43, 45
425 } ;
426
427 static yyconst flex_int16_t yy_def[43] =
428 { 0,
429 38, 1, 38, 38, 38, 38, 38, 39, 38, 38,
430 40, 40, 38, 38, 38, 38, 41, 42, 38, 38,
431 38, 39, 38, 39, 38, 12, 12, 38, 38, 38,
432 38, 38, 41, 42, 38, 38, 38, 0, 38, 38,
433 38, 38
434 } ;
435
436 static yyconst flex_int16_t yy_nxt[68] =
437 { 0,
438 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
439 14, 15, 16, 17, 18, 18, 19, 20, 23, 28,
440 29, 31, 32, 34, 34, 23, 37, 34, 34, 26,
441 36, 35, 24, 30, 38, 27, 25, 21, 38, 24,
442 24, 22, 22, 22, 33, 33, 34, 34, 3, 38,
443 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
444 38, 38, 38, 38, 38, 38, 38
445 } ;
446
447 static yyconst flex_int16_t yy_chk[68] =
448 { 0,
449 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
450 1, 1, 1, 1, 1, 1, 1, 1, 8, 14,
451 14, 16, 16, 17, 17, 22, 24, 33, 33, 40,
452 20, 19, 8, 15, 12, 11, 10, 7, 3, 22,
453 24, 39, 39, 39, 41, 41, 42, 42, 38, 38,
454 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
455 38, 38, 38, 38, 38, 38, 38
456 } ;
457
458 static yy_state_type yy_last_accepting_state;
459 static char *yy_last_accepting_cpos;
460
461 extern int yy_flex_debug;
462 int yy_flex_debug = 0;
463
464 /* The intent behind this definition is that it'll catch
465 * any uses of REJECT which flex missed.
466 */
467 #define REJECT reject_used_but_not_detected
468 #define yymore() yymore_used_but_not_detected
469 #define YY_MORE_ADJ 0
470 #define YY_RESTORE_YY_MORE_OFFSET
471 char *yytext;
472 #line 1 "calclex.l"
473 /* Lexical analyzer for calc program.
474
475 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
476
477 This file is part of the GNU MP Library.
478
479 This program is free software; you can redistribute it and/or modify it under
480 the terms of the GNU General Public License as published by the Free Software
481 Foundation; either version 3 of the License, or (at your option) any later
482 version.
483
484 This program is distributed in the hope that it will be useful, but WITHOUT ANY
485 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
486 PARTICULAR PURPOSE. See the GNU General Public License for more details.
487
488 You should have received a copy of the GNU General Public License along with
489 this program. If not, see http://www.gnu.org/licenses/. */
490 #line 20 "calclex.l"
491 #include <string.h>
492 #include "calc-common.h"
493
494
495 #if WITH_READLINE
496 /* Let GNU flex use readline. See the calcread.c redefined input() for a
497 way that might work for a standard lex too. */
498 #define YY_INPUT(buf,result,max_size) \
499 result = calc_input (buf, max_size);
500 #endif
501
502
503 /* Non-zero when reading the second or subsequent line of an expression,
504 used to give a different prompt when using readline. */
505 int calc_more_input = 0;
506
507
508 const struct calc_keywords_t calc_keywords[] = {
509 { "abs", ABS },
510 { "bin", BIN },
511 { "decimal", DECIMAL },
512 { "fib", FIB },
513 { "hex", HEX },
514 { "help", HELP },
515 { "gcd", GCD },
516 { "kron", KRON },
517 { "lcm", LCM },
518 { "lucnum", LUCNUM },
519 { "nextprime", NEXTPRIME },
520 { "powm", POWM },
521 { "quit", QUIT },
522 { "root", ROOT },
523 { "sqrt", SQRT },
524 { NULL }
525 };
526 #line 527 "calclex.c"
527
528 #define INITIAL 0
529
530 #ifndef YY_NO_UNISTD_H
531 /* Special case for "unistd.h", since it is non-ANSI. We include it way
532 * down here because we want the user's section 1 to have been scanned first.
533 * The user has a chance to override it with an option.
534 */
535 #include <unistd.h>
536 #endif
537
538 #ifndef YY_EXTRA_TYPE
539 #define YY_EXTRA_TYPE void *
540 #endif
541
542 static int yy_init_globals (void );
543
544 /* Accessor methods to globals.
545 These are made visible to non-reentrant scanners for convenience. */
546
547 int yylex_destroy (void );
548
549 int yyget_debug (void );
550
551 void yyset_debug (int debug_flag );
552
553 YY_EXTRA_TYPE yyget_extra (void );
554
555 void yyset_extra (YY_EXTRA_TYPE user_defined );
556
557 FILE *yyget_in (void );
558
559 void yyset_in (FILE * in_str );
560
561 FILE *yyget_out (void );
562
563 void yyset_out (FILE * out_str );
564
565 yy_size_t yyget_leng (void );
566
567 char *yyget_text (void );
568
569 int yyget_lineno (void );
570
571 void yyset_lineno (int line_number );
572
573 /* Macros after this point can all be overridden by user definitions in
574 * section 1.
575 */
576
577 #ifndef YY_SKIP_YYWRAP
578 #ifdef __cplusplus
579 extern "C" int yywrap (void );
580 #else
581 extern int yywrap (void );
582 #endif
583 #endif
584
585 static void yyunput (int c,char *buf_ptr );
586
587 #ifndef yytext_ptr
588 static void yy_flex_strncpy (char *,yyconst char *,int );
589 #endif
590
591 #ifdef YY_NEED_STRLEN
592 static int yy_flex_strlen (yyconst char * );
593 #endif
594
595 #ifndef YY_NO_INPUT
596
597 #ifdef __cplusplus
598 static int yyinput (void );
599 #else
600 static int input (void );
601 #endif
602
603 #endif
604
605 /* Amount of stuff to slurp up with each read. */
606 #ifndef YY_READ_BUF_SIZE
607 #define YY_READ_BUF_SIZE 8192
608 #endif
609
610 /* Copy whatever the last rule matched to the standard output. */
611 #ifndef ECHO
612 /* This used to be an fputs(), but since the string might contain NUL's,
613 * we now use fwrite().
614 */
615 #define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
616 #endif
617
618 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
619 * is returned in "result".
620 */
621 #ifndef YY_INPUT
622 #define YY_INPUT(buf,result,max_size) \
623 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
624 { \
625 int c = '*'; \
626 size_t n; \
627 for ( n = 0; n < max_size && \
628 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
629 buf[n] = (char) c; \
630 if ( c == '\n' ) \
631 buf[n++] = (char) c; \
632 if ( c == EOF && ferror( yyin ) ) \
633 YY_FATAL_ERROR( "input in flex scanner failed" ); \
634 result = n; \
635 } \
636 else \
637 { \
638 errno=0; \
639 while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
640 { \
641 if( errno != EINTR) \
642 { \
643 YY_FATAL_ERROR( "input in flex scanner failed" ); \
644 break; \
645 } \
646 errno=0; \
647 clearerr(yyin); \
648 } \
649 }\
650 \
651
652 #endif
653
654 /* No semi-colon after return; correct usage is to write "yyterminate();" -
655 * we don't want an extra ';' after the "return" because that will cause
656 * some compilers to complain about unreachable statements.
657 */
658 #ifndef yyterminate
659 #define yyterminate() return YY_NULL
660 #endif
661
662 /* Number of entries by which start-condition stack grows. */
663 #ifndef YY_START_STACK_INCR
664 #define YY_START_STACK_INCR 25
665 #endif
666
667 /* Report a fatal error. */
668 #ifndef YY_FATAL_ERROR
669 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
670 #endif
671
672 /* end tables serialization structures and prototypes */
673
674 /* Default declaration of generated scanner - a define so the user can
675 * easily add parameters.
676 */
677 #ifndef YY_DECL
678 #define YY_DECL_IS_OURS 1
679
680 extern int yylex (void);
681
682 #define YY_DECL int yylex (void)
683 #endif /* !YY_DECL */
684
685 /* Code executed at the beginning of each rule, after yytext and yyleng
686 * have been set up.
687 */
688 #ifndef YY_USER_ACTION
689 #define YY_USER_ACTION
690 #endif
691
692 /* Code executed at the end of each rule. */
693 #ifndef YY_BREAK
694 #define YY_BREAK break;
695 #endif
696
697 #define YY_RULE_SETUP \
698 YY_USER_ACTION
699
700 /** The main scanner function which does all the work.
701 */
702 YY_DECL
703 {
704 register yy_state_type yy_current_state;
705 register char *yy_cp, *yy_bp;
706 register int yy_act;
707
708 #line 57 "calclex.l"
709
710
711 #line 712 "calclex.c"
712
713 if ( !(yy_init) )
714 {
715 (yy_init) = 1;
716
717 #ifdef YY_USER_INIT
718 YY_USER_INIT;
719 #endif
720
721 if ( ! (yy_start) )
722 (yy_start) = 1; /* first start state */
723
724 if ( ! yyin )
725 yyin = stdin;
726
727 if ( ! yyout )
728 yyout = stdout;
729
730 if ( ! YY_CURRENT_BUFFER ) {
731 yyensure_buffer_stack ();
732 YY_CURRENT_BUFFER_LVALUE =
733 yy_create_buffer(yyin,YY_BUF_SIZE );
734 }
735
736 yy_load_buffer_state( );
737 }
738
739 while ( 1 ) /* loops until end-of-file is reached */
740 {
741 yy_cp = (yy_c_buf_p);
742
743 /* Support of yytext. */
744 *yy_cp = (yy_hold_char);
745
746 /* yy_bp points to the position in yy_ch_buf of the start of
747 * the current run.
748 */
749 yy_bp = yy_cp;
750
751 yy_current_state = (yy_start);
752 yy_match:
753 do
754 {
755 register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
756 if ( yy_accept[yy_current_state] )
757 {
758 (yy_last_accepting_state) = yy_current_state;
759 (yy_last_accepting_cpos) = yy_cp;
760 }
761 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
762 {
763 yy_current_state = (int) yy_def[yy_current_state];
764 if ( yy_current_state >= 39 )
765 yy_c = yy_meta[(unsigned int) yy_c];
766 }
767 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
768 ++yy_cp;
769 }
770 while ( yy_base[yy_current_state] != 49 );
771
772 yy_find_action:
773 yy_act = yy_accept[yy_current_state];
774 if ( yy_act == 0 )
775 { /* have to back up */
776 yy_cp = (yy_last_accepting_cpos);
777 yy_current_state = (yy_last_accepting_state);
778 yy_act = yy_accept[yy_current_state];
779 }
780
781 YY_DO_BEFORE_ACTION;
782
783 do_action: /* This label is used only to access EOF actions. */
784
785 switch ( yy_act )
786 { /* beginning of action switch */
787 case 0: /* must back up */
788 /* undo the effects of YY_DO_BEFORE_ACTION */
789 *yy_cp = (yy_hold_char);
790 yy_cp = (yy_last_accepting_cpos);
791 yy_current_state = (yy_last_accepting_state);
792 goto yy_find_action;
793
794 case 1:
795 YY_RULE_SETUP
796 #line 59 "calclex.l"
797 { /* white space is skipped */ }
798 YY_BREAK
799 case 2:
800 /* rule 2 can match eol */
801 YY_RULE_SETUP
802 #line 61 "calclex.l"
803 { /* semicolon or newline separates statements */
804 calc_more_input = 0;
805 return EOS; }
806 YY_BREAK
807 case 3:
808 /* rule 3 can match eol */
809 YY_RULE_SETUP
810 #line 64 "calclex.l"
811 { /* escaped newlines are skipped */ }
812 YY_BREAK
813 case 4:
814 /* rule 4 can match eol */
815 YY_RULE_SETUP
816 #line 67 "calclex.l"
817 {
818 /* comment through to escaped newline is skipped */ }
819 YY_BREAK
820 case 5:
821 /* rule 5 can match eol */
822 YY_RULE_SETUP
823 #line 69 "calclex.l"
824 { /* comment through to newline is a separator */
825 calc_more_input = 0;
826 return EOS; }
827 YY_BREAK
828 case 6:
829 YY_RULE_SETUP
830 #line 72 "calclex.l"
831 { /* comment through to EOF skipped */ }
832 YY_BREAK
833 case 7:
834 YY_RULE_SETUP
835 #line 75 "calclex.l"
836 { return yytext[0]; }
837 YY_BREAK
838 case 8:
839 YY_RULE_SETUP
840 #line 76 "calclex.l"
841 { return LE; }
842 YY_BREAK
843 case 9:
844 YY_RULE_SETUP
845 #line 77 "calclex.l"
846 { return GE; }
847 YY_BREAK
848 case 10:
849 YY_RULE_SETUP
850 #line 78 "calclex.l"
851 { return EQ; }
852 YY_BREAK
853 case 11:
854 YY_RULE_SETUP
855 #line 79 "calclex.l"
856 { return NE; }
857 YY_BREAK
858 case 12:
859 YY_RULE_SETUP
860 #line 80 "calclex.l"
861 { return LSHIFT; }
862 YY_BREAK
863 case 13:
864 YY_RULE_SETUP
865 #line 81 "calclex.l"
866 { return RSHIFT; }
867 YY_BREAK
868 case 14:
869 YY_RULE_SETUP
870 #line 82 "calclex.l"
871 { return LAND; }
872 YY_BREAK
873 case 15:
874 YY_RULE_SETUP
875 #line 83 "calclex.l"
876 { return LOR; }
877 YY_BREAK
878 case 16:
879 YY_RULE_SETUP
880 #line 85 "calclex.l"
881 {
882 yylval.str = yytext;
883 return NUMBER; }
884 YY_BREAK
885 case 17:
886 YY_RULE_SETUP
887 #line 89 "calclex.l"
888 {
889 int i;
890
891 for (i = 0; calc_keywords[i].name != NULL; i++)
892 if (strcmp (yytext, calc_keywords[i].name) == 0)
893 return calc_keywords[i].value;
894
895 if (yytext[0] >= 'a' && yytext[0] <= 'z' && yytext[1] == '\0')
896 {
897 yylval.var = yytext[0] - 'a';
898 return VARIABLE;
899 }
900
901 return BAD;
902 }
903 YY_BREAK
904 case 18:
905 YY_RULE_SETUP
906 #line 105 "calclex.l"
907 { return BAD; }
908 YY_BREAK
909 case 19:
910 YY_RULE_SETUP
911 #line 107 "calclex.l"
912 ECHO;
913 YY_BREAK
914 #line 915 "calclex.c"
915 case YY_STATE_EOF(INITIAL):
916 yyterminate();
917
918 case YY_END_OF_BUFFER:
919 {
920 /* Amount of text matched not including the EOB char. */
921 int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
922
923 /* Undo the effects of YY_DO_BEFORE_ACTION. */
924 *yy_cp = (yy_hold_char);
925 YY_RESTORE_YY_MORE_OFFSET
926
927 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
928 {
929 /* We're scanning a new file or input source. It's
930 * possible that this happened because the user
931 * just pointed yyin at a new source and called
932 * yylex(). If so, then we have to assure
933 * consistency between YY_CURRENT_BUFFER and our
934 * globals. Here is the right place to do so, because
935 * this is the first action (other than possibly a
936 * back-up) that will match for the new input source.
937 */
938 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
939 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
940 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
941 }
942
943 /* Note that here we test for yy_c_buf_p "<=" to the position
944 * of the first EOB in the buffer, since yy_c_buf_p will
945 * already have been incremented past the NUL character
946 * (since all states make transitions on EOB to the
947 * end-of-buffer state). Contrast this with the test
948 * in input().
949 */
950 if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
951 { /* This was really a NUL. */
952 yy_state_type yy_next_state;
953
954 (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
955
956 yy_current_state = yy_get_previous_state( );
957
958 /* Okay, we're now positioned to make the NUL
959 * transition. We couldn't have
960 * yy_get_previous_state() go ahead and do it
961 * for us because it doesn't know how to deal
962 * with the possibility of jamming (and we don't
963 * want to build jamming into it because then it
964 * will run more slowly).
965 */
966
967 yy_next_state = yy_try_NUL_trans( yy_current_state );
968
969 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
970
971 if ( yy_next_state )
972 {
973 /* Consume the NUL. */
974 yy_cp = ++(yy_c_buf_p);
975 yy_current_state = yy_next_state;
976 goto yy_match;
977 }
978
979 else
980 {
981 yy_cp = (yy_c_buf_p);
982 goto yy_find_action;
983 }
984 }
985
986 else switch ( yy_get_next_buffer( ) )
987 {
988 case EOB_ACT_END_OF_FILE:
989 {
990 (yy_did_buffer_switch_on_eof) = 0;
991
992 if ( yywrap( ) )
993 {
994 /* Note: because we've taken care in
995 * yy_get_next_buffer() to have set up
996 * yytext, we can now set up
997 * yy_c_buf_p so that if some total
998 * hoser (like flex itself) wants to
999 * call the scanner after we return the
1000 * YY_NULL, it'll still work - another
1001 * YY_NULL will get returned.
1002 */
1003 (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
1004
1005 yy_act = YY_STATE_EOF(YY_START);
1006 goto do_action;
1007 }
1008
1009 else
1010 {
1011 if ( ! (yy_did_buffer_switch_on_eof) )
1012 YY_NEW_FILE;
1013 }
1014 break;
1015 }
1016
1017 case EOB_ACT_CONTINUE_SCAN:
1018 (yy_c_buf_p) =
1019 (yytext_ptr) + yy_amount_of_matched_text;
1020
1021 yy_current_state = yy_get_previous_state( );
1022
1023 yy_cp = (yy_c_buf_p);
1024 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1025 goto yy_match;
1026
1027 case EOB_ACT_LAST_MATCH:
1028 (yy_c_buf_p) =
1029 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
1030
1031 yy_current_state = yy_get_previous_state( );
1032
1033 yy_cp = (yy_c_buf_p);
1034 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1035 goto yy_find_action;
1036 }
1037 break;
1038 }
1039
1040 default:
1041 YY_FATAL_ERROR(
1042 "fatal flex scanner internal error--no action found" );
1043 } /* end of action switch */
1044 } /* end of scanning one token */
1045 } /* end of yylex */
1046
1047 /* yy_get_next_buffer - try to read in a new buffer
1048 *
1049 * Returns a code representing an action:
1050 * EOB_ACT_LAST_MATCH -
1051 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1052 * EOB_ACT_END_OF_FILE - end of file
1053 */
1054 static int yy_get_next_buffer (void)
1055 {
1056 register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1057 register char *source = (yytext_ptr);
1058 register int number_to_move, i;
1059 int ret_val;
1060
1061 if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1062 YY_FATAL_ERROR(
1063 "fatal flex scanner internal error--end of buffer missed" );
1064
1065 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1066 { /* Don't try to fill the buffer, so this is an EOF. */
1067 if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
1068 {
1069 /* We matched a single character, the EOB, so
1070 * treat this as a final EOF.
1071 */
1072 return EOB_ACT_END_OF_FILE;
1073 }
1074
1075 else
1076 {
1077 /* We matched some text prior to the EOB, first
1078 * process it.
1079 */
1080 return EOB_ACT_LAST_MATCH;
1081 }
1082 }
1083
1084 /* Try to read more data. */
1085
1086 /* First move last chars to start of buffer. */
1087 number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
1088
1089 for ( i = 0; i < number_to_move; ++i )
1090 *(dest++) = *(source++);
1091
1092 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1093 /* don't do the read, it's not guaranteed to return an EOF,
1094 * just force an EOF
1095 */
1096 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1097
1098 else
1099 {
1100 yy_size_t num_to_read =
1101 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1102
1103 while ( num_to_read <= 0 )
1104 { /* Not enough room in the buffer - grow it. */
1105
1106 /* just a shorter name for the current buffer */
1107 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1108
1109 int yy_c_buf_p_offset =
1110 (int) ((yy_c_buf_p) - b->yy_ch_buf);
1111
1112 if ( b->yy_is_our_buffer )
1113 {
1114 yy_size_t new_size = b->yy_buf_size * 2;
1115
1116 if ( new_size <= 0 )
1117 b->yy_buf_size += b->yy_buf_size / 8;
1118 else
1119 b->yy_buf_size *= 2;
1120
1121 b->yy_ch_buf = (char *)
1122 /* Include room in for 2 EOB chars. */
1123 yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
1124 }
1125 else
1126 /* Can't grow it, we don't own it. */
1127 b->yy_ch_buf = 0;
1128
1129 if ( ! b->yy_ch_buf )
1130 YY_FATAL_ERROR(
1131 "fatal error - scanner input buffer overflow" );
1132
1133 (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1134
1135 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1136 number_to_move - 1;
1137
1138 }
1139
1140 if ( num_to_read > YY_READ_BUF_SIZE )
1141 num_to_read = YY_READ_BUF_SIZE;
1142
1143 /* Read in more data. */
1144 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1145 (yy_n_chars), num_to_read );
1146
1147 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1148 }
1149
1150 if ( (yy_n_chars) == 0 )
1151 {
1152 if ( number_to_move == YY_MORE_ADJ )
1153 {
1154 ret_val = EOB_ACT_END_OF_FILE;
1155 yyrestart(yyin );
1156 }
1157
1158 else
1159 {
1160 ret_val = EOB_ACT_LAST_MATCH;
1161 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1162 YY_BUFFER_EOF_PENDING;
1163 }
1164 }
1165
1166 else
1167 ret_val = EOB_ACT_CONTINUE_SCAN;
1168
1169 if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1170 /* Extend the array by 50%, plus the number we really need. */
1171 yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1172 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
1173 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1174 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1175 }
1176
1177 (yy_n_chars) += number_to_move;
1178 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1179 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1180
1181 (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1182
1183 return ret_val;
1184 }
1185
1186 /* yy_get_previous_state - get the state just before the EOB char was reached */
1187
1188 static yy_state_type yy_get_previous_state (void)
1189 {
1190 register yy_state_type yy_current_state;
1191 register char *yy_cp;
1192
1193 yy_current_state = (yy_start);
1194
1195 for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1196 {
1197 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1198 if ( yy_accept[yy_current_state] )
1199 {
1200 (yy_last_accepting_state) = yy_current_state;
1201 (yy_last_accepting_cpos) = yy_cp;
1202 }
1203 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1204 {
1205 yy_current_state = (int) yy_def[yy_current_state];
1206 if ( yy_current_state >= 39 )
1207 yy_c = yy_meta[(unsigned int) yy_c];
1208 }
1209 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1210 }
1211
1212 return yy_current_state;
1213 }
1214
1215 /* yy_try_NUL_trans - try to make a transition on the NUL character
1216 *
1217 * synopsis
1218 * next_state = yy_try_NUL_trans( current_state );
1219 */
1220 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
1221 {
1222 register int yy_is_jam;
1223 register char *yy_cp = (yy_c_buf_p);
1224
1225 register YY_CHAR yy_c = 1;
1226 if ( yy_accept[yy_current_state] )
1227 {
1228 (yy_last_accepting_state) = yy_current_state;
1229 (yy_last_accepting_cpos) = yy_cp;
1230 }
1231 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1232 {
1233 yy_current_state = (int) yy_def[yy_current_state];
1234 if ( yy_current_state >= 39 )
1235 yy_c = yy_meta[(unsigned int) yy_c];
1236 }
1237 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1238 yy_is_jam = (yy_current_state == 38);
1239
1240 return yy_is_jam ? 0 : yy_current_state;
1241 }
1242
1243 static void yyunput (int c, register char * yy_bp )
1244 {
1245 register char *yy_cp;
1246
1247 yy_cp = (yy_c_buf_p);
1248
1249 /* undo effects of setting up yytext */
1250 *yy_cp = (yy_hold_char);
1251
1252 if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1253 { /* need to shift things up to make room */
1254 /* +2 for EOB chars. */
1255 register yy_size_t number_to_move = (yy_n_chars) + 2;
1256 register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1257 YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1258 register char *source =
1259 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1260
1261 while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1262 *--dest = *--source;
1263
1264 yy_cp += (int) (dest - source);
1265 yy_bp += (int) (dest - source);
1266 YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
1267 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1268
1269 if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1270 YY_FATAL_ERROR( "flex scanner push-back overflow" );
1271 }
1272
1273 *--yy_cp = (char) c;
1274
1275 (yytext_ptr) = yy_bp;
1276 (yy_hold_char) = *yy_cp;
1277 (yy_c_buf_p) = yy_cp;
1278 }
1279
1280 #ifndef YY_NO_INPUT
1281 #ifdef __cplusplus
1282 static int yyinput (void)
1283 #else
1284 static int input (void)
1285 #endif
1286
1287 {
1288 int c;
1289
1290 *(yy_c_buf_p) = (yy_hold_char);
1291
1292 if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1293 {
1294 /* yy_c_buf_p now points to the character we want to return.
1295 * If this occurs *before* the EOB characters, then it's a
1296 * valid NUL; if not, then we've hit the end of the buffer.
1297 */
1298 if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1299 /* This was really a NUL. */
1300 *(yy_c_buf_p) = '\0';
1301
1302 else
1303 { /* need more input */
1304 yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
1305 ++(yy_c_buf_p);
1306
1307 switch ( yy_get_next_buffer( ) )
1308 {
1309 case EOB_ACT_LAST_MATCH:
1310 /* This happens because yy_g_n_b()
1311 * sees that we've accumulated a
1312 * token and flags that we need to
1313 * try matching the token before
1314 * proceeding. But for input(),
1315 * there's no matching to consider.
1316 * So convert the EOB_ACT_LAST_MATCH
1317 * to EOB_ACT_END_OF_FILE.
1318 */
1319
1320 /* Reset buffer status. */
1321 yyrestart(yyin );
1322
1323 /*FALLTHROUGH*/
1324
1325 case EOB_ACT_END_OF_FILE:
1326 {
1327 if ( yywrap( ) )
1328 return EOF;
1329
1330 if ( ! (yy_did_buffer_switch_on_eof) )
1331 YY_NEW_FILE;
1332 #ifdef __cplusplus
1333 return yyinput();
1334 #else
1335 return input();
1336 #endif
1337 }
1338
1339 case EOB_ACT_CONTINUE_SCAN:
1340 (yy_c_buf_p) = (yytext_ptr) + offset;
1341 break;
1342 }
1343 }
1344 }
1345
1346 c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
1347 *(yy_c_buf_p) = '\0'; /* preserve yytext */
1348 (yy_hold_char) = *++(yy_c_buf_p);
1349
1350 return c;
1351 }
1352 #endif /* ifndef YY_NO_INPUT */
1353
1354 /** Immediately switch to a different input stream.
1355 * @param input_file A readable stream.
1356 *
1357 * @note This function does not reset the start condition to @c INITIAL .
1358 */
1359 void yyrestart (FILE * input_file )
1360 {
1361
1362 if ( ! YY_CURRENT_BUFFER ){
1363 yyensure_buffer_stack ();
1364 YY_CURRENT_BUFFER_LVALUE =
1365 yy_create_buffer(yyin,YY_BUF_SIZE );
1366 }
1367
1368 yy_init_buffer(YY_CURRENT_BUFFER,input_file );
1369 yy_load_buffer_state( );
1370 }
1371
1372 /** Switch to a different input buffer.
1373 * @param new_buffer The new input buffer.
1374 *
1375 */
1376 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
1377 {
1378
1379 /* TODO. We should be able to replace this entire function body
1380 * with
1381 * yypop_buffer_state();
1382 * yypush_buffer_state(new_buffer);
1383 */
1384 yyensure_buffer_stack ();
1385 if ( YY_CURRENT_BUFFER == new_buffer )
1386 return;
1387
1388 if ( YY_CURRENT_BUFFER )
1389 {
1390 /* Flush out information for old buffer. */
1391 *(yy_c_buf_p) = (yy_hold_char);
1392 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1393 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1394 }
1395
1396 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1397 yy_load_buffer_state( );
1398
1399 /* We don't actually know whether we did this switch during
1400 * EOF (yywrap()) processing, but the only time this flag
1401 * is looked at is after yywrap() is called, so it's safe
1402 * to go ahead and always set it.
1403 */
1404 (yy_did_buffer_switch_on_eof) = 1;
1405 }
1406
1407 static void yy_load_buffer_state (void)
1408 {
1409 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1410 (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1411 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1412 (yy_hold_char) = *(yy_c_buf_p);
1413 }
1414
1415 /** Allocate and initialize an input buffer state.
1416 * @param file A readable stream.
1417 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1418 *
1419 * @return the allocated buffer state.
1420 */
1421 YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
1422 {
1423 YY_BUFFER_STATE b;
1424
1425 b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1426 if ( ! b )
1427 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1428
1429 b->yy_buf_size = size;
1430
1431 /* yy_ch_buf has to be 2 characters longer than the size given because
1432 * we need to put in 2 end-of-buffer characters.
1433 */
1434 b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );
1435 if ( ! b->yy_ch_buf )
1436 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1437
1438 b->yy_is_our_buffer = 1;
1439
1440 yy_init_buffer(b,file );
1441
1442 return b;
1443 }
1444
1445 /** Destroy the buffer.
1446 * @param b a buffer created with yy_create_buffer()
1447 *
1448 */
1449 void yy_delete_buffer (YY_BUFFER_STATE b )
1450 {
1451
1452 if ( ! b )
1453 return;
1454
1455 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1456 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1457
1458 if ( b->yy_is_our_buffer )
1459 yyfree((void *) b->yy_ch_buf );
1460
1461 yyfree((void *) b );
1462 }
1463
1464 /* Initializes or reinitializes a buffer.
1465 * This function is sometimes called more than once on the same buffer,
1466 * such as during a yyrestart() or at EOF.
1467 */
1468 static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
1469
1470 {
1471 int oerrno = errno;
1472
1473 yy_flush_buffer(b );
1474
1475 b->yy_input_file = file;
1476 b->yy_fill_buffer = 1;
1477
1478 /* If b is the current buffer, then yy_init_buffer was _probably_
1479 * called from yyrestart() or through yy_get_next_buffer.
1480 * In that case, we don't want to reset the lineno or column.
1481 */
1482 if (b != YY_CURRENT_BUFFER){
1483 b->yy_bs_lineno = 1;
1484 b->yy_bs_column = 0;
1485 }
1486
1487 b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1488
1489 errno = oerrno;
1490 }
1491
1492 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1493 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1494 *
1495 */
1496 void yy_flush_buffer (YY_BUFFER_STATE b )
1497 {
1498 if ( ! b )
1499 return;
1500
1501 b->yy_n_chars = 0;
1502
1503 /* We always need two end-of-buffer characters. The first causes
1504 * a transition to the end-of-buffer state. The second causes
1505 * a jam in that state.
1506 */
1507 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1508 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1509
1510 b->yy_buf_pos = &b->yy_ch_buf[0];
1511
1512 b->yy_at_bol = 1;
1513 b->yy_buffer_status = YY_BUFFER_NEW;
1514
1515 if ( b == YY_CURRENT_BUFFER )
1516 yy_load_buffer_state( );
1517 }
1518
1519 /** Pushes the new state onto the stack. The new state becomes
1520 * the current state. This function will allocate the stack
1521 * if necessary.
1522 * @param new_buffer The new state.
1523 *
1524 */
1525 void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
1526 {
1527 if (new_buffer == NULL)
1528 return;
1529
1530 yyensure_buffer_stack();
1531
1532 /* This block is copied from yy_switch_to_buffer. */
1533 if ( YY_CURRENT_BUFFER )
1534 {
1535 /* Flush out information for old buffer. */
1536 *(yy_c_buf_p) = (yy_hold_char);
1537 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1538 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1539 }
1540
1541 /* Only push if top exists. Otherwise, replace top. */
1542 if (YY_CURRENT_BUFFER)
1543 (yy_buffer_stack_top)++;
1544 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1545
1546 /* copied from yy_switch_to_buffer. */
1547 yy_load_buffer_state( );
1548 (yy_did_buffer_switch_on_eof) = 1;
1549 }
1550
1551 /** Removes and deletes the top of the stack, if present.
1552 * The next element becomes the new top.
1553 *
1554 */
1555 void yypop_buffer_state (void)
1556 {
1557 if (!YY_CURRENT_BUFFER)
1558 return;
1559
1560 yy_delete_buffer(YY_CURRENT_BUFFER );
1561 YY_CURRENT_BUFFER_LVALUE = NULL;
1562 if ((yy_buffer_stack_top) > 0)
1563 --(yy_buffer_stack_top);
1564
1565 if (YY_CURRENT_BUFFER) {
1566 yy_load_buffer_state( );
1567 (yy_did_buffer_switch_on_eof) = 1;
1568 }
1569 }
1570
1571 /* Allocates the stack if it does not exist.
1572 * Guarantees space for at least one push.
1573 */
1574 static void yyensure_buffer_stack (void)
1575 {
1576 yy_size_t num_to_alloc;
1577
1578 if (!(yy_buffer_stack)) {
1579
1580 /* First allocation is just for 2 elements, since we don't know if this
1581 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1582 * immediate realloc on the next call.
1583 */
1584 num_to_alloc = 1;
1585 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1586 (num_to_alloc * sizeof(struct yy_buffer_state*)
1587 );
1588 if ( ! (yy_buffer_stack) )
1589 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1590
1591 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1592
1593 (yy_buffer_stack_max) = num_to_alloc;
1594 (yy_buffer_stack_top) = 0;
1595 return;
1596 }
1597
1598 if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1599
1600 /* Increase the buffer to prepare for a possible push. */
1601 int grow_size = 8 /* arbitrary grow size */;
1602
1603 num_to_alloc = (yy_buffer_stack_max) + grow_size;
1604 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1605 ((yy_buffer_stack),
1606 num_to_alloc * sizeof(struct yy_buffer_state*)
1607 );
1608 if ( ! (yy_buffer_stack) )
1609 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1610
1611 /* zero only the new slots.*/
1612 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1613 (yy_buffer_stack_max) = num_to_alloc;
1614 }
1615 }
1616
1617 /** Setup the input buffer state to scan directly from a user-specified character buffer.
1618 * @param base the character buffer
1619 * @param size the size in bytes of the character buffer
1620 *
1621 * @return the newly allocated buffer state object.
1622 */
1623 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
1624 {
1625 YY_BUFFER_STATE b;
1626
1627 if ( size < 2 ||
1628 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1629 base[size-1] != YY_END_OF_BUFFER_CHAR )
1630 /* They forgot to leave room for the EOB's. */
1631 return 0;
1632
1633 b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1634 if ( ! b )
1635 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1636
1637 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1638 b->yy_buf_pos = b->yy_ch_buf = base;
1639 b->yy_is_our_buffer = 0;
1640 b->yy_input_file = 0;
1641 b->yy_n_chars = b->yy_buf_size;
1642 b->yy_is_interactive = 0;
1643 b->yy_at_bol = 1;
1644 b->yy_fill_buffer = 0;
1645 b->yy_buffer_status = YY_BUFFER_NEW;
1646
1647 yy_switch_to_buffer(b );
1648
1649 return b;
1650 }
1651
1652 /** Setup the input buffer state to scan a string. The next call to yylex() will
1653 * scan from a @e copy of @a str.
1654 * @param yystr a NUL-terminated string to scan
1655 *
1656 * @return the newly allocated buffer state object.
1657 * @note If you want to scan bytes that may contain NUL values, then use
1658 * yy_scan_bytes() instead.
1659 */
1660 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1661 {
1662
1663 return yy_scan_bytes(yystr,strlen(yystr) );
1664 }
1665
1666 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1667 * scan from a @e copy of @a bytes.
1668 * @param yybytes the byte buffer to scan
1669 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
1670 *
1671 * @return the newly allocated buffer state object.
1672 */
1673 YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
1674 {
1675 YY_BUFFER_STATE b;
1676 char *buf;
1677 yy_size_t n;
1678 int i;
1679
1680 /* Get memory for full buffer, including space for trailing EOB's. */
1681 n = _yybytes_len + 2;
1682 buf = (char *) yyalloc(n );
1683 if ( ! buf )
1684 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1685
1686 for ( i = 0; i < _yybytes_len; ++i )
1687 buf[i] = yybytes[i];
1688
1689 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
1690
1691 b = yy_scan_buffer(buf,n );
1692 if ( ! b )
1693 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
1694
1695 /* It's okay to grow etc. this buffer, and we should throw it
1696 * away when we're done.
1697 */
1698 b->yy_is_our_buffer = 1;
1699
1700 return b;
1701 }
1702
1703 #ifndef YY_EXIT_FAILURE
1704 #define YY_EXIT_FAILURE 2
1705 #endif
1706
1707 static void yy_fatal_error (yyconst char* msg )
1708 {
1709 (void) fprintf( stderr, "%s\n", msg );
1710 exit( YY_EXIT_FAILURE );
1711 }
1712
1713 /* Redefine yyless() so it works in section 3 code. */
1714
1715 #undef yyless
1716 #define yyless(n) \
1717 do \
1718 { \
1719 /* Undo effects of setting up yytext. */ \
1720 int yyless_macro_arg = (n); \
1721 YY_LESS_LINENO(yyless_macro_arg);\
1722 yytext[yyleng] = (yy_hold_char); \
1723 (yy_c_buf_p) = yytext + yyless_macro_arg; \
1724 (yy_hold_char) = *(yy_c_buf_p); \
1725 *(yy_c_buf_p) = '\0'; \
1726 yyleng = yyless_macro_arg; \
1727 } \
1728 while ( 0 )
1729
1730 /* Accessor methods (get/set functions) to struct members. */
1731
1732 /** Get the current line number.
1733 *
1734 */
1735 int yyget_lineno (void)
1736 {
1737
1738 return yylineno;
1739 }
1740
1741 /** Get the input stream.
1742 *
1743 */
1744 FILE *yyget_in (void)
1745 {
1746 return yyin;
1747 }
1748
1749 /** Get the output stream.
1750 *
1751 */
1752 FILE *yyget_out (void)
1753 {
1754 return yyout;
1755 }
1756
1757 /** Get the length of the current token.
1758 *
1759 */
1760 yy_size_t yyget_leng (void)
1761 {
1762 return yyleng;
1763 }
1764
1765 /** Get the current token.
1766 *
1767 */
1768
1769 char *yyget_text (void)
1770 {
1771 return yytext;
1772 }
1773
1774 /** Set the current line number.
1775 * @param line_number
1776 *
1777 */
1778 void yyset_lineno (int line_number )
1779 {
1780
1781 yylineno = line_number;
1782 }
1783
1784 /** Set the input stream. This does not discard the current
1785 * input buffer.
1786 * @param in_str A readable stream.
1787 *
1788 * @see yy_switch_to_buffer
1789 */
1790 void yyset_in (FILE * in_str )
1791 {
1792 yyin = in_str ;
1793 }
1794
1795 void yyset_out (FILE * out_str )
1796 {
1797 yyout = out_str ;
1798 }
1799
1800 int yyget_debug (void)
1801 {
1802 return yy_flex_debug;
1803 }
1804
1805 void yyset_debug (int bdebug )
1806 {
1807 yy_flex_debug = bdebug ;
1808 }
1809
1810 static int yy_init_globals (void)
1811 {
1812 /* Initialization is the same as for the non-reentrant scanner.
1813 * This function is called from yylex_destroy(), so don't allocate here.
1814 */
1815
1816 (yy_buffer_stack) = 0;
1817 (yy_buffer_stack_top) = 0;
1818 (yy_buffer_stack_max) = 0;
1819 (yy_c_buf_p) = (char *) 0;
1820 (yy_init) = 0;
1821 (yy_start) = 0;
1822
1823 /* Defined in main.c */
1824 #ifdef YY_STDINIT
1825 yyin = stdin;
1826 yyout = stdout;
1827 #else
1828 yyin = (FILE *) 0;
1829 yyout = (FILE *) 0;
1830 #endif
1831
1832 /* For future reference: Set errno on error, since we are called by
1833 * yylex_init()
1834 */
1835 return 0;
1836 }
1837
1838 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
1839 int yylex_destroy (void)
1840 {
1841
1842 /* Pop the buffer stack, destroying each element. */
1843 while(YY_CURRENT_BUFFER){
1844 yy_delete_buffer(YY_CURRENT_BUFFER );
1845 YY_CURRENT_BUFFER_LVALUE = NULL;
1846 yypop_buffer_state();
1847 }
1848
1849 /* Destroy the stack itself. */
1850 yyfree((yy_buffer_stack) );
1851 (yy_buffer_stack) = NULL;
1852
1853 /* Reset the globals. This is important in a non-reentrant scanner so the next time
1854 * yylex() is called, initialization will occur. */
1855 yy_init_globals( );
1856
1857 return 0;
1858 }
1859
1860 /*
1861 * Internal utility routines.
1862 */
1863
1864 #ifndef yytext_ptr
1865 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1866 {
1867 register int i;
1868 for ( i = 0; i < n; ++i )
1869 s1[i] = s2[i];
1870 }
1871 #endif
1872
1873 #ifdef YY_NEED_STRLEN
1874 static int yy_flex_strlen (yyconst char * s )
1875 {
1876 register int n;
1877 for ( n = 0; s[n]; ++n )
1878 ;
1879
1880 return n;
1881 }
1882 #endif
1883
1884 void *yyalloc (yy_size_t size )
1885 {
1886 return (void *) malloc( size );
1887 }
1888
1889 void *yyrealloc (void * ptr, yy_size_t size )
1890 {
1891 /* The cast to (char *) in the following accommodates both
1892 * implementations that use char* generic pointers, and those
1893 * that use void* generic pointers. It works with the latter
1894 * because both ANSI C and C++ allow castless assignment from
1895 * any pointer type to void*, and deal with argument conversions
1896 * as though doing an assignment.
1897 */
1898 return (void *) realloc( (char *) ptr, size );
1899 }
1900
1901 void yyfree (void * ptr )
1902 {
1903 free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
1904 }
1905
1906 #define YYTABLES_NAME "yytables"
1907
1908 #line 107 "calclex.l"
1909
1910
1911
1912 int
1913 yywrap ()
1914 {
1915 return 1;
1916 }
1917
1918