+++ /dev/null
-/* Main function for dlg version\r
- *\r
- * SOFTWARE RIGHTS\r
- *\r
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
- * company may do whatever they wish with source code distributed with\r
- * PCCTS or the code generated by PCCTS, including the incorporation of\r
- * PCCTS, or its output, into commerical software.\r
- *\r
- * We encourage users to develop software with PCCTS. However, we do ask\r
- * that credit is given to us for developing PCCTS. By "credit",\r
- * we mean that if you incorporate our source code into one of your\r
- * programs (commercial product, research project, or otherwise) that you\r
- * acknowledge this fact somewhere in the documentation, research report,\r
- * etc... If you like PCCTS and have developed a nice tool with the\r
- * output, please mention that you developed it using PCCTS. In\r
- * addition, we ask that this header remain intact in our source code.\r
- * As long as these guidelines are kept, we expect to continue enhancing\r
- * this system and expect to make other tools available as they are\r
- * completed.\r
- *\r
- * DLG 1.33\r
- * Will Cohen\r
- * With mods by Terence Parr; AHPCRC, University of Minnesota\r
- * 1989-2001\r
- */\r
-\r
-#include <stdio.h>\r
-#include "stdpccts.h"\r
-\r
-char program[] = "dlg";\r
-char version[] = "1.33MR33"; /* MRXXX */\r
-int numfiles = 0;\r
-char *file_str[2] = {NULL, NULL};\r
-char *mode_file = "mode.h";\r
-char *class_name = DEFAULT_CLASSNAME;\r
-char *OutputDirectory = TopDirectory;\r
-\r
-/* Option variables */\r
-int comp_level = 0;\r
-int interactive = FALSE;\r
-int case_insensitive = FALSE;\r
-int warn_ambig = FALSE;\r
-int gen_cpp = FALSE;\r
-\r
-#ifdef __USE_PROTOS\r
-static int ci_strequ(char *a,char *b)\r
-#else\r
-static int ci_strequ(a,b)\r
- char *a;\r
- char *b;\r
-#endif\r
-{\r
- for ( ;*a != 0 && *b != 0; a++, b++) {\r
- if (toupper(*a) != toupper(*b)) return 0;\r
- }\r
- return (*a == *b);\r
-}\r
-\r
-/* Option List Stuff */\r
-#ifdef __USE_PROTOS\r
-void p_comp0(void) {comp_level = 0;}\r
-void p_comp1(void) {comp_level = 1;}\r
-void p_comp2(void) {comp_level = 2;}\r
-void p_stdio(void) { file_str[numfiles++] = NULL;}\r
-void p_file(char *s) { file_str[numfiles++] = s;}\r
-void p_cl_name(char *s, char *t)\r
- {\r
- if ( gen_cpp ) {\r
- class_name = t;\r
- }\r
- else {\r
- warning("-cl only valid in C++ mode; -cl ignored...",0);\r
- }\r
- }\r
-void p_mode_file(char *s, char *t){mode_file=t;}\r
-void p_outdir(char *s,char *t) {OutputDirectory=t;}\r
-void p_ansi(void) {gen_ansi = TRUE;}\r
-void p_interactive(void) {interactive = TRUE;}\r
-void p_case_s(void) { case_insensitive = FALSE; }\r
-void p_case_i(void) { case_insensitive = TRUE; }\r
-void p_warn_ambig(void) { warn_ambig = TRUE; }\r
-void p_cpp(void) { gen_cpp = TRUE; }\r
-#else\r
-void p_comp0() {comp_level = 0;}\r
-void p_comp1() {comp_level = 1;}\r
-void p_comp2() {comp_level = 2;}\r
-void p_stdio() { file_str[numfiles++] = NULL;}\r
-void p_file(s) char *s; { file_str[numfiles++] = s;}\r
-void p_cl_name(s,t)\r
- char *s, *t;\r
- {\r
- if ( gen_cpp ) {\r
- class_name = t;\r
- }\r
- else {\r
- warning("-cl only valid in C++ mode; -cl ignored...",0);\r
- }\r
- }\r
-void p_mode_file(s,t) char *s,*t;{mode_file=t;}\r
-void p_outdir(s,t) char *s,*t;{OutputDirectory=t;}\r
-void p_ansi() {gen_ansi = TRUE;}\r
-void p_interactive() {interactive = TRUE;}\r
-void p_case_s() { case_insensitive = FALSE; }\r
-void p_case_i() { case_insensitive = TRUE; }\r
-void p_warn_ambig() { warn_ambig = TRUE; }\r
-void p_cpp() { gen_cpp = TRUE; }\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-typedef void (*WildFunc)(...);\r
-#else\r
-typedef void (*WildFunc)();\r
-#endif\r
-\r
-typedef struct {\r
- char *option;\r
- int arg;\r
- WildFunc process;\r
- char *descr;\r
- } Opt;\r
-\r
-Opt options[] = {\r
- { "-CC", 0, (WildFunc)p_cpp, "Generate C++ output" },\r
- { "-C0", 0, (WildFunc)p_comp0, "No compression (default)" },\r
- { "-C1", 0, (WildFunc)p_comp1, "Compression level 1" },\r
- { "-C2", 0, (WildFunc)p_comp2, "Compression level 2" },\r
- { "-ga", 0, (WildFunc)p_ansi, "Generate ansi C"},\r
- { "-Wambiguity", 0, (WildFunc)p_warn_ambig, "Warn if expressions ambiguous"},\r
- { "-m", 1, (WildFunc)p_mode_file, "Rename lexical mode output file"},\r
- { "-i", 0, (WildFunc)p_interactive, "Build interactive scanner (not valid for C++ mode)"},\r
- { "-ci", 0, (WildFunc)p_case_i, "Make lexical analyzer case insensitive"},\r
- { "-cl", 1, (WildFunc)p_cl_name, "Rename lexer class (DLGLexer); only used for -CC"},\r
- { "-cs", 0, (WildFunc)p_case_s, "Make lexical analyzer case sensitive (default)"},\r
- { "-o", 1, (WildFunc)p_outdir, OutputDirectoryOption},\r
- { "-", 0, (WildFunc)p_stdio, "Use standard i/o rather than file"},\r
- { "*", 0, (WildFunc)p_file, ""}, /* anything else is a file */\r
- { NULL, 0, NULL } \r
- };\r
-\r
-#ifdef __USE_PROTOS\r
-void ProcessArgs(int argc, char **argv, Opt *options)\r
-#else\r
-void ProcessArgs(argc, argv, options)\r
-int argc;\r
-char **argv;\r
-Opt *options;\r
-#endif\r
-{\r
- Opt *p;\r
- \r
- while ( argc-- > 0 )\r
- {\r
- p = options;\r
- while ( p->option != NULL )\r
- {\r
- if ( strcmp(p->option, "*") == 0 ||\r
- ci_strequ(p->option,*argv) )\r
- {\r
- if ( p->arg )\r
- {\r
- (*p->process)( *argv, *(argv+1) );\r
- argv++;\r
- argc--;\r
- }\r
- else\r
- (*p->process)( *argv );\r
- break;\r
- }\r
- p++;\r
- }\r
- argv++;\r
- }\r
-}\r
-\r
-#ifdef __USE_PROTOS\r
-int main(int argc, char *argv[])\r
-#else\r
-int main(argc, argv)\r
-int argc;\r
-char *argv[];\r
-#endif\r
-{\r
- init();\r
- fprintf(stderr, "%s Version %s 1989-2001\n", &(program[0]),\r
- &(version[0]));\r
- if ( argc == 1 )\r
- {\r
- Opt *p = options;\r
- fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);\r
- while ( *(p->option) != '*' )\r
- {\r
- fprintf(stderr, "\t%s %s\t%s\n",\r
- p->option,\r
- (p->arg)?"___":" ",\r
- p->descr);\r
- p++;\r
- }\r
- }else{\r
- ProcessArgs(argc-1, &(argv[1]), options);\r
- if (interactive && gen_cpp) {\r
- fprintf(stderr,"\n");\r
-/*** MR21a This statement is wrong ! ***/\r
-#if 0\r
-*** fprintf(stderr,"Interactive lexer option (\"-i\") has no effect when in C++ mode\n");\r
-*** fprintf(stderr,"because of extra buffering provided by ANTLRTokenBuffer class.\n");\r
-*** fprintf(stderr,"\n");\r
-#endif\r
- }\r
- input_stream = read_stream(file_str[0]);\r
- if (input_stream) {\r
- /* don't overwrite unless input okay */\r
- if ( gen_cpp ) {\r
- output_stream = write_stream(ClassName(CPP_FILE_SUFFIX));\r
- if ( file_str[1]!=NULL ) {\r
- warning("output file implicit in C++ mode; ignored...",0);\r
- }\r
- class_stream = write_stream(ClassName(".h"));\r
- mode_stream = class_stream;\r
- }\r
- else {\r
- output_stream = write_stream(file_str[1]);\r
- mode_stream = write_stream(mode_file);\r
- }\r
- }\r
- /* make sure that error reporting routines in grammar\r
- know what the file really is */\r
- /* make sure that reading and writing somewhere */\r
- if (input_stream && output_stream && mode_stream){\r
- ANTLR(grammar(), input_stream);\r
- }\r
- p_class_def2(); /* MR1 */\r
- }\r
- if ( output_stream!=NULL ) fclose(output_stream);\r
- if ( !gen_cpp && mode_stream!=NULL ) fclose(mode_stream);\r
- if ( class_stream!=NULL ) fclose(class_stream);\r
- exit(PCCTS_EXIT_SUCCESS);\r
- return 0; /* get rid of warning message MR1 */\r
-}\r
-\r
-/* initialize all the variables */\r
-void \r
-#ifdef __USE_PROTOS\r
-init(void)\r
-#else\r
-init()\r
-#endif\r
-{\r
- register int i;\r
-\r
-#ifdef SPECIAL_INITS\r
- special_inits(); /* MR1 */\r
-#endif\r
- used_chars = empty;\r
- used_classes = empty;\r
- /* make the valid character set */\r
- normal_chars = empty;\r
- /* NOTE: MIN_CHAR is EOF */\r
- /* NOTE: EOF is not quite a valid char, it is special. Skip it*/\r
- for (i = 1; i<CHAR_RANGE; ++i){\r
- set_orel(i,&normal_chars);\r
- }\r
- make_nfa_model_node();\r
- clear_hash();\r
- /* NOTE: need to set this flag before the lexer starts getting */\r
- /* tokens */\r
- func_action = FALSE; \r
-}\r
-\r
-/* stuff that needs to be reset when a new automaton is being built */\r
-void \r
-#ifdef __USE_PROTOS\r
-new_automaton_mode(void) /* MR1 */\r
-#else\r
-new_automaton_mode() /* MR1 */\r
-#endif\r
-{\r
- set_free(used_chars);\r
- clear_hash();\r
-}\r