+++ /dev/null
-/* dlgauto.h automaton\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
- * ANTLR 1.33\r
- * Will Cohen and Terence Parr\r
- * Parr Research Corporation\r
- * with Purdue University and AHPCRC, University of Minnesota\r
- * 1989-1998\r
- */\r
-\r
-#ifndef ZZDEFAUTO_H\r
-#define ZZDEFAUTO_H\r
-\r
-/* 10-Apr-97 133MR1 Uses __USE_PROTOS show should #include pcctscfg.h */\r
-\r
-#include "pcctscfg.h"\r
-\r
-zzchar_t *zzlextext; /* text of most recently matched token */\r
-zzchar_t *zzbegexpr; /* beginning of last reg expr recogn. */\r
-zzchar_t *zzendexpr; /* beginning of last reg expr recogn. */\r
-int zzbufsize = 0; /* number of characters in zzlextext */ /* MR7 */\r
-int zzbegcol = 0; /* column that first character of token is in*/\r
-int zzendcol = 0; /* column that last character of token is in */\r
-int zzline = 1; /* line current token is on */\r
-int zzreal_line=1; /* line of 1st portion of token that is not skipped */\r
-int zzchar; /* character to determine next state */\r
-int zzbufovf; /* indicates that buffer too small for text */\r
-int zzcharfull = 0;\r
-static zzchar_t *zznextpos;/* points to next available position in zzlextext*/\r
-static int zzclass;\r
-\r
-#ifdef __USE_PROTOS\r
-void zzerrstd(const char *);\r
-void (*zzerr)(const char *)=zzerrstd;/* pointer to error reporting function */\r
-extern int zzerr_in(void);\r
-static int (*zzfunc_in)(void) = zzerr_in; /* MR20 */\r
-#else\r
-void zzerrstd();\r
-void (*zzerr)()=zzerrstd; /* pointer to error reporting function */\r
-extern int zzerr_in();\r
-static int (*zzfunc_in)() = zzerr_in; /* MR20 */\r
-#endif\r
-\r
-static FILE *zzstream_in=0;\r
-static zzchar_t *zzstr_in=0;\r
-\r
-#ifdef USER_ZZMODE_STACK\r
-int zzauto = 0;\r
-#else\r
-static int zzauto = 0;\r
-#endif\r
-static int zzadd_erase;\r
-static char zzebuf[70];\r
-\r
-#ifdef ZZCOL\r
-#define ZZINC (++zzendcol)\r
-#else\r
-#define ZZINC\r
-#endif\r
-\r
-\r
-#define ZZGETC_STREAM {zzchar = getc(zzstream_in); zzclass = ZZSHIFT(zzchar);}\r
-#define ZZGETC_FUNC {zzchar = (*zzfunc_in)(); zzclass = ZZSHIFT(zzchar);}\r
-#define ZZGETC_STR { \\r
- if (*zzstr_in){ \\r
- zzchar = *zzstr_in; \\r
- ++zzstr_in; \\r
- }else{ \\r
- zzchar = EOF; \\r
- } \\r
- zzclass = ZZSHIFT(zzchar); \\r
-}\r
-\r
-#define ZZNEWSTATE (newstate = dfa[state][zzclass])\r
-\r
-#ifndef ZZCOPY\r
-#define ZZCOPY \\r
- /* Truncate matching buffer to size (not an error) */ \\r
- if (zznextpos < lastpos){ \\r
- *(zznextpos++) = zzchar; \\r
- }else{ \\r
- zzbufovf = 1; \\r
- }\r
-#endif\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzrdstream( FILE *f )\r
-#else\r
-zzrdstream( f )\r
-FILE *f;\r
-#endif\r
-{\r
- /* make sure that it is really set to something, otherwise just\r
- leave it be.\r
- */\r
- if (f){\r
- /* make sure that there is always someplace to get input\r
- before closing zzstream_in\r
- */\r
-#if 0\r
- if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
-#endif\r
- zzline = 1;\r
- zzstream_in = f;\r
- zzfunc_in = NULL;\r
- zzstr_in = 0;\r
- zzcharfull = 0;\r
- }\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzrdfunc( int (*f)(void) )\r
-#else\r
-zzrdfunc( f )\r
-int (*f)();\r
-#endif\r
-{\r
- /* make sure that it is really set to something, otherwise just\r
- leave it be.\r
- */\r
- if (f){\r
- /* make sure that there is always someplace to get input\r
- before closing zzstream_in\r
- */\r
-#if 0\r
- if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
-#endif\r
- zzline = 1;\r
- zzstream_in = NULL;\r
- zzfunc_in = f;\r
- zzstr_in = 0;\r
- zzcharfull = 0;\r
- }\r
-}\r
-\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzrdstr( zzchar_t *s )\r
-#else\r
-zzrdstr( s )\r
-zzchar_t *s;\r
-#endif\r
-{\r
- /* make sure that it is really set to something, otherwise just\r
- leave it be.\r
- */\r
- if (s){\r
- /* make sure that there is always someplace to get input\r
- before closing zzstream_in\r
- */\r
-#if 0\r
- if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
-#endif\r
- zzline = 1;\r
- zzstream_in = NULL;\r
- zzfunc_in = 0;\r
- zzstr_in = s;\r
- zzcharfull = 0;\r
- }\r
-}\r
-\r
-\r
-#ifdef __USE_PROTOS\r
-void zzclose_stream(void)\r
-#else\r
-void zzclose_stream()\r
-#endif\r
-{\r
-#if 0\r
- fclose( zzstream_in );\r
- zzstream_in = NULL;\r
- zzfunc_in = NULL;\r
-#endif\r
-}\r
-\r
-/* saves dlg state, but not what feeds dlg (such as file position) */\r
-void\r
-#ifdef __USE_PROTOS\r
-zzsave_dlg_state(struct zzdlg_state *state)\r
-#else\r
-zzsave_dlg_state(state)\r
-struct zzdlg_state *state;\r
-#endif\r
-{\r
- state->stream = zzstream_in;\r
- state->func_ptr = zzfunc_in;\r
- state->str = zzstr_in;\r
- state->auto_num = zzauto;\r
- state->add_erase = zzadd_erase;\r
- state->lookc = zzchar;\r
- state->char_full = zzcharfull;\r
- state->begcol = zzbegcol;\r
- state->endcol = zzendcol;\r
- state->line = zzline;\r
- state->lextext = zzlextext;\r
- state->begexpr = zzbegexpr;\r
- state->endexpr = zzendexpr;\r
- state->bufsize = zzbufsize;\r
- state->bufovf = zzbufovf;\r
- state->nextpos = zznextpos;\r
- state->class_num = zzclass;\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzrestore_dlg_state(struct zzdlg_state *state)\r
-#else\r
-zzrestore_dlg_state(state)\r
-struct zzdlg_state *state;\r
-#endif\r
-{\r
- zzstream_in = state->stream;\r
- zzfunc_in = state->func_ptr;\r
- zzstr_in = state->str;\r
- zzauto = state->auto_num;\r
- zzadd_erase = state->add_erase;\r
- zzchar = state->lookc;\r
- zzcharfull = state->char_full;\r
- zzbegcol = state->begcol;\r
- zzendcol = state->endcol;\r
- zzline = state->line;\r
- zzlextext = state->lextext;\r
- zzbegexpr = state->begexpr;\r
- zzendexpr = state->endexpr;\r
- zzbufsize = state->bufsize;\r
- zzbufovf = state->bufovf;\r
- zznextpos = state->nextpos;\r
- zzclass = state->class_num;\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzmode( int m )\r
-#else\r
-zzmode( m )\r
-int m;\r
-#endif\r
-{\r
- /* points to base of dfa table */\r
- if (m<MAX_MODE){\r
- zzauto = m;\r
- /* have to redo class since using different compression */\r
- zzclass = ZZSHIFT(zzchar);\r
- }else{\r
- sprintf(zzebuf,"Invalid automaton mode = %d ",m);\r
- zzerr(zzebuf);\r
- }\r
-}\r
-\r
-/* erase what is currently in the buffer, and get a new reg. expr */\r
-\r
-#ifdef __USE_PROTOS\r
-void zzskip(void)\r
-#else\r
-void zzskip()\r
-#endif\r
-{\r
- zzadd_erase = 1;\r
-}\r
-\r
-/* don't erase what is in the zzlextext buffer, add on to it */\r
-#ifdef __USE_PROTOS\r
-void zzmore()\r
-#else\r
-void zzmore()\r
-#endif\r
-{\r
- zzadd_erase = 2;\r
-}\r
-\r
-/* substitute c for the reg. expr last matched and is in the buffer */\r
-#ifdef __USE_PROTOS\r
-void\r
-zzreplchar(zzchar_t c)\r
-#else\r
-void\r
-zzreplchar(c)\r
-zzchar_t c;\r
-#endif\r
-{\r
- /* can't allow overwriting null at end of string */\r
- if (zzbegexpr < &zzlextext[zzbufsize-1]){\r
- *zzbegexpr = c;\r
- *(zzbegexpr+1) = '\0';\r
- }\r
- zzendexpr = zzbegexpr;\r
- zznextpos = zzbegexpr + 1;\r
-}\r
-\r
-/* replace the string s for the reg. expr last matched and in the buffer */\r
-void\r
-#ifdef __USE_PROTOS\r
-zzreplstr(register zzchar_t *s)\r
-#else\r
-zzreplstr(s)\r
-register zzchar_t *s;\r
-#endif\r
-{\r
- register zzchar_t *l= &zzlextext[zzbufsize -1];\r
-\r
- zznextpos = zzbegexpr;\r
- if (s){\r
- while ((zznextpos <= l) && (*(zznextpos++) = *(s++))!=0){\r
- /* empty */\r
- }\r
- /* correct for NULL at end of string */\r
- zznextpos--;\r
- }\r
- if ((zznextpos <= l) && (*(--s) == 0)){\r
- zzbufovf = 0;\r
- }else{\r
- zzbufovf = 1;\r
- }\r
- *(zznextpos) = '\0';\r
- zzendexpr = zznextpos - 1;\r
-}\r
-\r
-#ifdef __USE_PROTOS\r
-void zzgettok(void)\r
-#else\r
-void zzgettok()\r
-#endif\r
-{\r
- register int state, newstate;\r
- /* last space reserved for the null char */\r
- register zzchar_t *lastpos;\r
-\r
-skip:\r
- zzreal_line = zzline;\r
- zzbufovf = 0;\r
- lastpos = &zzlextext[zzbufsize-1];\r
- zznextpos = zzlextext;\r
- zzbegcol = zzendcol+1;\r
-more:\r
- zzbegexpr = zznextpos;\r
-#ifdef ZZINTERACTIVE\r
- /* interactive version of automaton */\r
- /* if there is something in zzchar, process it */\r
- state = newstate = dfa_base[zzauto];\r
- if (zzcharfull){\r
- ZZINC;\r
- ZZCOPY;\r
- ZZNEWSTATE;\r
- }\r
- if (zzstr_in)\r
- while (zzalternatives[newstate]){\r
- state = newstate;\r
- ZZGETC_STR;\r
- ZZINC;\r
- ZZCOPY;\r
- ZZNEWSTATE;\r
- }\r
- else if (zzstream_in)\r
- while (zzalternatives[newstate]){\r
- state = newstate;\r
- ZZGETC_STREAM;\r
- ZZINC;\r
- ZZCOPY;\r
- ZZNEWSTATE;\r
- }\r
- else if (zzfunc_in)\r
- while (zzalternatives[newstate]){\r
- state = newstate;\r
- ZZGETC_FUNC;\r
- ZZINC;\r
- ZZCOPY;\r
- ZZNEWSTATE;\r
- }\r
- /* figure out if last character really part of token */\r
- if ((state != dfa_base[zzauto]) && (newstate == DfaStates)){\r
- zzcharfull = 1;\r
- --zznextpos;\r
- }else{\r
- zzcharfull = 0;\r
- state = newstate;\r
- }\r
- *(zznextpos) = '\0';\r
- /* Able to transition out of start state to some non err state?*/\r
- if ( state == dfa_base[zzauto] ){\r
- /* make sure doesn't get stuck */\r
- zzadvance();\r
- }\r
-#else\r
- /* non-interactive version of automaton */\r
- if (!zzcharfull)\r
- zzadvance();\r
- else\r
- ZZINC;\r
- state = dfa_base[zzauto];\r
- if (zzstr_in)\r
- while (ZZNEWSTATE != DfaStates){\r
- state = newstate;\r
- ZZCOPY;\r
- ZZGETC_STR;\r
- ZZINC;\r
- }\r
- else if (zzstream_in)\r
- while (ZZNEWSTATE != DfaStates){\r
- state = newstate;\r
- ZZCOPY;\r
- ZZGETC_STREAM;\r
- ZZINC;\r
- }\r
- else if (zzfunc_in)\r
- while (ZZNEWSTATE != DfaStates){\r
- state = newstate;\r
- ZZCOPY;\r
- ZZGETC_FUNC;\r
- ZZINC;\r
- }\r
- zzcharfull = 1;\r
- if ( state == dfa_base[zzauto] ){\r
- if (zznextpos < lastpos){\r
- *(zznextpos++) = zzchar;\r
- }else{\r
- zzbufovf = 1;\r
- }\r
- *zznextpos = '\0';\r
- /* make sure doesn't get stuck */\r
- zzadvance();\r
- }else{\r
- *zznextpos = '\0';\r
- }\r
-#endif\r
-#ifdef ZZCOL\r
- zzendcol -= zzcharfull;\r
-#endif\r
- zzendexpr = zznextpos -1;\r
- zzadd_erase = 0;\r
- (*actions[accepts[state]])();\r
- switch (zzadd_erase) {\r
- case 1: goto skip;\r
- case 2: goto more;\r
- }\r
-}\r
-\r
-#ifdef __USE_PROTOS\r
-void zzadvance(void)\r
-#else\r
-void zzadvance()\r
-#endif\r
-{\r
- if (zzstream_in) { ZZGETC_STREAM; zzcharfull = 1; ZZINC;}\r
- if (zzfunc_in) { ZZGETC_FUNC; zzcharfull = 1; ZZINC;}\r
- if (zzstr_in) { ZZGETC_STR; zzcharfull = 1; ZZINC;}\r
- if (!(zzstream_in || zzfunc_in || zzstr_in)){\r
- zzerr_in();\r
- }\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-zzerrstd(const char *s)\r
-#else\r
-zzerrstd(s)\r
-char *s;\r
-#endif\r
-{\r
- zzLexErrCount++; /* MR11 */\r
- fprintf(stderr,\r
- "%s near line %d (text was '%s')\n",\r
- ((s == NULL) ? "Lexical error" : s),\r
- zzline,zzlextext);\r
-}\r
-\r
-#ifdef __USE_PROTOS\r
-int zzerr_in(void)\r
-#else\r
-int zzerr_in()\r
-#endif\r
-{\r
- fprintf(stderr,"No input stream, function, or string\n");\r
- /* return eof to get out gracefully */\r
- return EOF;\r
-}\r
-\r
-#endif\r