From 6d7c3321ba710da3a984ec5da9dc7faf4bbcca23 Mon Sep 17 00:00:00 2001 From: John Millaway Date: Fri, 16 Aug 2002 22:32:02 +0000 Subject: Added --tables option. Omitted tables code from generated scanner when unused. --- flexdef.h | 10 ++++++++++ main.c | 14 +++++++++++++- misc.c | 10 +++++++--- options.c | 1 + options.h | 1 + parse.y | 3 +++ scan.l | 1 + 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/flexdef.h b/flexdef.h index a7effb5..036611c 100644 --- a/flexdef.h +++ b/flexdef.h @@ -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; diff --git a/main.c b/main.c index 762d328..895b5ce 100644 --- a/main.c +++ b/main.c @@ -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" diff --git a/misc.c b/misc.c index ab09657..976ea18 100644 --- a/misc.c +++ b/misc.c @@ -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 ); + } } } diff --git a/options.c b/options.c index 2091dba..d4d61c1 100644 --- a/options.c +++ b/options.c @@ -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. */ diff --git a/options.h b/options.h index afe0e4a..cbf6472 100644 --- a/options.h +++ b/options.h @@ -112,6 +112,7 @@ enum flexopt_flag_t { OPT_STACK, OPT_STDINIT, OPT_STDOUT, + OPT_TABLES, OPT_TRACE, OPT_NO_UNISTD_H, OPT_VERBOSE, diff --git a/parse.y b/parse.y index 145d8dd..94a7075 100644 --- a/parse.y +++ b/parse.y @@ -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' diff --git a/scan.l b/scan.l index 18d0de8..43dd669 100644 --- a/scan.l +++ b/scan.l @@ -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 ); -- cgit v1.2.3