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