Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enumsc and enumscstr. #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/flexdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
25 changes: 24 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand All @@ -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. */

Expand Down
2 changes: 2 additions & 0 deletions src/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down