diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 75 |
1 files changed, 58 insertions, 17 deletions
@@ -1,7 +1,11 @@ -/* $Id: main.c,v 1.41 2014/01/01 14:23:27 Christos.Zoulas Exp $ */ +/* $Id: main.c,v 1.49 2014/04/09 21:25:20 Rick.Spates Exp $ */ #include <signal.h> +#ifndef _WIN32 #include <unistd.h> /* for _exit() */ +#else +#include <stdlib.h> /* for _exit() */ +#endif #include "defs.h" @@ -73,21 +77,30 @@ FILE *union_file; /* a temp file, used to save the union */ FILE *verbose_file; /* y.output */ FILE *graph_file; /* y.dot */ -int nitems; -int nrules; -int nsyms; -int ntokens; -int nvars; +Value_t nitems; +Value_t nrules; +Value_t nsyms; +Value_t ntokens; +Value_t nvars; Value_t start_symbol; char **symbol_name; char **symbol_pname; Value_t *symbol_value; -short *symbol_prec; +Value_t *symbol_prec; char *symbol_assoc; int pure_parser; int token_table; + +#if defined(YYBTYACC) +Value_t *symbol_pval; +char **symbol_destructor; +char **symbol_type_tag; +int locations = 0; /* default to no position processing */ +int backtrack = 0; /* default is no backtracking */ +#endif + int exit_code; Value_t *ritem; @@ -116,6 +129,10 @@ done(int k) { DO_CLOSE(input_file); DO_CLOSE(output_file); + if (iflag) + DO_CLOSE(externs_file); + if (rflag) + DO_CLOSE(code_file); DO_CLOSE(action_file); DO_CLOSE(defines_file); @@ -153,9 +170,6 @@ done(int k) reader_leaks(); #endif - if (rflag) - DO_CLOSE(code_file); - exit(k); } @@ -191,11 +205,14 @@ usage(void) "" ,"Options:" ," -b file_prefix set filename prefix (default \"y.\")" - ," -d write definitions (y.tab.h)" + ," -B create a backtracking parser" + ," -d write definitions (" DEFINES_SUFFIX ")" + ," -D enable value stack memory reclamation" ," -i write interface (y.tab.i)" ," -g write a graphical description" ," -l suppress #line directives" - ," -o output_file (default \"y.tab.c\")" + ," -L enable position processing, e.g., \"%locations\"" + ," -o output_file (default \"" OUTPUT_SUFFIX "\")" ," -p symbol_prefix set symbol prefix (default \"yy\")" ," -P create a reentrant parser, e.g., \"%pure-parser\"" ," -r produce separate code and table files (y.code.c)" @@ -219,6 +236,14 @@ setflag(int ch) { switch (ch) { + case 'B': +#if defined(YYBTYACC) + backtrack = 1; +#else + unsupported_flag_warning("-B", "reconfigure with --enable-btyacc"); +#endif + break; + case 'd': dflag = 1; break; @@ -235,6 +260,14 @@ setflag(int ch) lflag = 1; break; + case 'L': +#if defined(YYBTYACC) + locations = 1; +#else + unsupported_flag_warning("-B", "reconfigure with --enable-btyacc"); +#endif + break; + case 'P': pure_parser = 1; break; @@ -364,10 +397,18 @@ allocate(size_t n) } #define CREATE_FILE_NAME(dest, suffix) \ - dest = TMALLOC(char, len + strlen(suffix) + 1); \ - NO_SPACE(dest); \ - strcpy(dest, file_prefix); \ - strcpy(dest + len, suffix) + dest = alloc_file_name(len, suffix) + +static char * +alloc_file_name(size_t len, const char *suffix) +{ + char *result = TMALLOC(char, len + strlen(suffix) + 1); + if (result == 0) + no_space(); + strcpy(result, file_prefix); + strcpy(result + len, suffix); + return result; +} static void create_file_names(void) @@ -384,7 +425,7 @@ create_file_names(void) /* compute the file_prefix from the user provided output_file_name */ if (output_file_name != 0) { - if (!(prefix = strstr(output_file_name, ".tab.c")) + if (!(prefix = strstr(output_file_name, OUTPUT_SUFFIX)) && (prefix = strstr(output_file_name, ".c"))) { defines_suffix = ".h"; |