err.h
来自「本工具提供一个词法分析器和语法分析器的集成开发环境」· C头文件 代码 · 共 1,161 行 · 第 1/2 页
H
1,161 行
} zzdirty = 1; zzMakeAttr return 1;}#endif /*LL_K*/#elseint#ifdef __USE_PROTOS_zzmatch(int _t, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet)#else_zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)int _t;char **zzBadText;char **zzMissText;int *zzMissTok, *zzBadTok;SetWordType **zzMissSet;#endif{ if ( LA(1)!=_t ) { *zzBadText = *zzMissText=LATEXT(1); *zzMissTok= _t; *zzBadTok=LA(1); *zzMissSet=NULL; return 0; } zzMakeAttr return 1;}int#ifdef __USE_PROTOS_zzmatch_wsig(int _t)#else_zzmatch_wsig(_t)int _t;#endif{ if ( LA(1)!=_t ) return 0; zzMakeAttr return 1;}#endif /*DEMAND_LOOK*/#ifdef ZZINF_LOOKvoid#ifdef __USE_PROTOS_inf_zzgettok(void)#else_inf_zzgettok()#endif{ if ( zzinf_labase >= zzinf_last ) {NLA = zzEOF_TOKEN; strcpy(NLATEXT, "");} else { NLA = zzinf_tokens[zzinf_labase]; zzline = zzinf_line[zzinf_labase]; /* wrong in 1.21 */ strcpy(NLATEXT, zzinf_text[zzinf_labase]); 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_PROTOSzzfill_inf_look(void)#elsezzfill_inf_look()#endif{ int tok, line; int zzinf_token_buffer_size = ZZINF_DEF_TOKEN_BUFFER_SIZE; int zzinf_text_buffer_size = ZZINF_DEF_TEXT_BUFFER_SIZE; int zzinf_text_buffer_index = 0; int zzinf_lap = 0; /* allocate text/token buffers */ zzinf_text_buffer = (char *) malloc(zzinf_text_buffer_size); if ( zzinf_text_buffer == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d bytes)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_tokens = (int *) calloc(zzinf_token_buffer_size,sizeof(int)); if ( zzinf_tokens == NULL ) { fprintf(stderr, "cannot allocate token buffer (%d tokens)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_line = (int *) calloc(zzinf_token_buffer_size,sizeof(int)); if ( zzinf_line == NULL ) { fprintf(stderr, "cannot allocate line buffer (%d ints)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } /* get tokens, copying text to text buffer */ zzinf_text_buffer_index = 0; do { zzgettok(); line = zzreal_line; while ( zzinf_lap>=zzinf_token_buffer_size ) { zzinf_token_buffer_size += ZZINF_BUFFER_TOKEN_CHUNK_SIZE; zzinf_tokens = (int *) realloc(zzinf_tokens, zzinf_token_buffer_size*sizeof(int)); if ( zzinf_tokens == NULL ) { fprintf(stderr, "cannot allocate lookahead token buffer (%d tokens)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_line = (int *) realloc(zzinf_line, zzinf_token_buffer_size*sizeof(int)); if ( zzinf_line == NULL ) { fprintf(stderr, "cannot allocate lookahead line buffer (%d ints)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } } while ( (zzinf_text_buffer_index+strlen(NLATEXT)+1) >= zzinf_text_buffer_size ) { zzinf_text_buffer_size += ZZINF_BUFFER_TEXT_CHUNK_SIZE; zzinf_text_buffer = (char *) realloc(zzinf_text_buffer, zzinf_text_buffer_size); if ( zzinf_text_buffer == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d bytes)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } } /* record token and text and line of input symbol */ tok = zzinf_tokens[zzinf_lap] = NLA; strcpy(&zzinf_text_buffer[zzinf_text_buffer_index], NLATEXT); zzinf_text_buffer_index += strlen(NLATEXT)+1; zzinf_line[zzinf_lap] = line; zzinf_lap++; } while (tok!=zzEOF_TOKEN); zzinf_labase = 0; zzinf_last = zzinf_lap-1; /* allocate ptrs to text of ith token */ zzinf_text = (char **) calloc(zzinf_last+1,sizeof(char *)); if ( zzinf_text == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_text_buffer_index = 0; 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) { zzinf_text[zzinf_lap++] = &zzinf_text_buffer[zzinf_text_buffer_index]; zzinf_text_buffer_index += strlen(&zzinf_text_buffer[zzinf_text_buffer_index])+1; }}#endifint#ifdef __USE_PROTOS_zzsetmatch(SetWordType *e, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet)#else_zzsetmatch(e, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet)SetWordType *e;char **zzBadText;char **zzMissText;int *zzMissTok, *zzBadTok;SetWordType **zzMissSet;#endif{#ifdef DEMAND_LOOK#ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;}#else if ( zzdirty ) {zzCONSUME;}#endif#endif if ( !zzset_el((unsigned)LA(1), e) ) { *zzBadText = LATEXT(1); *zzMissText=NULL; *zzMissTok= 0; *zzBadTok=LA(1); *zzMissSet=e; 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_zzmatch_wdfltsig(int tokenWanted, SetWordType *whatFollows)#else_zzmatch_wdfltsig(tokenWanted, whatFollows)int tokenWanted;SetWordType *whatFollows;#endif{#ifdef DEMAND_LOOK#ifdef LL_K if ( zzdirty==LL_K ) { zzCONSUME; }#else if ( zzdirty ) {zzCONSUME;}#endif#endif if ( LA(1)!=tokenWanted ) { zzSyntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", zzline, (LA(1)==zzEOF_TOKEN)?"<eof>":LATEXT(1), zztokens[tokenWanted]); zzconsumeUntil( whatFollows ); return 0; } else { zzMakeAttr #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_zzsetmatch_wdfltsig(SetWordType *tokensWanted, int tokenTypeOfSet, SetWordType *whatFollows)#else_zzsetmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows)SetWordType *tokensWanted;int tokenTypeOfSet;SetWordType *whatFollows;#endif{#ifdef DEMAND_LOOK#ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;}#else if ( zzdirty ) {zzCONSUME;}#endif#endif if ( !zzset_el((unsigned)LA(1), tokensWanted) ) { zzSyntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", zzline, (LA(1)==zzEOF_TOKEN)?"<eof>":LATEXT(1), zztokens[tokenTypeOfSet]); zzconsumeUntil( whatFollows ); return 0; } else { zzMakeAttr#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_zzsetmatch_wsig(SetWordType *e)#else_zzsetmatch_wsig(e)SetWordType *e;#endif{#ifdef DEMAND_LOOK#ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;}#else if ( zzdirty ) {zzCONSUME;}#endif#endif if ( !zzset_el((unsigned)LA(1), e) ) 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;}#ifdef USER_ZZMODE_STACKstatic int zzmstk[ZZMAXSTK] = { -1 };static int zzmdep = 0;static char zzmbuf[70];void#ifdef __USE_PROTOSzzmpush( int m )#elsezzmpush( m )int m;#endif{ if(zzmdep == ZZMAXSTK - 1) { sprintf(zzmbuf, "Mode stack overflow "); zzerr(zzmbuf); } else { zzmstk[zzmdep++] = zzauto; zzmode(m); }}void#ifdef __USE_PROTOSzzmpop( void )#elsezzmpop( )#endif{ if(zzmdep == 0) { sprintf(zzmbuf, "Mode stack underflow "); zzerr(zzmbuf); } else { zzmdep--; zzmode(zzmstk[zzmdep]); }}void#ifdef __USE_PROTOSzzsave_mode_stack( int modeStack[], int *modeLevel )#elsezzsave_mode_stack( modeStack, modeLevel )int modeStack[];int *modeLevel;#endif{ int i; memcpy(modeStack, zzmstk, sizeof(zzmstk)); *modeLevel = zzmdep; zzmdep = 0; return;}void#ifdef __USE_PROTOSzzrestore_mode_stack( int modeStack[], int *modeLevel )#elsezzrestore_mode_stack( modeStack, modeLevel )int modeStack[];int *modeLevel;#endif{ int i; memcpy(zzmstk, modeStack, sizeof(zzmstk)); zzmdep = *modeLevel; return;}#endif /* USER_ZZMODE_STACK */void zzTraceReset() {#ifdef zzTRACE_RULES zzTraceOptionValue=zzTraceOptionValueDefault; zzTraceGuessOptionValue=1; zzTraceCurrentRuleName=NULL; zzTraceDepth=0;#endif}void zzTraceGuessFail() {#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) { fprintf(stderr,"guess failed\n"); };#endif#endif}/* zzTraceOption: zero value turns off trace*/#ifdef __USE_PROTOSvoid zzTraceIn(char * rule)#elsevoid zzTraceIn(rule) char *rule;#endif{#ifdef zzTRACE_RULES int doIt=0; zzTraceDepth++; zzTraceCurrentRuleName=rule; if (zzTraceOptionValue <= 0) { doIt=0;#ifdef ZZCAN_GUESS } else if (zzguessing && zzTraceGuessOptionValue <= 0) { doIt=0;#endif } else { doIt=1; }; if (doIt) { fprintf(stderr,"enter rule %s {\"%s\"} depth %d", rule, LA(1)==1 ? "@" : LATEXT(1), zzTraceDepth);#ifdef ZZCAN_GUESS if (zzguessing) fprintf(stderr," guessing");#endif fprintf(stderr,"\n"); };#endif return;}#ifdef __USE_PROTOSvoid zzTraceOut(char * rule)#elsevoid 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) { fprintf(stderr,"exit rule %s {\"%s\"} depth %d", rule, LA(1)==1 ? "@" : LATEXT(1), zzTraceDepth+1);#ifdef ZZCAN_GUESS if (zzguessing) fprintf(stderr," guessing");#endif fprintf(stderr,"\n"); };#endif}#ifdef __USE_PROTOSint zzTraceOption(int delta)#elseint zzTraceOption(delta) int delta;#endif{#ifdef zzTRACE_RULES int prevValue=zzTraceOptionValue; zzTraceOptionValue=zzTraceOptionValue+delta; if (zzTraceCurrentRuleName != NULL) { if (prevValue <= 0 && zzTraceOptionValue > 0) { fprintf(stderr,"trace enabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; if (prevValue > 0 && zzTraceOptionValue <= 0) { fprintf(stderr,"trace disabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; }; return prevValue;#else return 0;#endif}#ifdef __USE_PROTOSint zzTraceGuessOption(int delta)#elseint zzTraceGuessOption(delta) int delta;#endif{#ifdef zzTRACE_RULES#ifdef ZZCAN_GUESS int prevValue=zzTraceGuessOptionValue; zzTraceGuessOptionValue=zzTraceGuessOptionValue+delta; if (zzTraceCurrentRuleName != NULL) { if (prevValue <= 0 && zzTraceGuessOptionValue > 0) { fprintf(stderr,"guess trace enabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; if (prevValue > 0 && zzTraceGuessOptionValue <= 0) { fprintf(stderr,"guess trace disabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; }; return prevValue;#else return 0;#endif#else return 0;#endif}#endif /* ERR_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?