]> granicus.if.org Git - flex/commitdiff
Added --tables option.
authorJohn Millaway <john43@users.sourceforge.net>
Fri, 16 Aug 2002 22:32:02 +0000 (22:32 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Fri, 16 Aug 2002 22:32:02 +0000 (22:32 +0000)
Omitted tables code from generated scanner when unused.

flexdef.h
main.c
misc.c
options.c
options.h
parse.y
scan.l

index a7effb55acf7eafd6405a47abf0ee02c75c2687c..036611c25ebe7bdb9b65647b58bb59c9bfc1647c 100644 (file)
--- 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 762d328286f4527aaa0cacb6a41ffbf60f5164fe..895b5ce081909c02edaa0dae5c56caa69e06edbd 100644 (file)
--- 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 ab09657afc54e950b010689e341c2e9101814cc1..976ea18d875c574f081cfd94c1fcfc0c77ce29a7 100644 (file)
--- 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 );
+                       }
                }
        }
 
index 2091dba8ee7e834649a46b72b902300d90d8e584..d4d61c183782c59ac36ecde162e2b0e17934900e 100644 (file)
--- 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. */
index afe0e4a4d1c65fc1181a3ca2dfd4be9829ff9f24..cbf64727f88e17c96ae55594d92be17200e7a597 100644 (file)
--- 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 145d8dd2cfe181a87b3851c3746077ca3618eaad..94a7075a6f99ccb6f8f18e3682c564afa43c46a5 100644 (file)
--- 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 18d0de8a57f65f2b5dfe74e70707e2392f36e326..43dd66981f5328aaa78370fc5796d064079b0a59 100644 (file)
--- 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 );