5 #define YY_INT_ALIGNED short int
7 /* A lexical scanner generated by flex */
10 #define YY_FLEX_MAJOR_VERSION 2
11 #define YY_FLEX_MINOR_VERSION 5
12 #define YY_FLEX_SUBMINOR_VERSION 35
13 #if YY_FLEX_SUBMINOR_VERSION > 0
17 /* First, we deal with platform-specific or compiler-specific issues. */
19 /* begin standard C headers. */
25 /* end standard C headers. */
27 /* flex integer type definitions */
32 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
34 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
36 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
37 * if you want the limit (max/min) macros for int types.
39 #ifndef __STDC_LIMIT_MACROS
40 #define __STDC_LIMIT_MACROS 1
44 typedef int8_t flex_int8_t;
45 typedef uint8_t flex_uint8_t;
46 typedef int16_t flex_int16_t;
47 typedef uint16_t flex_uint16_t;
48 typedef int32_t flex_int32_t;
49 typedef uint32_t flex_uint32_t;
51 typedef signed char flex_int8_t;
52 typedef short int flex_int16_t;
53 typedef int flex_int32_t;
54 typedef unsigned char flex_uint8_t;
55 typedef unsigned short int flex_uint16_t;
56 typedef unsigned int flex_uint32_t;
59 /* Limits of integral types. */
61 #define INT8_MIN (-128)
64 #define INT16_MIN (-32767-1)
67 #define INT32_MIN (-2147483647-1)
70 #define INT8_MAX (127)
73 #define INT16_MAX (32767)
76 #define INT32_MAX (2147483647)
79 #define UINT8_MAX (255U)
82 #define UINT16_MAX (65535U)
85 #define UINT32_MAX (4294967295U)
88 #endif /* ! FLEXINT_H */
92 /* The "const" storage-class-modifier is valid. */
95 #else /* ! __cplusplus */
97 /* C99 requires __STDC__ to be defined as 1. */
98 #if defined (__STDC__)
102 #endif /* defined (__STDC__) */
103 #endif /* ! __cplusplus */
106 #define yyconst const
111 /* Returned upon end-of-file. */
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
119 #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
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.
125 #define BEGIN (yy_start) = 1 + 2 *
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
131 #define YY_START (((yy_start) - 1) / 2)
132 #define YYSTATE YY_START
134 /* Action number for EOF rule of a given start state. */
135 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
137 /* Special action meaning "start processing a new file". */
138 #define YY_NEW_FILE yyrestart(yyin )
140 #define YY_END_OF_BUFFER_CHAR 0
142 /* Size of default input buffer. */
144 #define YY_BUF_SIZE 16384
147 /* The state buf must be large enough to hold one state per character in the main buffer.
149 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
151 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
152 #define YY_TYPEDEF_YY_BUFFER_STATE
153 typedef struct yy_buffer_state *YY_BUFFER_STATE;
158 extern FILE *yyin, *yyout;
160 #define EOB_ACT_CONTINUE_SCAN 0
161 #define EOB_ACT_END_OF_FILE 1
162 #define EOB_ACT_LAST_MATCH 2
164 #define YY_LESS_LINENO(n)
166 /* Return all but the first "n" matched characters back to the input stream. */
170 /* Undo effects of setting up yytext. */ \
171 int yyless_macro_arg = (n); \
172 YY_LESS_LINENO(yyless_macro_arg);\
173 *yy_cp = (yy_hold_char); \
174 YY_RESTORE_YY_MORE_OFFSET \
175 (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
176 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
180 #define unput(c) yyunput( c, (yytext_ptr) )
182 #ifndef YY_TYPEDEF_YY_SIZE_T
183 #define YY_TYPEDEF_YY_SIZE_T
184 typedef size_t yy_size_t;
187 #ifndef YY_STRUCT_YY_BUFFER_STATE
188 #define YY_STRUCT_YY_BUFFER_STATE
189 struct yy_buffer_state
193 char *yy_ch_buf; /* input buffer */
194 char *yy_buf_pos; /* current position in input buffer */
196 /* Size of input buffer in bytes, not including room for EOB
199 yy_size_t yy_buf_size;
201 /* Number of characters read into yy_ch_buf, not including EOB
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
210 int yy_is_our_buffer;
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
217 int yy_is_interactive;
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
225 int yy_bs_lineno; /**< The line count. */
226 int yy_bs_column; /**< The column count. */
228 /* Whether to try to fill the input buffer when we reach the
233 int yy_buffer_status;
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.
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.
247 #define YY_BUFFER_EOF_PENDING 2
250 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
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. */
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
261 * Returns the top of the stack, or NULL.
263 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
264 ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
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.
270 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
272 /* yy_hold_char holds the character lost when yytext is formed. */
273 static char yy_hold_char;
274 static int yy_n_chars; /* number of characters read into yy_ch_buf */
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 */
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 ...
285 static int yy_did_buffer_switch_on_eof;
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 );
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 );
299 #define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )
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,int len );
305 void *yyalloc (yy_size_t );
306 void *yyrealloc (void *,yy_size_t );
307 void yyfree (void * );
309 #define yy_new_buffer yy_create_buffer
311 #define yy_set_interactive(is_interactive) \
313 if ( ! YY_CURRENT_BUFFER ){ \
314 yyensure_buffer_stack (); \
315 YY_CURRENT_BUFFER_LVALUE = \
316 yy_create_buffer(yyin,YY_BUF_SIZE ); \
318 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
321 #define yy_set_bol(at_bol) \
323 if ( ! YY_CURRENT_BUFFER ){\
324 yyensure_buffer_stack (); \
325 YY_CURRENT_BUFFER_LVALUE = \
326 yy_create_buffer(yyin,YY_BUF_SIZE ); \
328 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
331 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
333 /* Begin user sect3 */
335 typedef unsigned char YY_CHAR;
337 FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
339 typedef int yy_state_type;
346 #define yytext_ptr yytext
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[] );
353 /* Done after the current pattern has been matched and before the
354 * corresponding action - sets up yytext.
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; \
361 (yy_c_buf_p) = yy_cp;
363 #define YY_NUM_RULES 21
364 #define YY_END_OF_BUFFER 22
365 /* This struct is not used in this scanner,
366 but its presence is necessary. */
369 flex_int32_t yy_verify;
372 static yyconst flex_int16_t yy_accept[111] =
374 0, 0, 13, 13, 0, 0, 22, 20, 19, 19,
375 20, 20, 17, 17, 20, 20, 18, 20, 13, 13,
376 13, 13, 13, 13, 13, 13, 2, 3, 1, 0,
377 0, 9, 8, 0, 0, 0, 0, 0, 15, 17,
378 12, 15, 4, 0, 0, 0, 0, 0, 6, 13,
379 13, 8, 13, 13, 13, 13, 13, 13, 12, 13,
380 13, 13, 0, 7, 0, 10, 0, 11, 0, 15,
381 15, 0, 0, 10, 13, 11, 13, 13, 13, 13,
382 0, 15, 0, 0, 0, 13, 13, 13, 13, 15,
383 5, 16, 13, 15, 13, 15, 13, 15, 13, 0,
385 0, 0, 14, 0, 0, 12, 14, 10, 11, 0
388 static yyconst flex_int32_t yy_ec[256] =
390 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
391 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
392 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
393 1, 2, 1, 4, 5, 1, 1, 1, 1, 1,
394 1, 1, 6, 1, 7, 8, 9, 10, 11, 11,
395 11, 11, 10, 11, 11, 11, 11, 12, 1, 1,
396 13, 1, 1, 1, 9, 9, 9, 9, 9, 9,
397 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
398 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
399 14, 15, 16, 1, 9, 1, 9, 9, 17, 18,
401 19, 9, 9, 9, 20, 9, 9, 21, 9, 22,
402 9, 9, 9, 9, 9, 9, 23, 9, 9, 9,
403 9, 9, 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, 1, 1, 1, 1, 1,
409 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
410 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
412 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
414 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
415 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
416 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
420 static yyconst flex_int32_t yy_meta[24] =
422 1, 2, 2, 1, 1, 3, 3, 3, 3, 3,
423 3, 4, 3, 1, 1, 1, 3, 3, 3, 3,
427 static yyconst flex_int16_t yy_base[122] =
429 0, 230, 23, 229, 44, 45, 233, 395, 227, 395,
430 47, 42, 61, 83, 95, 85, 395, 228, 0, 105,
431 44, 120, 136, 158, 0, 54, 395, 395, 395, 227,
432 96, 395, 395, 225, 0, 168, 214, 180, 192, 204,
433 395, 216, 395, 237, 110, 144, 207, 222, 395, 0,
434 247, 0, 89, 0, 211, 261, 274, 0, 0, 199,
435 65, 92, 217, 395, 203, 395, 202, 395, 296, 192,
436 93, 48, 191, 0, 199, 0, 308, 0, 191, 140,
437 191, 141, 193, 162, 184, 187, 159, 168, 320, 150,
438 395, 182, 126, 170, 114, 97, 95, 187, 194, 330,
440 99, 342, 0, 164, 188, 74, 395, 62, 46, 395,
441 355, 359, 362, 365, 369, 373, 376, 380, 384, 387,
445 static yyconst flex_int16_t yy_def[122] =
447 110, 1, 110, 3, 111, 111, 110, 110, 110, 110,
448 112, 110, 110, 113, 110, 114, 110, 115, 116, 117,
449 116, 110, 22, 116, 116, 118, 110, 110, 110, 119,
450 112, 110, 110, 112, 15, 110, 110, 113, 120, 113,
451 110, 120, 110, 110, 114, 114, 114, 115, 110, 116,
452 117, 116, 117, 24, 116, 23, 110, 23, 116, 57,
453 24, 118, 119, 110, 110, 110, 38, 110, 120, 42,
454 42, 44, 114, 116, 56, 116, 57, 57, 57, 24,
455 69, 42, 72, 83, 114, 77, 57, 24, 116, 42,
456 110, 114, 57, 42, 57, 42, 57, 42, 57, 121,
458 121, 121, 36, 121, 121, 121, 110, 121, 121, 0,
459 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
463 static yyconst flex_int16_t yy_nxt[419] =
465 8, 9, 10, 11, 8, 8, 12, 13, 14, 15,
466 15, 16, 8, 17, 8, 8, 14, 14, 14, 14,
467 14, 14, 14, 19, 9, 10, 20, 19, 19, 21,
468 22, 23, 24, 24, 16, 19, 25, 19, 19, 23,
469 23, 23, 23, 23, 23, 23, 28, 28, 107, 32,
470 33, 35, 35, 54, 54, 48, 49, 83, 84, 29,
471 29, 34, 36, 36, 107, 48, 37, 38, 39, 39,
472 40, 40, 50, 41, 80, 80, 107, 39, 39, 39,
473 42, 39, 39, 39, 36, 36, 46, 46, 37, 38,
474 31, 110, 47, 48, 49, 41, 43, 43, 32, 33,
476 31, 107, 44, 48, 35, 35, 31, 32, 52, 82,
477 34, 46, 46, 99, 70, 98, 31, 47, 70, 53,
478 50, 36, 36, 50, 50, 55, 56, 57, 57, 58,
479 58, 97, 59, 50, 50, 50, 57, 57, 57, 60,
480 57, 57, 57, 58, 58, 46, 46, 50, 95, 88,
481 89, 47, 58, 58, 58, 58, 58, 58, 58, 43,
482 43, 90, 70, 91, 91, 61, 107, 54, 54, 36,
483 36, 70, 94, 37, 65, 50, 108, 89, 89, 93,
484 41, 110, 110, 110, 110, 110, 67, 96, 100, 100,
485 107, 70, 68, 36, 36, 100, 100, 37, 69, 50,
487 109, 92, 84, 110, 41, 36, 36, 87, 70, 37,
488 38, 50, 85, 70, 110, 68, 41, 36, 36, 64,
489 79, 37, 69, 74, 49, 73, 66, 110, 41, 64,
490 49, 30, 110, 26, 18, 110, 110, 71, 43, 43,
491 110, 110, 110, 110, 110, 110, 72, 72, 31, 32,
492 52, 110, 110, 110, 110, 110, 110, 110, 31, 110,
493 110, 53, 110, 110, 110, 110, 50, 75, 110, 110,
494 110, 110, 110, 76, 50, 36, 36, 50, 50, 55,
495 77, 78, 78, 78, 78, 110, 59, 50, 50, 50,
496 78, 78, 78, 78, 78, 78, 78, 110, 110, 110,
498 110, 110, 81, 110, 110, 110, 110, 110, 68, 110,
499 110, 110, 110, 50, 86, 110, 110, 110, 110, 110,
500 76, 91, 91, 110, 110, 110, 110, 110, 110, 89,
501 89, 102, 103, 110, 110, 104, 105, 110, 110, 110,
502 110, 110, 106, 102, 103, 110, 110, 104, 105, 110,
503 110, 110, 110, 110, 106, 27, 27, 27, 27, 31,
504 31, 31, 31, 40, 40, 45, 45, 45, 45, 48,
505 48, 48, 48, 50, 110, 50, 51, 51, 51, 51,
506 62, 62, 62, 62, 63, 63, 63, 63, 70, 70,
507 101, 101, 101, 101, 7, 110, 110, 110, 110, 110,
509 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
510 110, 110, 110, 110, 110, 110, 110, 110
513 static yyconst flex_int16_t yy_chk[419] =
515 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
516 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
517 1, 1, 1, 3, 3, 3, 3, 3, 3, 3,
518 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
519 3, 3, 3, 3, 3, 3, 5, 6, 109, 11,
520 11, 12, 12, 21, 21, 26, 26, 72, 72, 5,
521 6, 11, 13, 13, 108, 26, 13, 13, 13, 13,
522 13, 13, 61, 13, 61, 61, 106, 13, 13, 13,
523 13, 13, 13, 13, 14, 14, 16, 16, 14, 14,
524 53, 53, 16, 62, 62, 14, 15, 15, 31, 31,
526 53, 101, 15, 62, 15, 15, 20, 20, 20, 71,
527 31, 45, 45, 97, 71, 96, 20, 45, 96, 20,
528 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
529 22, 95, 22, 22, 22, 22, 22, 22, 22, 22,
530 22, 22, 22, 23, 23, 46, 46, 80, 93, 80,
531 80, 46, 23, 23, 23, 23, 23, 23, 23, 24,
532 24, 82, 82, 84, 84, 24, 104, 24, 24, 36,
533 36, 90, 90, 36, 36, 88, 104, 88, 88, 87,
534 36, 38, 38, 92, 92, 38, 38, 94, 98, 98,
535 105, 94, 38, 39, 39, 99, 99, 39, 39, 86,
537 105, 85, 83, 81, 39, 40, 40, 79, 98, 40,
538 40, 75, 73, 70, 67, 65, 40, 42, 42, 63,
539 60, 42, 42, 55, 48, 47, 37, 34, 42, 30,
540 18, 9, 7, 4, 2, 0, 0, 42, 44, 44,
541 0, 0, 0, 0, 0, 0, 44, 44, 51, 51,
542 51, 0, 0, 0, 0, 0, 0, 0, 51, 0,
543 0, 51, 56, 56, 0, 0, 56, 56, 0, 0,
544 0, 0, 0, 56, 57, 57, 57, 57, 57, 57,
545 57, 57, 57, 57, 57, 0, 57, 57, 57, 57,
546 57, 57, 57, 57, 57, 57, 57, 69, 69, 0,
548 0, 69, 69, 0, 0, 0, 0, 0, 69, 77,
549 77, 0, 0, 77, 77, 0, 0, 0, 0, 0,
550 77, 89, 89, 0, 0, 0, 0, 0, 0, 89,
551 89, 100, 100, 0, 0, 100, 100, 0, 0, 0,
552 0, 0, 100, 102, 102, 0, 0, 102, 102, 0,
553 0, 0, 0, 0, 102, 111, 111, 111, 111, 112,
554 112, 112, 112, 113, 113, 114, 114, 114, 114, 115,
555 115, 115, 115, 116, 0, 116, 117, 117, 117, 117,
556 118, 118, 118, 118, 119, 119, 119, 119, 120, 120,
557 121, 121, 121, 121, 110, 110, 110, 110, 110, 110,
559 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
560 110, 110, 110, 110, 110, 110, 110, 110
563 static yy_state_type yy_last_accepting_state;
564 static char *yy_last_accepting_cpos;
566 extern int yy_flex_debug;
567 int yy_flex_debug = 0;
569 /* The intent behind this definition is that it'll catch
570 * any uses of REJECT which flex missed.
572 #define REJECT reject_used_but_not_detected
573 #define yymore() yymore_used_but_not_detected
574 #define YY_MORE_ADJ 0
575 #define YY_RESTORE_YY_MORE_OFFSET
583 #include "../lib/q.h"
585 #include "../lib/utf8.h"
587 //RVALUE {NUMBER}|{PERCENT}|{NAME}|\"{STRING}\"|{DIM}
588 //<a>. {printf("<a>%s\n", yytext);}
589 // %x: exclusive, %s: inclusive
590 char*type_names[] = {"twip","number","command","string","assignment","identifier","label","end"};
597 static void count(char*text, int len, int condition)
610 static char*prefix = 0;
612 static void unescapeString(string_t * tmp)
615 /* fixme - this routine expects the string to be
618 for (p1=(char*)tmp->str; (p=strchr(p1, '\\')); p1 = p+1)
624 case '\\': p[0] = '\\'; break;
625 case '"': p[0] = '"'; break;
626 case 'b': p[0] = '\b'; break;
627 case 'f': p[0] = '\f'; break;
628 case 'n': p[0] = '\n'; break;
629 case 'r': p[0] = '\r'; break;
630 case 't': p[0] = '\t'; break;
631 case 'x': case 'u': {
639 bracket = 1;nr++;max++;
641 while(strchr("0123456789abcdefABCDEF", p[nr]) && (bracket || nr < max)) {
643 if(p[nr]>='0' && p[nr]<='9') num |= p[nr] - '0';
644 if(p[nr]>='a' && p[nr]<='f') num |= p[nr] - 'a' + 10;
645 if(p[nr]>='A' && p[nr]<='F') num |= p[nr] - 'A' + 10;
648 if(bracket && p[nr]=='}') {
654 memcpy(p, utf8, new); // do not copy the terminating zero
660 tmp->len -= (nr-new);
663 char*to=p+new,*from=p+nr;
673 static void store(enum type_t type, int line, int column, char*text, int length)
675 struct token_t token;
679 token.column = column;
680 //printf("->%d(%s) %s\n", type, type_names[type], text);fflush(stdout);
685 string_set2(&tmp, "", 0);
686 token.text = (char*)mem_putstring(&strings, tmp);
689 string_set2(&tmp, text+1, length-2);
690 unescapeString(&tmp);
691 token.text = (char*)mem_putstring(&strings, tmp);
696 string_set2(&tmp, text, length);
699 token.text = (char*)mem_put(&strings, prefix, strlen(prefix));
700 mem_putstring(&strings, tmp);
702 token.text = (char*)mem_putstring(&strings, tmp);
707 string_set2(&tmp, text+1/*:*/, length-5/*.end*/);
708 token.text = (char*)mem_putstring(&strings, tmp);
711 string_set2(&tmp, text+1, length-1);
712 token.text = (char*)mem_putstring(&strings, tmp);
715 char*x = &text[length-1];
716 if(x[-1] == '-' || x[-1] == '+')
718 do{x--;} while(*x==32 || *x==10 || *x==13 || *x=='\t');
720 string_set2(&tmp, text, x-text);
721 token.text = (char*)mem_putstring(&strings, tmp);
722 /*char*y,*x = strchr(text, '=');
725 do{y--;} while(*y==32 || *y==10 || *y==13 || *y=='\t');
726 do{x++;} while(*x==32 || *x==10 || *x==13 || *x=='\t');
727 token.text1 = (char*)put(&strings, text, y-text + 1, 1);
728 token.text2 = (char*)put(&strings, x, length-(x-text), 1);*/
732 mem_put(&tokens, &token, sizeof(struct token_t));
736 #define MAX_INCLUDE_DEPTH 16
737 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
738 static int line_stack[MAX_INCLUDE_DEPTH];
739 static int column_stack[MAX_INCLUDE_DEPTH];
740 static int include_stack_ptr = 0;
742 static void handleInclude(char*text, int len)
745 while(len >=1 && (text[0] == ' ' || text[0] == '\t')) {
749 (text[len-1] == ' ' ||
750 text[len-1] == '\r' ||
751 text[len-1] == '\n')) {
754 if(len >= 2 && text[0] == '"' && text[len-1] == '"') {
758 if(include_stack_ptr >= MAX_INCLUDE_DEPTH) {
759 fprintf( stderr, "Includes nested too deeply" );
762 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
763 line_stack[include_stack_ptr] = line;
764 column_stack[include_stack_ptr] = column;
766 yyin = fopen(text, "rb");
768 fprintf(stderr, "Couldn't open %s\n", text);
771 yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE ) );
781 #define c() {count(yytext, yyleng, YY_START);}
782 #define s(type) {store(type, line, column, yytext, yyleng);}
785 #line 786 "parser.yy.c"
791 #ifndef YY_NO_UNISTD_H
792 /* Special case for "unistd.h", since it is non-ANSI. We include it way
793 * down here because we want the user's section 1 to have been scanned first.
794 * The user has a chance to override it with an option.
799 #ifndef YY_EXTRA_TYPE
800 #define YY_EXTRA_TYPE void *
803 static int yy_init_globals (void );
805 /* Accessor methods to globals.
806 These are made visible to non-reentrant scanners for convenience. */
808 int yylex_destroy (void );
810 int yyget_debug (void );
812 void yyset_debug (int debug_flag );
814 YY_EXTRA_TYPE yyget_extra (void );
816 void yyset_extra (YY_EXTRA_TYPE user_defined );
818 FILE *yyget_in (void );
820 void yyset_in (FILE * in_str );
822 FILE *yyget_out (void );
824 void yyset_out (FILE * out_str );
826 int yyget_leng (void );
828 char *yyget_text (void );
830 int yyget_lineno (void );
832 void yyset_lineno (int line_number );
834 /* Macros after this point can all be overridden by user definitions in
838 #ifndef YY_SKIP_YYWRAP
840 extern "C" int yywrap (void );
842 extern int yywrap (void );
846 static void yyunput (int c,char *buf_ptr );
849 static void yy_flex_strncpy (char *,yyconst char *,int );
852 #ifdef YY_NEED_STRLEN
853 static int yy_flex_strlen (yyconst char * );
859 static int yyinput (void );
861 static int input (void );
866 /* Amount of stuff to slurp up with each read. */
867 #ifndef YY_READ_BUF_SIZE
868 #define YY_READ_BUF_SIZE 8192
871 /* Copy whatever the last rule matched to the standard output. */
873 /* This used to be an fputs(), but since the string might contain NUL's,
874 * we now use fwrite().
876 #define ECHO fwrite( yytext, yyleng, 1, yyout )
879 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
880 * is returned in "result".
883 #define YY_INPUT(buf,result,max_size) \
884 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
888 for ( n = 0; n < max_size && \
889 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
892 buf[n++] = (char) c; \
893 if ( c == EOF && ferror( yyin ) ) \
894 YY_FATAL_ERROR( "input in flex scanner failed" ); \
900 while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
902 if( errno != EINTR) \
904 YY_FATAL_ERROR( "input in flex scanner failed" ); \
915 /* No semi-colon after return; correct usage is to write "yyterminate();" -
916 * we don't want an extra ';' after the "return" because that will cause
917 * some compilers to complain about unreachable statements.
920 #define yyterminate() return YY_NULL
923 /* Number of entries by which start-condition stack grows. */
924 #ifndef YY_START_STACK_INCR
925 #define YY_START_STACK_INCR 25
928 /* Report a fatal error. */
929 #ifndef YY_FATAL_ERROR
930 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
933 /* end tables serialization structures and prototypes */
935 /* Default declaration of generated scanner - a define so the user can
936 * easily add parameters.
939 #define YY_DECL_IS_OURS 1
941 extern int yylex (void);
943 #define YY_DECL int yylex (void)
944 #endif /* !YY_DECL */
946 /* Code executed at the beginning of each rule, after yytext and yyleng
949 #ifndef YY_USER_ACTION
950 #define YY_USER_ACTION
953 /* Code executed at the end of each rule. */
955 #define YY_BREAK break;
958 #define YY_RULE_SETUP \
960 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
961 (yytext[yyleng - 1] == '\n'); \
964 /** The main scanner function which does all the work.
968 register yy_state_type yy_current_state;
969 register char *yy_cp, *yy_bp;
972 #line 219 "parser.lex"
975 #line 976 "parser.yy.c"
986 (yy_start) = 1; /* first start state */
994 if ( ! YY_CURRENT_BUFFER ) {
995 yyensure_buffer_stack ();
996 YY_CURRENT_BUFFER_LVALUE =
997 yy_create_buffer(yyin,YY_BUF_SIZE );
1000 yy_load_buffer_state( );
1003 while ( 1 ) /* loops until end-of-file is reached */
1005 yy_cp = (yy_c_buf_p);
1007 /* Support of yytext. */
1008 *yy_cp = (yy_hold_char);
1010 /* yy_bp points to the position in yy_ch_buf of the start of
1015 yy_current_state = (yy_start);
1016 yy_current_state += YY_AT_BOL();
1020 register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
1021 if ( yy_accept[yy_current_state] )
1023 (yy_last_accepting_state) = yy_current_state;
1024 (yy_last_accepting_cpos) = yy_cp;
1026 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1028 yy_current_state = (int) yy_def[yy_current_state];
1029 if ( yy_current_state >= 111 )
1030 yy_c = yy_meta[(unsigned int) yy_c];
1032 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1035 while ( yy_current_state != 110 );
1036 yy_cp = (yy_last_accepting_cpos);
1037 yy_current_state = (yy_last_accepting_state);
1040 yy_act = yy_accept[yy_current_state];
1042 YY_DO_BEFORE_ACTION;
1044 do_action: /* This label is used only to access EOF actions. */
1047 { /* beginning of action switch */
1048 case 0: /* must back up */
1049 /* undo the effects of YY_DO_BEFORE_ACTION */
1050 *yy_cp = (yy_hold_char);
1051 yy_cp = (yy_last_accepting_cpos);
1052 yy_current_state = (yy_last_accepting_state);
1053 goto yy_find_action;
1057 #line 221 "parser.lex"
1062 #line 222 "parser.lex"
1066 /* rule 3 can match eol */
1068 #line 223 "parser.lex"
1072 /* rule 4 can match eol */
1073 *yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
1074 (yy_c_buf_p) = yy_cp -= 1;
1075 YY_DO_BEFORE_ACTION; /* set up yytext again */
1077 #line 224 "parser.lex"
1078 {s(TWIP);c();BEGIN(0);}
1081 /* rule 5 can match eol */
1082 *yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
1083 (yy_c_buf_p) = yy_cp -= 1;
1084 YY_DO_BEFORE_ACTION; /* set up yytext again */
1086 #line 225 "parser.lex"
1087 {s(NUMBER);c();BEGIN(0);}
1090 /* rule 6 can match eol */
1092 #line 226 "parser.lex"
1096 /* rule 7 can match eol */
1098 #line 227 "parser.lex"
1103 #line 228 "parser.lex"
1104 {s(STRING);c();BEGIN(0);}
1107 *yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
1108 (yy_c_buf_p) = yy_cp -= 1;
1109 YY_DO_BEFORE_ACTION; /* set up yytext again */
1111 #line 229 "parser.lex"
1112 {c();printf("unterminated string in line %d: %s\n", line, yytext);exit(1);yyterminate();}
1115 /* rule 10 can match eol */
1117 #line 230 "parser.lex"
1118 {s(ASSIGNMENT);prefix="<plus>";c();BEGIN(R);}
1121 /* rule 11 can match eol */
1123 #line 231 "parser.lex"
1124 {s(ASSIGNMENT);prefix="<minus>";c();BEGIN(R);}
1127 /* rule 12 can match eol */
1129 #line 232 "parser.lex"
1130 {s(ASSIGNMENT);c();BEGIN(R);}
1132 /* values which appear only on the right-hand side of assignments, like: x=50% */
1135 #line 234 "parser.lex"
1136 {s(IDENTIFIER);c();BEGIN(0);}
1140 /* rule 14 can match eol */
1142 #line 236 "parser.lex"
1143 {handleInclude(yytext, yyleng);}
1147 #line 237 "parser.lex"
1151 /* rule 16 can match eol */
1153 #line 238 "parser.lex"
1158 #line 239 "parser.lex"
1159 {s(IDENTIFIER);c();}
1163 #line 240 "parser.lex"
1164 {c();BEGIN(BINARY);}
1167 /* rule 19 can match eol */
1169 #line 241 "parser.lex"
1174 #line 242 "parser.lex"
1175 {char c,c1=yytext[0];
1176 printf("Syntax error in line %d, %d: %s", line, column, yytext);
1179 if(c=='\n' || c==EOF)
1183 if(c1>='0' && c1<='9')
1184 printf(" (identifiers must not start with a digit)");
1190 case YY_STATE_EOF(INITIAL):
1191 case YY_STATE_EOF(R):
1192 case YY_STATE_EOF(BINARY):
1193 #line 256 "parser.lex"
1195 if ( --include_stack_ptr < 0 ) {
1199 yy_delete_buffer(YY_CURRENT_BUFFER );
1200 yy_switch_to_buffer(include_stack[include_stack_ptr] );
1201 column = column_stack[include_stack_ptr];
1202 line = line_stack[include_stack_ptr];
1208 #line 269 "parser.lex"
1209 YY_FATAL_ERROR( "flex scanner jammed" );
1211 #line 1212 "parser.yy.c"
1213 case YY_END_OF_BUFFER:
1215 /* Amount of text matched not including the EOB char. */
1216 int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
1218 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1219 *yy_cp = (yy_hold_char);
1220 YY_RESTORE_YY_MORE_OFFSET
1222 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1224 /* We're scanning a new file or input source. It's
1225 * possible that this happened because the user
1226 * just pointed yyin at a new source and called
1227 * yylex(). If so, then we have to assure
1228 * consistency between YY_CURRENT_BUFFER and our
1229 * globals. Here is the right place to do so, because
1230 * this is the first action (other than possibly a
1231 * back-up) that will match for the new input source.
1233 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1234 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1235 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1238 /* Note that here we test for yy_c_buf_p "<=" to the position
1239 * of the first EOB in the buffer, since yy_c_buf_p will
1240 * already have been incremented past the NUL character
1241 * (since all states make transitions on EOB to the
1242 * end-of-buffer state). Contrast this with the test
1245 if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1246 { /* This was really a NUL. */
1247 yy_state_type yy_next_state;
1249 (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
1251 yy_current_state = yy_get_previous_state( );
1253 /* Okay, we're now positioned to make the NUL
1254 * transition. We couldn't have
1255 * yy_get_previous_state() go ahead and do it
1256 * for us because it doesn't know how to deal
1257 * with the possibility of jamming (and we don't
1258 * want to build jamming into it because then it
1259 * will run more slowly).
1262 yy_next_state = yy_try_NUL_trans( yy_current_state );
1264 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1266 if ( yy_next_state )
1268 /* Consume the NUL. */
1269 yy_cp = ++(yy_c_buf_p);
1270 yy_current_state = yy_next_state;
1276 yy_cp = (yy_last_accepting_cpos);
1277 yy_current_state = (yy_last_accepting_state);
1278 goto yy_find_action;
1282 else switch ( yy_get_next_buffer( ) )
1284 case EOB_ACT_END_OF_FILE:
1286 (yy_did_buffer_switch_on_eof) = 0;
1290 /* Note: because we've taken care in
1291 * yy_get_next_buffer() to have set up
1292 * yytext, we can now set up
1293 * yy_c_buf_p so that if some total
1294 * hoser (like flex itself) wants to
1295 * call the scanner after we return the
1296 * YY_NULL, it'll still work - another
1297 * YY_NULL will get returned.
1299 (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
1301 yy_act = YY_STATE_EOF(YY_START);
1307 if ( ! (yy_did_buffer_switch_on_eof) )
1313 case EOB_ACT_CONTINUE_SCAN:
1315 (yytext_ptr) + yy_amount_of_matched_text;
1317 yy_current_state = yy_get_previous_state( );
1319 yy_cp = (yy_c_buf_p);
1320 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1323 case EOB_ACT_LAST_MATCH:
1325 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
1327 yy_current_state = yy_get_previous_state( );
1329 yy_cp = (yy_c_buf_p);
1330 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
1331 goto yy_find_action;
1338 "fatal flex scanner internal error--no action found" );
1339 } /* end of action switch */
1340 } /* end of scanning one token */
1341 } /* end of yylex */
1343 /* yy_get_next_buffer - try to read in a new buffer
1345 * Returns a code representing an action:
1346 * EOB_ACT_LAST_MATCH -
1347 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1348 * EOB_ACT_END_OF_FILE - end of file
1350 static int yy_get_next_buffer (void)
1352 register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1353 register char *source = (yytext_ptr);
1354 register int number_to_move, i;
1357 if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1359 "fatal flex scanner internal error--end of buffer missed" );
1361 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1362 { /* Don't try to fill the buffer, so this is an EOF. */
1363 if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
1365 /* We matched a single character, the EOB, so
1366 * treat this as a final EOF.
1368 return EOB_ACT_END_OF_FILE;
1373 /* We matched some text prior to the EOB, first
1376 return EOB_ACT_LAST_MATCH;
1380 /* Try to read more data. */
1382 /* First move last chars to start of buffer. */
1383 number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
1385 for ( i = 0; i < number_to_move; ++i )
1386 *(dest++) = *(source++);
1388 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1389 /* don't do the read, it's not guaranteed to return an EOF,
1392 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1397 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1399 while ( num_to_read <= 0 )
1400 { /* Not enough room in the buffer - grow it. */
1402 /* just a shorter name for the current buffer */
1403 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1405 int yy_c_buf_p_offset =
1406 (int) ((yy_c_buf_p) - b->yy_ch_buf);
1408 if ( b->yy_is_our_buffer )
1410 int new_size = b->yy_buf_size * 2;
1412 if ( new_size <= 0 )
1413 b->yy_buf_size += b->yy_buf_size / 8;
1415 b->yy_buf_size *= 2;
1417 b->yy_ch_buf = (char *)
1418 /* Include room in for 2 EOB chars. */
1419 yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
1422 /* Can't grow it, we don't own it. */
1425 if ( ! b->yy_ch_buf )
1427 "fatal error - scanner input buffer overflow" );
1429 (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1431 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1436 if ( num_to_read > YY_READ_BUF_SIZE )
1437 num_to_read = YY_READ_BUF_SIZE;
1439 /* Read in more data. */
1440 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1441 (yy_n_chars), (size_t) num_to_read );
1443 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1446 if ( (yy_n_chars) == 0 )
1448 if ( number_to_move == YY_MORE_ADJ )
1450 ret_val = EOB_ACT_END_OF_FILE;
1456 ret_val = EOB_ACT_LAST_MATCH;
1457 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1458 YY_BUFFER_EOF_PENDING;
1463 ret_val = EOB_ACT_CONTINUE_SCAN;
1465 if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1466 /* Extend the array by 50%, plus the number we really need. */
1467 yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1468 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
1469 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1470 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1473 (yy_n_chars) += number_to_move;
1474 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1475 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1477 (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1482 /* yy_get_previous_state - get the state just before the EOB char was reached */
1484 static yy_state_type yy_get_previous_state (void)
1486 register yy_state_type yy_current_state;
1487 register char *yy_cp;
1489 yy_current_state = (yy_start);
1490 yy_current_state += YY_AT_BOL();
1492 for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1494 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1495 if ( yy_accept[yy_current_state] )
1497 (yy_last_accepting_state) = yy_current_state;
1498 (yy_last_accepting_cpos) = yy_cp;
1500 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1502 yy_current_state = (int) yy_def[yy_current_state];
1503 if ( yy_current_state >= 111 )
1504 yy_c = yy_meta[(unsigned int) yy_c];
1506 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1509 return yy_current_state;
1512 /* yy_try_NUL_trans - try to make a transition on the NUL character
1515 * next_state = yy_try_NUL_trans( current_state );
1517 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
1519 register int yy_is_jam;
1520 register char *yy_cp = (yy_c_buf_p);
1522 register YY_CHAR yy_c = 1;
1523 if ( yy_accept[yy_current_state] )
1525 (yy_last_accepting_state) = yy_current_state;
1526 (yy_last_accepting_cpos) = yy_cp;
1528 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1530 yy_current_state = (int) yy_def[yy_current_state];
1531 if ( yy_current_state >= 111 )
1532 yy_c = yy_meta[(unsigned int) yy_c];
1534 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1535 yy_is_jam = (yy_current_state == 110);
1537 return yy_is_jam ? 0 : yy_current_state;
1540 static void yyunput (int c, register char * yy_bp )
1542 register char *yy_cp;
1544 yy_cp = (yy_c_buf_p);
1546 /* undo effects of setting up yytext */
1547 *yy_cp = (yy_hold_char);
1549 if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1550 { /* need to shift things up to make room */
1551 /* +2 for EOB chars. */
1552 register int number_to_move = (yy_n_chars) + 2;
1553 register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1554 YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1555 register char *source =
1556 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1558 while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1559 *--dest = *--source;
1561 yy_cp += (int) (dest - source);
1562 yy_bp += (int) (dest - source);
1563 YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
1564 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1566 if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1567 YY_FATAL_ERROR( "flex scanner push-back overflow" );
1570 *--yy_cp = (char) c;
1572 (yytext_ptr) = yy_bp;
1573 (yy_hold_char) = *yy_cp;
1574 (yy_c_buf_p) = yy_cp;
1579 static int yyinput (void)
1581 static int input (void)
1587 *(yy_c_buf_p) = (yy_hold_char);
1589 if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1591 /* yy_c_buf_p now points to the character we want to return.
1592 * If this occurs *before* the EOB characters, then it's a
1593 * valid NUL; if not, then we've hit the end of the buffer.
1595 if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1596 /* This was really a NUL. */
1597 *(yy_c_buf_p) = '\0';
1600 { /* need more input */
1601 int offset = (yy_c_buf_p) - (yytext_ptr);
1604 switch ( yy_get_next_buffer( ) )
1606 case EOB_ACT_LAST_MATCH:
1607 /* This happens because yy_g_n_b()
1608 * sees that we've accumulated a
1609 * token and flags that we need to
1610 * try matching the token before
1611 * proceeding. But for input(),
1612 * there's no matching to consider.
1613 * So convert the EOB_ACT_LAST_MATCH
1614 * to EOB_ACT_END_OF_FILE.
1617 /* Reset buffer status. */
1622 case EOB_ACT_END_OF_FILE:
1627 if ( ! (yy_did_buffer_switch_on_eof) )
1636 case EOB_ACT_CONTINUE_SCAN:
1637 (yy_c_buf_p) = (yytext_ptr) + offset;
1643 c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
1644 *(yy_c_buf_p) = '\0'; /* preserve yytext */
1645 (yy_hold_char) = *++(yy_c_buf_p);
1647 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
1651 #endif /* ifndef YY_NO_INPUT */
1653 /** Immediately switch to a different input stream.
1654 * @param input_file A readable stream.
1656 * @note This function does not reset the start condition to @c INITIAL .
1658 void yyrestart (FILE * input_file )
1661 if ( ! YY_CURRENT_BUFFER ){
1662 yyensure_buffer_stack ();
1663 YY_CURRENT_BUFFER_LVALUE =
1664 yy_create_buffer(yyin,YY_BUF_SIZE );
1667 yy_init_buffer(YY_CURRENT_BUFFER,input_file );
1668 yy_load_buffer_state( );
1671 /** Switch to a different input buffer.
1672 * @param new_buffer The new input buffer.
1675 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
1678 /* TODO. We should be able to replace this entire function body
1680 * yypop_buffer_state();
1681 * yypush_buffer_state(new_buffer);
1683 yyensure_buffer_stack ();
1684 if ( YY_CURRENT_BUFFER == new_buffer )
1687 if ( YY_CURRENT_BUFFER )
1689 /* Flush out information for old buffer. */
1690 *(yy_c_buf_p) = (yy_hold_char);
1691 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1692 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1695 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1696 yy_load_buffer_state( );
1698 /* We don't actually know whether we did this switch during
1699 * EOF (yywrap()) processing, but the only time this flag
1700 * is looked at is after yywrap() is called, so it's safe
1701 * to go ahead and always set it.
1703 (yy_did_buffer_switch_on_eof) = 1;
1706 static void yy_load_buffer_state (void)
1708 (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1709 (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1710 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1711 (yy_hold_char) = *(yy_c_buf_p);
1714 /** Allocate and initialize an input buffer state.
1715 * @param file A readable stream.
1716 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1718 * @return the allocated buffer state.
1720 YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
1724 b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1726 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1728 b->yy_buf_size = size;
1730 /* yy_ch_buf has to be 2 characters longer than the size given because
1731 * we need to put in 2 end-of-buffer characters.
1733 b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );
1734 if ( ! b->yy_ch_buf )
1735 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1737 b->yy_is_our_buffer = 1;
1739 yy_init_buffer(b,file );
1744 /** Destroy the buffer.
1745 * @param b a buffer created with yy_create_buffer()
1748 void yy_delete_buffer (YY_BUFFER_STATE b )
1754 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1755 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1757 if ( b->yy_is_our_buffer )
1758 yyfree((void *) b->yy_ch_buf );
1760 yyfree((void *) b );
1763 #ifndef _UNISTD_H /* assume unistd.h has isatty() for us */
1767 #ifdef __THROW /* this is a gnuism */
1768 extern int isatty (int ) __THROW;
1770 extern int isatty (int );
1777 /* Initializes or reinitializes a buffer.
1778 * This function is sometimes called more than once on the same buffer,
1779 * such as during a yyrestart() or at EOF.
1781 static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
1786 yy_flush_buffer(b );
1788 b->yy_input_file = file;
1789 b->yy_fill_buffer = 1;
1791 /* If b is the current buffer, then yy_init_buffer was _probably_
1792 * called from yyrestart() or through yy_get_next_buffer.
1793 * In that case, we don't want to reset the lineno or column.
1795 if (b != YY_CURRENT_BUFFER){
1796 b->yy_bs_lineno = 1;
1797 b->yy_bs_column = 0;
1800 b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1805 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1806 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1809 void yy_flush_buffer (YY_BUFFER_STATE b )
1816 /* We always need two end-of-buffer characters. The first causes
1817 * a transition to the end-of-buffer state. The second causes
1818 * a jam in that state.
1820 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1821 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1823 b->yy_buf_pos = &b->yy_ch_buf[0];
1826 b->yy_buffer_status = YY_BUFFER_NEW;
1828 if ( b == YY_CURRENT_BUFFER )
1829 yy_load_buffer_state( );
1832 /** Pushes the new state onto the stack. The new state becomes
1833 * the current state. This function will allocate the stack
1835 * @param new_buffer The new state.
1838 void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
1840 if (new_buffer == NULL)
1843 yyensure_buffer_stack();
1845 /* This block is copied from yy_switch_to_buffer. */
1846 if ( YY_CURRENT_BUFFER )
1848 /* Flush out information for old buffer. */
1849 *(yy_c_buf_p) = (yy_hold_char);
1850 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1851 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1854 /* Only push if top exists. Otherwise, replace top. */
1855 if (YY_CURRENT_BUFFER)
1856 (yy_buffer_stack_top)++;
1857 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1859 /* copied from yy_switch_to_buffer. */
1860 yy_load_buffer_state( );
1861 (yy_did_buffer_switch_on_eof) = 1;
1864 /** Removes and deletes the top of the stack, if present.
1865 * The next element becomes the new top.
1868 void yypop_buffer_state (void)
1870 if (!YY_CURRENT_BUFFER)
1873 yy_delete_buffer(YY_CURRENT_BUFFER );
1874 YY_CURRENT_BUFFER_LVALUE = NULL;
1875 if ((yy_buffer_stack_top) > 0)
1876 --(yy_buffer_stack_top);
1878 if (YY_CURRENT_BUFFER) {
1879 yy_load_buffer_state( );
1880 (yy_did_buffer_switch_on_eof) = 1;
1884 /* Allocates the stack if it does not exist.
1885 * Guarantees space for at least one push.
1887 static void yyensure_buffer_stack (void)
1891 if (!(yy_buffer_stack)) {
1893 /* First allocation is just for 2 elements, since we don't know if this
1894 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1895 * immediate realloc on the next call.
1898 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1899 (num_to_alloc * sizeof(struct yy_buffer_state*)
1901 if ( ! (yy_buffer_stack) )
1902 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1904 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1906 (yy_buffer_stack_max) = num_to_alloc;
1907 (yy_buffer_stack_top) = 0;
1911 if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1913 /* Increase the buffer to prepare for a possible push. */
1914 int grow_size = 8 /* arbitrary grow size */;
1916 num_to_alloc = (yy_buffer_stack_max) + grow_size;
1917 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1919 num_to_alloc * sizeof(struct yy_buffer_state*)
1921 if ( ! (yy_buffer_stack) )
1922 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1924 /* zero only the new slots.*/
1925 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1926 (yy_buffer_stack_max) = num_to_alloc;
1930 /** Setup the input buffer state to scan directly from a user-specified character buffer.
1931 * @param base the character buffer
1932 * @param size the size in bytes of the character buffer
1934 * @return the newly allocated buffer state object.
1936 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
1941 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1942 base[size-1] != YY_END_OF_BUFFER_CHAR )
1943 /* They forgot to leave room for the EOB's. */
1946 b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
1948 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1950 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1951 b->yy_buf_pos = b->yy_ch_buf = base;
1952 b->yy_is_our_buffer = 0;
1953 b->yy_input_file = 0;
1954 b->yy_n_chars = b->yy_buf_size;
1955 b->yy_is_interactive = 0;
1957 b->yy_fill_buffer = 0;
1958 b->yy_buffer_status = YY_BUFFER_NEW;
1960 yy_switch_to_buffer(b );
1965 /** Setup the input buffer state to scan a string. The next call to yylex() will
1966 * scan from a @e copy of @a str.
1967 * @param yystr a NUL-terminated string to scan
1969 * @return the newly allocated buffer state object.
1970 * @note If you want to scan bytes that may contain NUL values, then use
1971 * yy_scan_bytes() instead.
1973 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1976 return yy_scan_bytes(yystr,strlen(yystr) );
1979 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1980 * scan from a @e copy of @a bytes.
1981 * @param bytes the byte buffer to scan
1982 * @param len the number of bytes in the buffer pointed to by @a bytes.
1984 * @return the newly allocated buffer state object.
1986 YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len )
1993 /* Get memory for full buffer, including space for trailing EOB's. */
1994 n = _yybytes_len + 2;
1995 buf = (char *) yyalloc(n );
1997 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1999 for ( i = 0; i < _yybytes_len; ++i )
2000 buf[i] = yybytes[i];
2002 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2004 b = yy_scan_buffer(buf,n );
2006 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2008 /* It's okay to grow etc. this buffer, and we should throw it
2009 * away when we're done.
2011 b->yy_is_our_buffer = 1;
2016 #ifndef YY_EXIT_FAILURE
2017 #define YY_EXIT_FAILURE 2
2020 static void yy_fatal_error (yyconst char* msg )
2022 (void) fprintf( stderr, "%s\n", msg );
2023 exit( YY_EXIT_FAILURE );
2026 /* Redefine yyless() so it works in section 3 code. */
2032 /* Undo effects of setting up yytext. */ \
2033 int yyless_macro_arg = (n); \
2034 YY_LESS_LINENO(yyless_macro_arg);\
2035 yytext[yyleng] = (yy_hold_char); \
2036 (yy_c_buf_p) = yytext + yyless_macro_arg; \
2037 (yy_hold_char) = *(yy_c_buf_p); \
2038 *(yy_c_buf_p) = '\0'; \
2039 yyleng = yyless_macro_arg; \
2043 /* Accessor methods (get/set functions) to struct members. */
2045 /** Get the current line number.
2048 int yyget_lineno (void)
2054 /** Get the input stream.
2057 FILE *yyget_in (void)
2062 /** Get the output stream.
2065 FILE *yyget_out (void)
2070 /** Get the length of the current token.
2073 int yyget_leng (void)
2078 /** Get the current token.
2082 char *yyget_text (void)
2087 /** Set the current line number.
2088 * @param line_number
2091 void yyset_lineno (int line_number )
2094 yylineno = line_number;
2097 /** Set the input stream. This does not discard the current
2099 * @param in_str A readable stream.
2101 * @see yy_switch_to_buffer
2103 void yyset_in (FILE * in_str )
2108 void yyset_out (FILE * out_str )
2113 int yyget_debug (void)
2115 return yy_flex_debug;
2118 void yyset_debug (int bdebug )
2120 yy_flex_debug = bdebug ;
2123 static int yy_init_globals (void)
2125 /* Initialization is the same as for the non-reentrant scanner.
2126 * This function is called from yylex_destroy(), so don't allocate here.
2129 (yy_buffer_stack) = 0;
2130 (yy_buffer_stack_top) = 0;
2131 (yy_buffer_stack_max) = 0;
2132 (yy_c_buf_p) = (char *) 0;
2136 /* Defined in main.c */
2145 /* For future reference: Set errno on error, since we are called by
2151 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
2152 int yylex_destroy (void)
2155 /* Pop the buffer stack, destroying each element. */
2156 while(YY_CURRENT_BUFFER){
2157 yy_delete_buffer(YY_CURRENT_BUFFER );
2158 YY_CURRENT_BUFFER_LVALUE = NULL;
2159 yypop_buffer_state();
2162 /* Destroy the stack itself. */
2163 yyfree((yy_buffer_stack) );
2164 (yy_buffer_stack) = NULL;
2166 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2167 * yylex() is called, initialization will occur. */
2174 * Internal utility routines.
2178 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
2181 for ( i = 0; i < n; ++i )
2186 #ifdef YY_NEED_STRLEN
2187 static int yy_flex_strlen (yyconst char * s )
2190 for ( n = 0; s[n]; ++n )
2197 void *yyalloc (yy_size_t size )
2199 return (void *) malloc( size );
2202 void *yyrealloc (void * ptr, yy_size_t size )
2204 /* The cast to (char *) in the following accommodates both
2205 * implementations that use char* generic pointers, and those
2206 * that use void* generic pointers. It works with the latter
2207 * because both ANSI C and C++ allow castless assignment from
2208 * any pointer type to void*, and deal with argument conversions
2209 * as though doing an assignment.
2211 return (void *) realloc( (char *) ptr, size );
2214 void yyfree (void * ptr )
2216 free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2219 #define YYTABLES_NAME "yytables"
2221 #line 269 "parser.lex"
2230 void freeTokens(struct token_t*file)
2232 mem_clear(&strings);
2236 struct token_t* generateTokens(char*filename)
2240 struct token_t*result;
2246 if(!strcmp(filename,"-"))
2249 fi = fopen(filename, "rb");
2252 printf("Couldn't find file %s\n", filename);
2259 mem_put(&strings, &t, 1); //hack- make all valid strings start at position >0
2265 #ifdef YY_CURRENT_BUFFER
2266 // some newer flex versions require it like this:
2267 yy_delete_buffer(YY_CURRENT_BUFFER);
2269 yy_delete_buffer(yy_current_buffer);
2272 result = (struct token_t*)tokens.buffer;
2273 num = tokens.pos/sizeof(struct token_t);
2275 for(t=0;t<tokens.pos/sizeof(struct token_t);t++) {
2277 result[t].text += (int)strings.buffer;