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