gen.c (124183) | gen.c (179549) |
---|---|
1/* gen - actual generation (writing) of flex scanners */ 2 3/*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Vern Paxson. --- 14 unchanged lines hidden (view full) --- 23 * specific prior written permission. 24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 */ 28 29/* $Header: /home/daffy/u0/vern/flex/RCS/gen.c,v 2.56 96/05/25 20:43:38 vern Exp $ */ 30#include <sys/cdefs.h> | 1/* gen - actual generation (writing) of flex scanners */ 2 3/*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Vern Paxson. --- 14 unchanged lines hidden (view full) --- 23 * specific prior written permission. 24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 */ 28 29/* $Header: /home/daffy/u0/vern/flex/RCS/gen.c,v 2.56 96/05/25 20:43:38 vern Exp $ */ 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/usr.bin/lex/gen.c 124183 2004-01-06 18:54:55Z nectar $"); | 31__FBSDID("$FreeBSD: head/usr.bin/lex/gen.c 179549 2008-06-04 19:50:34Z dwmalone $"); |
32 33#include "flexdef.h" 34 35 36/* declare functions that have forward references */ 37 38void gen_next_state PROTO((int)); 39void genecs PROTO((void)); --- 18 unchanged lines hidden (view full) --- 58static char C_state_decl[] = 59 "static yyconst yy_state_type %s[%d] =\n { 0,\n"; 60 61 62/* Indent to the current level. */ 63 64void do_indent() 65 { | 32 33#include "flexdef.h" 34 35 36/* declare functions that have forward references */ 37 38void gen_next_state PROTO((int)); 39void genecs PROTO((void)); --- 18 unchanged lines hidden (view full) --- 58static char C_state_decl[] = 59 "static yyconst yy_state_type %s[%d] =\n { 0,\n"; 60 61 62/* Indent to the current level. */ 63 64void do_indent() 65 { |
66 register int i = indent_level * 8; | 66 int i = indent_level * 8; |
67 68 while ( i >= 8 ) 69 { 70 outc( '\t' ); 71 i -= 8; 72 } 73 74 while ( i > 0 ) --- 53 unchanged lines hidden (view full) --- 128 set_indent( 0 ); 129 } 130 131 132/* genctbl - generates full speed compressed transition table */ 133 134void genctbl() 135 { | 67 68 while ( i >= 8 ) 69 { 70 outc( '\t' ); 71 i -= 8; 72 } 73 74 while ( i > 0 ) --- 53 unchanged lines hidden (view full) --- 128 set_indent( 0 ); 129 } 130 131 132/* genctbl - generates full speed compressed transition table */ 133 134void genctbl() 135 { |
136 register int i; | 136 int i; |
137 int end_of_buffer_action = num_rules + 1; 138 139 /* Table of verify for transition and offset to next state. */ 140 out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n", 141 tblend + numecs + 1 ); 142 outn( " {" ); 143 144 /* We want the transition to be represented as the offset to the --- 79 unchanged lines hidden (view full) --- 224 genecs(); 225 } 226 227 228/* Generate equivalence-class tables. */ 229 230void genecs() 231 { | 137 int end_of_buffer_action = num_rules + 1; 138 139 /* Table of verify for transition and offset to next state. */ 140 out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n", 141 tblend + numecs + 1 ); 142 outn( " {" ); 143 144 /* We want the transition to be represented as the offset to the --- 79 unchanged lines hidden (view full) --- 224 genecs(); 225 } 226 227 228/* Generate equivalence-class tables. */ 229 230void genecs() 231 { |
232 register int i, j; | 232 int i, j; |
233 int numrows; 234 235 out_str_dec( C_int_decl, "yy_ec", csize ); 236 237 for ( i = 1; i < csize; ++i ) 238 { 239 if ( caseins && (i >= 'A') && (i <= 'Z') ) 240 ecgroup[i] = ecgroup[clower( i )]; --- 166 unchanged lines hidden (view full) --- 407 } 408 } 409 410 411/* genftbl - generate full transition table */ 412 413void genftbl() 414 { | 233 int numrows; 234 235 out_str_dec( C_int_decl, "yy_ec", csize ); 236 237 for ( i = 1; i < csize; ++i ) 238 { 239 if ( caseins && (i >= 'A') && (i <= 'Z') ) 240 ecgroup[i] = ecgroup[clower( i )]; --- 166 unchanged lines hidden (view full) --- 407 } 408 } 409 410 411/* genftbl - generate full transition table */ 412 413void genftbl() 414 { |
415 register int i; | 415 int i; |
416 int end_of_buffer_action = num_rules + 1; 417 418 out_str_dec( long_align ? C_long_decl : C_short_decl, 419 "yy_accept", lastdfa + 1 ); 420 421 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; 422 423 for ( i = 1; i <= lastdfa; ++i ) 424 { | 416 int end_of_buffer_action = num_rules + 1; 417 418 out_str_dec( long_align ? C_long_decl : C_short_decl, 419 "yy_accept", lastdfa + 1 ); 420 421 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; 422 423 for ( i = 1; i <= lastdfa; ++i ) 424 { |
425 register int anum = dfaacc[i].dfaacc_state; | 425 int anum = dfaacc[i].dfaacc_state; |
426 427 mkdata( anum ); 428 429 if ( trace && anum ) 430 fprintf( stderr, _( "state # %d accepts: [%d]\n" ), 431 i, anum ); 432 } 433 --- 8 unchanged lines hidden (view full) --- 442 } 443 444 445/* Generate the code to find the next compressed-table state. */ 446 447void gen_next_compressed_state( char_map ) 448char *char_map; 449 { | 426 427 mkdata( anum ); 428 429 if ( trace && anum ) 430 fprintf( stderr, _( "state # %d accepts: [%d]\n" ), 431 i, anum ); 432 } 433 --- 8 unchanged lines hidden (view full) --- 442 } 443 444 445/* Generate the code to find the next compressed-table state. */ 446 447void gen_next_compressed_state( char_map ) 448char *char_map; 449 { |
450 indent_put2s( "register YY_CHAR yy_c = %s;", char_map ); | 450 indent_put2s( "YY_CHAR yy_c = %s;", char_map ); |
451 452 /* Save the backing-up info \before/ computing the next state 453 * because we always compute one more state than needed - we 454 * always proceed until we reach a jam state 455 */ 456 gen_backing_up(); 457 458 indent_puts( --- 70 unchanged lines hidden (view full) --- 529 outc( '\n' ); 530 indent_puts( "yy_current_state = -yy_current_state;" ); 531 } 532 533 else if ( fullspd ) 534 { 535 indent_puts( "{" ); /* } for vi */ 536 indent_puts( | 451 452 /* Save the backing-up info \before/ computing the next state 453 * because we always compute one more state than needed - we 454 * always proceed until we reach a jam state 455 */ 456 gen_backing_up(); 457 458 indent_puts( --- 70 unchanged lines hidden (view full) --- 529 outc( '\n' ); 530 indent_puts( "yy_current_state = -yy_current_state;" ); 531 } 532 533 else if ( fullspd ) 534 { 535 indent_puts( "{" ); /* } for vi */ 536 indent_puts( |
537 "register yyconst struct yy_trans_info *yy_trans_info;\n" ); 538 indent_puts( "register YY_CHAR yy_c;\n" ); | 537 "yyconst struct yy_trans_info *yy_trans_info;\n" ); 538 indent_puts( "YY_CHAR yy_c;\n" ); |
539 indent_put2s( "for ( yy_c = %s;", char_map ); 540 indent_puts( 541 " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" ); 542 indent_puts( "yy_verify == yy_c;" ); 543 indent_put2s( " yy_c = %s )", char_map_2 ); 544 545 indent_up(); 546 --- 124 unchanged lines hidden (view full) --- 671 * that uses it. Otherwise lint and the like complain. 672 */ 673 int need_backing_up = (num_backing_up > 0 && ! reject); 674 675 if ( need_backing_up && (! nultrans || fullspd || fulltbl) ) 676 /* We're going to need yy_cp lying around for the call 677 * below to gen_backing_up(). 678 */ | 539 indent_put2s( "for ( yy_c = %s;", char_map ); 540 indent_puts( 541 " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" ); 542 indent_puts( "yy_verify == yy_c;" ); 543 indent_put2s( " yy_c = %s )", char_map_2 ); 544 545 indent_up(); 546 --- 124 unchanged lines hidden (view full) --- 671 * that uses it. Otherwise lint and the like complain. 672 */ 673 int need_backing_up = (num_backing_up > 0 && ! reject); 674 675 if ( need_backing_up && (! nultrans || fullspd || fulltbl) ) 676 /* We're going to need yy_cp lying around for the call 677 * below to gen_backing_up(). 678 */ |
679 indent_puts( "register char *yy_cp = yy_c_buf_p;" ); | 679 indent_puts( "char *yy_cp = yy_c_buf_p;" ); |
680 681 outc( '\n' ); 682 683 if ( nultrans ) 684 { 685 indent_puts( 686 "yy_current_state = yy_NUL_trans[yy_current_state];" ); 687 indent_puts( "yy_is_jam = (yy_current_state == 0);" ); --- 5 unchanged lines hidden (view full) --- 693 out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n", 694 NUL_ec ); 695 indent_puts( "yy_is_jam = (yy_current_state <= 0);" ); 696 } 697 698 else if ( fullspd ) 699 { 700 do_indent(); | 680 681 outc( '\n' ); 682 683 if ( nultrans ) 684 { 685 indent_puts( 686 "yy_current_state = yy_NUL_trans[yy_current_state];" ); 687 indent_puts( "yy_is_jam = (yy_current_state == 0);" ); --- 5 unchanged lines hidden (view full) --- 693 out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n", 694 NUL_ec ); 695 indent_puts( "yy_is_jam = (yy_current_state <= 0);" ); 696 } 697 698 else if ( fullspd ) 699 { 700 do_indent(); |
701 out_dec( "register int yy_c = %d;\n", NUL_ec ); | 701 out_dec( "int yy_c = %d;\n", NUL_ec ); |
702 703 indent_puts( | 702 703 indent_puts( |
704 "register yyconst struct yy_trans_info *yy_trans_info;\n" ); | 704 "yyconst struct yy_trans_info *yy_trans_info;\n" ); |
705 indent_puts( 706 "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" ); 707 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); 708 709 indent_puts( 710 "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" ); 711 } 712 --- 241 unchanged lines hidden (view full) --- 954 total_states = lastdfa + numtemps; 955 956 out_str_dec( (tblend >= MAX_SHORT || long_align) ? 957 C_long_decl : C_short_decl, 958 "yy_base", total_states + 1 ); 959 960 for ( i = 1; i <= lastdfa; ++i ) 961 { | 705 indent_puts( 706 "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" ); 707 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); 708 709 indent_puts( 710 "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" ); 711 } 712 --- 241 unchanged lines hidden (view full) --- 954 total_states = lastdfa + numtemps; 955 956 out_str_dec( (tblend >= MAX_SHORT || long_align) ? 957 C_long_decl : C_short_decl, 958 "yy_base", total_states + 1 ); 959 960 for ( i = 1; i <= lastdfa; ++i ) 961 { |
962 register int d = def[i]; | 962 int d = def[i]; |
963 964 if ( base[i] == JAMSTATE ) 965 base[i] = jambase; 966 967 if ( d == JAMSTATE ) 968 def[i] = jamstate; 969 970 else if ( d < 0 ) --- 84 unchanged lines hidden (view full) --- 1055 } 1056 1057 1058/* make_tables - generate transition tables and finishes generating output file 1059 */ 1060 1061void make_tables() 1062 { | 963 964 if ( base[i] == JAMSTATE ) 965 base[i] = jambase; 966 967 if ( d == JAMSTATE ) 968 def[i] = jamstate; 969 970 else if ( d < 0 ) --- 84 unchanged lines hidden (view full) --- 1055 } 1056 1057 1058/* make_tables - generate transition tables and finishes generating output file 1059 */ 1060 1061void make_tables() 1062 { |
1063 register int i; | 1063 int i; |
1064 int did_eof_rule = false; 1065 1066 skelout(); 1067 1068 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore 1069 * being used. 1070 */ 1071 set_indent( 1 ); --- 558 unchanged lines hidden --- | 1064 int did_eof_rule = false; 1065 1066 skelout(); 1067 1068 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore 1069 * being used. 1070 */ 1071 set_indent( 1 ); --- 558 unchanged lines hidden --- |