err.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/*
* err.h
*
* Standard error handling mechanism
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* Has grown to hold all kinds of stuff (err.h is increasingly misnamed)
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ERR_H
#define ERR_H
#include "pcctscfg.h"
#include <stdlib.h>
#include <assert.h>
/* */
/* 7-Apr-97 133MR1 */
/* Proper choice of STDC and cplusplus pre-processor symbols (?) */
/* */
#include "pccts_string.h"
#ifdef PCCTS_USE_STDARG
#include "pccts_stdarg.h"
#else
#include <varargs.h>
#endif
#ifdef DUM
/* Define usable bits per unsigned int word (used for set stuff) */
#ifdef PC
#define BSETWORDSIZE 16
#define BSETLOGWORDSIZE 4
#else
#define BSETWORDSIZE 32
#define BSETLOGWORDSIZE 5
#endif
#endif
#define BSETWORDSIZE 8
/* This is not put into the global pccts_parser structure because it is
* hidden and does not need to be saved during a "save state" operation
*/
static SetWordType bitmask[] = {
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080
};
#ifdef zzTRACE_RULES
int zzTraceOptionValueDefault=1;
int zzTraceOptionValue=1;
int zzTraceGuessOptionValue=1;
char *zzTraceCurrentRuleName=NULL;
int zzTraceDepth=0;
#endif
int zzGuessSeq=0; /* MR10 */
int zzSyntaxErrCount=0; /* MR11 */
int zzLexErrCount=0; /* MR11 */
void
#ifdef __USE_PROTOS
#else
#endif
{
static int consumed = 1;
/* if you enter here without having consumed a token from last resynch
* force a token consumption.
*/
/* if current token is in resynch set, we've got what we wanted */
/* scan until we find something in the resynch set */
consumed=1;
}
/* */
/* 7-Apr-97 133MR1 for C++ and MR7 for C */
/* Change suggested by Eli Sternheim (eli@interhdl.com) */
/* */
void
#ifdef __USE_PROTOS
#else
#endif
{
int tmp; /* MR7 */
zzCONSUME; } /* MR7 */
}
/* */
/* 7-Apr-97 133MR1 for C++ and MR7 for C */
/* Change suggested by Eli Sternheim (eli@interhdl.com) */
/* */
void
#ifdef __USE_PROTOS
zzconsumeUntilToken(int t)
#else
int t;
#endif
{
int tmp; /* MR7 */
}
/* input looks like:
* zzFAIL(k, e1, e2, ...,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText)
* where the zzMiss stuff is set here to the token that did not match
* (and which set wasn't it a member of).
*/
#ifdef PCCTS_USE_STDARG
void zzFAIL(int k, ...)
#else
#endif
{
#ifdef LL_K
SetWordType *f[LL_K];
#else
SetWordType *f[1];
#endif
char **miss_text;
int *bad_tok;
char **bad_text;
int *err_k;
int i;
#ifndef PCCTS_USE_STDARG /* MR20 */
int k;
#endif
#ifdef PCCTS_USE_STDARG /* MR20 */
#else
#endif
assert(k <= sizeof(f)/sizeof(f[0])); /* MR20 G. Hobbelt */
text[0] = '\0';
for (i=1; i<=k; i++) /* collect all lookahead sets */
{
}
for (i=1; i<=k; i++) /* look for offending token */
{
}
if ( i>k )
{
/* bad; lookahead is permutation that cannot be matched,
* but, the ith token of lookahead is valid at the ith position
* (The old LL sub 1 (k) versus LL(k) parsing technique)
*/
*err_k = k;
return;
}
/* fprintf(stderr, "%s not in %dth set\n", zztokens[LA(i)], i);*/
*miss_set = f[i-1];
else *err_k = k;
}
#ifdef __USE_PROTOS
#else
void zzTraceGuessDone(state)
#endif
{
#ifdef zzTRACE_RULES
#ifdef ZZCAN_GUESS
int doIt=0;
if (zzTraceCurrentRuleName == NULL) return;
if (zzTraceOptionValue <= 0) {
doIt=0;
} else if (zzTraceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
LATEXT(1),
state->traceDepth);
} else {
};
};
#endif
#endif
}
void
#ifdef __USE_PROTOS
#else
#endif
{
#ifdef LL_K
int i;
#endif
#ifdef ZZCAN_GUESS
#endif
#ifdef GENAST
#endif
#ifdef ZZINF_LOOK
/* MR6 Gunnar Rxnning (gunnar@candleweb.no) */
#endif
#ifdef DEMAND_LOOK
#endif
#ifdef LL_K
#else
#endif
#ifdef zzTRACE_RULES
/* MR10 */
#endif
}
void
#ifdef __USE_PROTOS
#else
#endif
{
#ifdef zzTRACE_RULES
int prevTraceOptionValue;
#endif
#ifdef LL_K
int i;
#endif
#ifdef ZZCAN_GUESS
#endif
#ifdef GENAST
#endif
#ifdef ZZINF_LOOK
/* MR6 Gunnar Rxnning (gunnar@candleweb.no) */
#endif
#ifdef DEMAND_LOOK
#endif
#ifdef LL_K
#else
#endif
#ifdef zzTRACE_RULES
if ( (prevTraceOptionValue > 0) !=
(zzTraceOptionValue > 0)) {
if (zzTraceOptionValue > 0) {
};
if (zzTraceOptionValue <= 0) {
};
};
#endif
}
void
#ifdef __USE_PROTOS
zzedecode(SetWordType *a)
#else
zzedecode(a)
SetWordType *a;
#endif
{
register SetWordType *p = a;
register unsigned e = 0;
do {
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
e++;
} while (++p < endp);
}
#ifndef USER_ZZSYN
/* standard error reporting function */
void
#ifdef __USE_PROTOS
#else
int tok;
int etok;
int k;
#endif
{
zzSyntaxErrCount++; /* MR11 */
else
{
}
}
#endif
/* is b an element of set p? */
int
#ifdef __USE_PROTOS
zzset_el(unsigned b, SetWordType *p)
#else
zzset_el(b,p)
unsigned b;
SetWordType *p;
#endif
{
}
int
#ifdef __USE_PROTOS
zzset_deg(SetWordType *a)
#else
zzset_deg(a)
SetWordType *a;
#endif
{
/* Fast compute degree of a set... the number
of elements present in the set. Assumes
that all word bits are used in the set
*/
register SetWordType *p = a;
register int degree = 0;
if ( a == NULL ) return 0;
while ( p < endp )
{
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
if (t & *b) ++degree;
p++;
}
return(degree);
}
#ifdef DEMAND_LOOK
#ifdef LL_K
int
#ifdef __USE_PROTOS
#else
int _t;
char **zzBadText;
char **zzMissText;
#endif
{
}
return 0;
}
zzdirty++;
zzlabase++;
return 1;
}
int
#ifdef __USE_PROTOS
_zzmatch_wsig(int _t)
#else
int _t;
#endif
{
}
return 0;
}
zzdirty++;
zzlabase++;
return 1;
}
#else
int
#ifdef __USE_PROTOS
#else
int _t;
char **zzBadText;
char **zzMissText;
#endif
{
return 0;
}
zzdirty = 1;
return 1;
}
int
#ifdef __USE_PROTOS
_zzmatch_wsig(int _t)
#else
int _t;
#endif
{
return 0;
}
zzdirty = 1;
return 1;
}
#endif /*LL_K*/
#else
int
#ifdef __USE_PROTOS
#else
int _t;
char **zzBadText;
char **zzMissText;
#endif
{
return 0;
}
return 1;
}
int
#ifdef __USE_PROTOS
_zzmatch_wsig(int _t)
#else
int _t;
#endif
{
return 1;
}
#endif /*DEMAND_LOOK*/
#ifdef ZZINF_LOOK
void
#ifdef __USE_PROTOS
_inf_zzgettok(void)
#else
#endif
{
if ( zzinf_labase >= zzinf_last )
else {
zzinf_labase++;
}
}
#endif
#ifdef ZZINF_LOOK
/* allocate default size text,token and line arrays;
* then, read all of the input reallocing the arrays as needed.
* Once the number of total tokens is known, the LATEXT(i) array (zzinf_text)
* is allocated and it's pointers are set to the tokens in zzinf_text_buffer.
*/
void
#ifdef __USE_PROTOS
zzfill_inf_look(void)
#else
#endif
{
int zzinf_text_buffer_index = 0;
int zzinf_lap = 0;
if ( zzinf_text_buffer == NULL )
{
}
if ( zzinf_tokens == NULL )
{
}
if ( zzinf_line == NULL )
{
}
/* get tokens, copying text to text buffer */
do {
zzgettok();
line = zzreal_line;
while ( zzinf_lap>=zzinf_token_buffer_size )
{
zzinf_token_buffer_size*sizeof(int));
if ( zzinf_tokens == NULL )
{
}
zzinf_token_buffer_size*sizeof(int));
if ( zzinf_line == NULL )
{
}
}
{
if ( zzinf_text_buffer == NULL )
{
}
}
/* record token and text and line of input symbol */
zzinf_lap++;
} while (tok!=zzEOF_TOKEN);
zzinf_labase = 0;
/* allocate ptrs to text of ith token */
if ( zzinf_text == NULL )
{
}
zzinf_lap = 0;
/* set ptrs so that zzinf_text[i] is the text of the ith token found on input */
while (zzinf_lap<=zzinf_last)
{
}
}
#endif
int
#ifdef __USE_PROTOS
#else
SetWordType *e;
char **zzBadText;
char **zzMissText;
#endif
{
#ifdef DEMAND_LOOK
#ifdef LL_K
#else
#endif
#endif
return 0;
}
zzMakeAttr /* MR14 Ger Hobbelt (hobbelt@axa.nl) */
#ifdef DEMAND_LOOK
#ifdef LL_K
zzdirty++;
zzlabase++; /* MR14 Ger Hobbelt (hobbelt@axa.nl) */
#else
zzdirty = 1;
#endif
#endif
return 1;
}
int
#ifdef __USE_PROTOS
#else
int tokenWanted;
#endif
{
#ifdef DEMAND_LOOK
#ifdef LL_K
}
#else
#endif
#endif
{
zzSyntaxErrCount++; /* MR11 */
"line %d: syntax error at \"%s\" missing %s\n",
return 0;
}
else {
#ifdef DEMAND_LOOK
#ifdef LL_K
zzdirty++;
zzlabase++;
#else
zzdirty = 1;
#endif
#else
/* zzCONSUME; consume if not demand lookahead */
#endif
return 1;
}
}
int
#ifdef __USE_PROTOS
int tokenTypeOfSet,
#else
int tokenTypeOfSet;
#endif
{
#ifdef DEMAND_LOOK
#ifdef LL_K
#else
#endif
#endif
{
zzSyntaxErrCount++; /* MR11 */
"line %d: syntax error at \"%s\" missing %s\n",
return 0;
}
else {
#ifdef DEMAND_LOOK
#ifdef LL_K
zzdirty++;
zzlabase++;
#else
zzdirty = 1;
#endif
#else
/* zzCONSUME; consume if not demand lookahead */
#endif
return 1;
}
}
int
#ifdef __USE_PROTOS
#else
SetWordType *e;
#endif
{
#ifdef DEMAND_LOOK
#ifdef LL_K
#else
#endif
#endif
zzMakeAttr /* MR14 Ger Hobbelt (hobbelt@axa.nl) */
#ifdef DEMAND_LOOK
#ifdef LL_K
zzdirty++;
zzlabase++; /* MR14 Ger Hobbelt (hobbelt@axa.nl) */
#else
zzdirty = 1;
#endif
#endif
return 1;
}
#ifdef USER_ZZMODE_STACK
static int zzmdep = 0;
static char zzmbuf[70];
void
#ifdef __USE_PROTOS
zzmpush( int m )
#else
zzmpush( m )
int m;
#endif
{
} else {
zzmode(m);
}
}
void
#ifdef __USE_PROTOS
zzmpop( void )
#else
zzmpop( )
#endif
{
if(zzmdep == 0)
}
else
{ zzmdep--;
}
}
void
#ifdef __USE_PROTOS
#else
int modeStack[];
int *modeLevel;
#endif
{
int i;
zzmdep = 0;
return;
}
void
#ifdef __USE_PROTOS
#else
int modeStack[];
int *modeLevel;
#endif
{
int i;
return;
}
#endif /* USER_ZZMODE_STACK */
#ifdef __USE_PROTOS
void zzTraceReset(void)
#else
void zzTraceReset()
#endif
{
#ifdef zzTRACE_RULES
zzTraceDepth=0;
#endif
}
#ifdef __USE_PROTOS
void zzTraceGuessFail(void)
#else
void zzTraceGuessFail()
#endif
{
#ifdef zzTRACE_RULES
#ifdef ZZCAN_GUESS
int doIt=0;
if (zzTraceOptionValue <= 0) {
doIt=0;
} else if (zzguessing && zzTraceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
};
#endif
#endif
}
/* zzTraceOption:
zero value turns off trace
*/
#ifdef __USE_PROTOS
#else
char *rule;
#endif
{
#ifdef zzTRACE_RULES
int doIt=0;
zzTraceDepth++;
if (zzTraceOptionValue <= 0) {
doIt=0;
#ifdef ZZCAN_GUESS
} else if (zzguessing && zzTraceGuessOptionValue <= 0) {
doIt=0;
#endif
} else {
doIt=1;
};
if (doIt) {
rule,
#ifdef ZZCAN_GUESS
#endif
};
#endif
return;
}
#ifdef __USE_PROTOS
void zzTraceOut(char * rule)
#else
void zzTraceOut(rule)
char *rule;
#endif
{
#ifdef zzTRACE_RULES
int doIt=0;
zzTraceDepth--;
if (zzTraceOptionValue <= 0) {
doIt=0;
#ifdef ZZCAN_GUESS
} else if (zzguessing && zzTraceGuessOptionValue <= 0) {
doIt=0;
#endif
} else {
doIt=1;
};
if (doIt) {
rule,
zzTraceDepth+1);
#ifdef ZZCAN_GUESS
#endif
};
#endif
}
#ifdef __USE_PROTOS
int zzTraceOption(int delta)
#else
int zzTraceOption(delta)
int delta;
#endif
{
#ifdef zzTRACE_RULES
if (zzTraceCurrentRuleName != NULL) {
if (prevValue <= 0 && zzTraceOptionValue > 0) {
};
if (prevValue > 0 && zzTraceOptionValue <= 0) {
};
};
return prevValue;
#else
return 0;
#endif
}
#ifdef __USE_PROTOS
int zzTraceGuessOption(int delta)
#else
int zzTraceGuessOption(delta)
int delta;
#endif
{
#ifdef zzTRACE_RULES
#ifdef ZZCAN_GUESS
if (zzTraceCurrentRuleName != NULL) {
if (prevValue <= 0 && zzTraceGuessOptionValue > 0) {
};
if (prevValue > 0 && zzTraceGuessOptionValue <= 0) {
};
};
return prevValue;
#else
return 0;
#endif
#else
return 0;
#endif
}
#endif /* ERR_H */