diff options
author | John Millaway <john43@users.sourceforge.net> | 2002-08-16 22:32:02 +0000 |
---|---|---|
committer | John Millaway <john43@users.sourceforge.net> | 2002-08-16 22:32:02 +0000 |
commit | 6d7c3321ba710da3a984ec5da9dc7faf4bbcca23 (patch) | |
tree | aef195d74a0e584597ac7e1c478eb0d1675d543d | |
parent | 2bb924b502c41a23ab2bc8a29355f08746f8eb21 (diff) |
Added --tables option.
Omitted tables code from generated scanner when unused.
-rw-r--r-- | flexdef.h | 10 | ||||
-rw-r--r-- | main.c | 14 | ||||
-rw-r--r-- | misc.c | 10 | ||||
-rw-r--r-- | options.c | 1 | ||||
-rw-r--r-- | options.h | 1 | ||||
-rw-r--r-- | parse.y | 3 | ||||
-rw-r--r-- | scan.l | 1 |
7 files changed, 36 insertions, 4 deletions
@@ -384,6 +384,16 @@ extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap; extern int csize; extern int yymore_used, reject, real_reject, continued_action, in_rule; +/* + * tablesext - if true, create external tables + * tablestoggle - if true, then output extneral tables code + * tablesfilename - filename for external tables + * tablesout - FILE stream for external tables + */ +extern bool tablesext, tablestoggle; +extern char* tablesfilename; +extern FILE* tablesout; + extern int yymore_really_used, reject_really_used; @@ -105,6 +105,10 @@ jmp_buf flex_main_jmp_buf; bool *rule_has_nl, *ccl_has_nl; int nlch = '\n'; +bool tablesext, tablestoggle; +char* tablesfilename; +FILE* tablesout; + /* Make sure program_name is initialized so we don't crash if writing * out an error message before getting the program name from argv[0]. */ @@ -966,6 +970,9 @@ char **argv; prefix = "yy"; yyclass = 0; use_read = use_stdout = false; + tablesext = tablestoggle = false; + tablesfilename = NULL; + tablesout = NULL; sawcmpflag = false; @@ -1169,7 +1176,11 @@ char **argv; case OPT_NO_UNISTD_H: buf_strdefine(&userdef_buf,"YY_NO_UNISTD_H", "1"); break; - + + case OPT_TABLES: + tablesext = true; + break; + case OPT_TRACE: trace = true; break; @@ -1794,6 +1805,7 @@ _( " -t, --stdout write scanner on stdout instead of %s\n" " --yyclass=NAME name of C++ class\n" " --header=FILE create a C header file in addition to the scanner\n" +" --tables[=FILE] write tables to FILE\n" "\n" "Scanner behavior:\n" @@ -842,9 +842,10 @@ void skelout() /* a comment in the skel. ignore. */ break; - case 't': - /* %t - toggle tables api */ - break; + case 't': + /* %t - toggle tables api */ + tablestoggle = !tablestoggle; + break; default: flexfatal( @@ -853,7 +854,10 @@ void skelout() } else if ( do_copy ) + { + if (tablesext || !tablestoggle) outn( buf ); + } } } @@ -114,6 +114,7 @@ optspec_t flexopts[] = { {"--stdout", OPT_STDOUT,0},/* Write generated scanner to stdout. */ {"-T", OPT_TRACE,0}, {"--trace", OPT_TRACE,0},/* Flex should run in trace mode. */ +{"--tables[=FILE]", OPT_TABLES,0},/* Save tables to FILE */ {"--nounistd", OPT_NO_UNISTD_H,0}, /* Do not include unistd.h */ {"-v", OPT_VERBOSE,0}, {"--verbose", OPT_VERBOSE,0},/* Write summary of scanner statistics to stdout. */ @@ -112,6 +112,7 @@ enum flexopt_flag_t { OPT_STACK, OPT_STDINIT, OPT_STDOUT, + OPT_TABLES, OPT_TRACE, OPT_NO_UNISTD_H, OPT_VERBOSE, @@ -2,6 +2,7 @@ %token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP %token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER +%token OPT_TABLES %token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH %token CCE_LOWER CCE_PRINT CCE_PUNCT CCE_SPACE CCE_UPPER CCE_XDIGIT @@ -217,6 +218,8 @@ option : OPT_OUTFILE '=' NAME { yyclass = copy_string( nmstr ); } | OPT_HEADER '=' NAME { headerfilename = copy_string( nmstr ); } + | OPT_TABLES '=' NAME + { tablesext = true; tablesfilename = copy_string( nmstr ); } ; sect2 : sect2 scon initforrule flexrule '\n' @@ -316,6 +316,7 @@ LEXOPT [aceknopr] prefix return OPT_PREFIX; yyclass return OPT_YYCLASS; header return OPT_HEADER; + tables return OPT_TABLES; \"[^"\n]*\" { strcpy( nmstr, yytext + 1 ); |