Omitted tables code from generated scanner when unused.
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;
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].
*/
prefix = "yy";
yyclass = 0;
use_read = use_stdout = false;
+ tablesext = tablestoggle = false;
+ tablesfilename = NULL;
+ tablesout = NULL;
sawcmpflag = false;
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;
" -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"
/* 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(
}
else if ( do_copy )
+ {
+ if (tablesext || !tablestoggle)
outn( buf );
+ }
}
}
{"--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. */
OPT_STACK,
OPT_STDINIT,
OPT_STDOUT,
+ OPT_TABLES,
OPT_TRACE,
OPT_NO_UNISTD_H,
OPT_VERBOSE,
%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
{ 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'
prefix return OPT_PREFIX;
yyclass return OPT_YYCLASS;
header return OPT_HEADER;
+ tables return OPT_TABLES;
\"[^"\n]*\" {
strcpy( nmstr, yytext + 1 );