diff --git a/src/flexdef.h b/src/flexdef.h index a48c64d1e..474f38c77 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -354,6 +354,8 @@ * of what we think based on references to it in the user's actions. * reject_really_used - same for REJECT * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals + * enumsc - Use enum for start cond (instead of define) + * enumstr - generate the enumsc string table for easier debug printout. */ extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, @@ -368,6 +370,7 @@ extern int yymore_used, reject, real_reject, continued_action, in_rule; extern int yymore_really_used, reject_really_used; extern int trace_hex; +extern int enumsc, enumscstr; /* Variables used in the flex input routines: * datapos - characters on current output line diff --git a/src/main.c b/src/main.c index a4047d7be..844d3f115 100644 --- a/src/main.c +++ b/src/main.c @@ -48,6 +48,7 @@ void set_up_initial_allocations(void); /* these globals are all defined and commented in flexdef.h */ +int enumsc, enumscstr; int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; int interactive, lex_compat, posix_compat, do_yylineno, useecs, fulltbl, usemecs; @@ -461,7 +462,7 @@ void check_options (void) long_align ? "long int" : "short int"); /* Define the start condition macros. */ - { + if(!enumsc){ struct Buf tmpbuf; buf_init(&tmpbuf, sizeof(char)); for (i = 1; i <= lastsc; i++) { @@ -479,6 +480,28 @@ void check_options (void) buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts); buf_destroy(&tmpbuf); } + else /* enumsc=1 */ + { struct Buf tmpbuf; + buf_init(&tmpbuf, sizeof(char)); + + buf_strappend(&tmpbuf, "typedef enum {"); + for (i = 1; i <= lastsc; i++) + { buf_strappend(&tmpbuf, scname[i]); + buf_strappend(&tmpbuf, ","); + } + buf_strappend(&tmpbuf, "} sc_e;"); + if(enumscstr) + { buf_strappend(&tmpbuf, "char *sc_name[]={"); + for (i = 1; i <= lastsc; i++) + { buf_strappend(&tmpbuf, "\""); + buf_strappend(&tmpbuf, scname[i]); + buf_strappend(&tmpbuf, "\","); + } + buf_strappend(&tmpbuf, "};"); + } + buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts); + buf_destroy(&tmpbuf); + } /* This is where we begin writing to the file. */ diff --git a/src/scan.l b/src/scan.l index f4b44b825..ed4f2c3f2 100644 --- a/src/scan.l +++ b/src/scan.l @@ -380,6 +380,8 @@ M4QEND "]""]" debug ddebug = option_sense; default spprdflt = ! option_sense; ecs useecs = option_sense; + enumsc enumsc = option_sense; + enumscstr enumscstr = enumsc = option_sense; fast { useecs = usemecs = false; use_read = fullspd = true;