📄 parser.y
字号:
error("Premature eof"); case 's': case 'S': /* start conditions */ lgate(); while(*p && index(*p," \t,") < 0) p++; n = TRUE; while(n){ while(*p && index(*p," \t,") >= 0) p++; t = p; while(*p && index(*p," \t,") < 0)p++; if(!*p) n = FALSE; *p++ = 0; if (*t == 0) continue; i = sptr*2; if(!ratfor)fprintf(fout,"# "); fprintf(fout,"define %s %d\n",t,i); scopy(t,sp); sname[sptr++] = sp; sname[sptr] = 0; /* required by lookup */ if(sptr >= STARTSIZE) error("Too many start conditions"); sp =+ slength(sp) + 1; if(sp >= schar+STARTCHAR) error("Start conditions too long"); } continue; default: warning("Invalid request %s",p); continue; } /* end of switch after seeing '%' */ case ' ': case '\t': /* must be code */ lgate(); fprintf(fout, "%s\n",p); continue; default: /* definition */ while(*p && !space(*p)) p++; if(*p == 0) continue; prev = *p; *p = 0; bptr = p+1; yylval = buf; if(digit(buf[0])) warning("Substitution strings may not begin with digits"); return(freturn(STR)); } } /* still sect 1, but prev != '\n' */ else { p = bptr; while(*p && space(*p)) p++; if(*p == 0) warning("No translation given - null string assumed"); scopy(p,token); yylval = token; prev = '\n'; return(freturn(STR)); } } /* end of section one processing */ } else if(sect == RULESECTION){ /* rules and actions */ while(!eof){ switch(c=gch()){ case '\0': return(freturn(0)); case '\n': if(prev == '\n') continue; x = NEWE; break; case ' ': case '\t': if(sectbegin == TRUE){ cpyact(); while((c=gch()) && c != '\n'); continue; } if(!funcflag)phead2(); funcflag = TRUE; if(ratfor)fprintf(fout,"%d\n",30000+casecount); else fprintf(fout,"case %d:\n",casecount); if(cpyact()){ if(ratfor)fprintf(fout,"goto 30997\n"); else fprintf(fout,"break;\n"); } while((c=gch()) && c != '\n'); if(peek == ' ' || peek == '\t' || sectbegin == TRUE){ warning("Executable statements should occur right after %%"); continue; } x = NEWE; break; case '%': if(prev != '\n') goto character; if(peek == '{'){ /* included code */ getl(buf); while(!eof && getl(buf) && scomp("%}",buf) != 0) fprintf(fout,"%s\n",buf); continue; } if(peek == '%'){ c = gch(); c = gch(); x = DELIM; break; } goto character; case '|': if(peek == ' ' || peek == '\t' || peek == '\n'){ if(ratfor)fprintf(fout,"%d\n",30000+casecount++); else fprintf(fout,"case %d:\n",casecount++); continue; } x = '|'; break; case '$': if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){ x = c; break; } goto character; case '^': if(prev != '\n' && scon != TRUE) goto character; /* valid only at line begin */ x = c; break; case '?': case '+': case '.': case '*': case '(': case ')': case ',': case '/': x = c; break; case '}': iter = FALSE; x = c; break; case '{': /* either iteration or definition */ if(digit(c=gch())){ /* iteration */ iter = TRUE; ieval: i = 0; while(digit(c)){ token[i++] = c; c = gch(); } token[i] = 0; yylval = siconv(token); munput('c',c); x = ITER; break; } else { /* definition */ i = 0; while(c && c!='}'){ token[i++] = c; c = gch(); } token[i] = 0; i = lookup(token,def); if(i < 0) warning("Definition %s not found",token); else munput('s',subs[i]); continue; } case '<': /* start condition ? */ if(prev != '\n') /* not at line begin, not start */ goto character; t = slptr; do { i = 0; c = gch(); while(c != ',' && c && c != '>'){ token[i++] = c; c = gch(); } token[i] = 0; if(i == 0) goto character; i = lookup(token,sname); if(i < 0) { warning("Undefined start condition %s",token); continue; } *slptr++ = i+1; } while(c && c != '>'); *slptr++ = 0; /* check if previous value re-usable */ for (xp=slist; xp<t; ) { if (strcmp(xp, t)==0) break; while (*xp++); } if (xp<t) { /* re-use previous pointer to string */ slptr=t; t=xp; } if(slptr > slist+STARTSIZE) /* note not packed ! */ error("Too many start conditions used"); yylval = t; x = SCON; break; case '"': i = 0; while((c=gch()) && c != '"' && c != '\n'){ if(c == '\\') c = usescape(c=gch()); token[i++] = c; if(i > TOKENSIZE){ warning("String too long"); i = TOKENSIZE-1; break; } } if(c == '\n') { yyline--; warning("Non-terminated string"); yyline++; } token[i] = 0; if(i == 0)x = NULLS; else if(i == 1){ yylval = token[0]; x = CHAR; } else { yylval = token; x = STR; } break; case '[': for(i=1;i<NCH;i++) symbol[i] = 0; x = CCL; if((c = gch()) == '^'){ x = NCCL; c = gch(); } while(c != ']' && c){ if(c == '\\') c = usescape(c=gch()); symbol[c] = 1; j = c; if((c=gch()) == '-' && peek != ']'){ /* range specified */ c = gch(); if(c == '\\') c = usescape(c=gch()); k = c; if(j > k) { n = j; j = k; k = n; } if(!(('A' <= j && k <= 'Z') || ('a' <= j && k <= 'z') || ('0' <= j && k <= '9'))) warning("Non-portable Character Class"); for(n=j+1;n<=k;n++) symbol[n] = 1; /* implementation dependent */ c = gch(); } } /* try to pack ccl's */ i = 0; for(j=0;j<NCH;j++) if(symbol[j])token[i++] = j; token[i] = 0; p = ccptr; if(optim){ p = ccl; while(p <ccptr && scomp(token,p) != 0)p++; } if(p < ccptr) /* found it */ yylval = p; else { yylval = ccptr; scopy(token,ccptr); ccptr =+ slength(token) + 1; if(ccptr >= ccl+CCLSIZE) error("Too many large character classes"); } cclinter(x==CCL); break; case '\\': c = usescape(c=gch()); default: character: if(iter){ /* second part of an iteration */ iter = FALSE; if('0' <= c && c <= '9') goto ieval; } if(alpha(peek)){ i = 0; yylval = token; token[i++] = c; while(alpha(peek)) token[i++] = gch(); if(peek == '?' || peek == '*' || peek == '+') munput('c',token[--i]); token[i] = 0; if(i == 1){ yylval = token[0]; x = CHAR; } else x = STR; } else { yylval = c; x = CHAR; } } scon = FALSE; if(x == SCON)scon = TRUE; sectbegin = FALSE; return(freturn(x)); } } /* section three */ ptail();# ifdef DEBUG if(debug) fprintf(fout,"\n/*this comes from section three - debug */\n");# endif while(getl(buf) && !eof) fprintf(fout,"%s\n",buf); return(freturn(0)); }/* end of yylex */# ifdef DEBUGfreturn(i) int i; { if(yydebug) { printf("now return "); if(i < NCH) allprint(i); else printf("%d",i); printf(" yylval = "); switch(i){ case STR: case CCL: case NCCL: strpt(yylval); break; case CHAR: allprint(yylval); break; default: printf("%d",yylval); break; } putchar('\n'); } return(i); }# endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -