|
|
1.1 ! root 1: %Start DOTSON ! 2: %{ ! 3: #undef INITIAL ! 4: #include <ctype.h> ! 5: #include "defs" ! 6: #include "tokdefs" ! 7: ! 8: typedef union { int ival; ptr pval; } YYSTYPE; ! 9: extern YYSTYPE yylval; ! 10: YYSTYPE prevl; ! 11: int prevv; ! 12: char *copys(); ! 13: static ptr p; ! 14: static /*ptr*/ struct stentry *q; ! 15: static FILE *fd; ! 16: static int quoted, k; ! 17: static int rket = 0; ! 18: FILE *opincl(); ! 19: ptr mkdef(), mkcomm(), mkname(), mkimcon(); ! 20: ! 21: #define RET(x) { RETI(x,x); } ! 22: ! 23: #define RETL(yv,yl) {yylval=prevl=yl;igeol=comneed=0;return(prevv=yv); } ! 24: #define RETP(yv,yl) {yylval.pval=prevl.pval=yl;igeol=comneed=0;return(prevv=yv); } ! 25: #define RETI(yv,yl) {yylval.ival=prevl.ival=yl;igeol=comneed=0;return(prevv=yv); } ! 26: #define REL(n) { RETI(RELOP, OPREL+n);} ! 27: #define AS(n) { RETI(ASGNOP, OPASGN+n); } ! 28: #define RETC(x) { RETP(CONST, mkconst(x,yytext) ); } ! 29: #define RETZ(x) { yytext[yyleng-1] = '\0'; RETP(CONST, mkimcon(x,yytext) ); } ! 30: ! 31: %} ! 32: ! 33: D [0-9] ! 34: d [dD][+-]?[0-9]+ ! 35: e [eE][+-]?[0-9]+ ! 36: i [iI] ! 37: ! 38: %% ! 39: ! 40: [a-zA-Z][a-zA-Z0-9_]* { ! 41: lower(yytext); ! 42: if(lettneed && yyleng==1) ! 43: { RETI(LETTER, yytext[0]); } ! 44: else if(defneed) ! 45: { ! 46: register char *q1, *q2; ! 47: for(q2=q1=yytext+yyleng+1 ; (*q1 = efgetc)!='\n' ; ++q1) ! 48: ; ! 49: *q1 = '\0'; ! 50: p = mkdef(yytext, q2); ! 51: defneed = 0; ! 52: ++yylineno; ! 53: unput('\n'); ! 54: } ! 55: else if(optneed) ! 56: { RETP(OPTNAME, (int *)copys(yytext)); } ! 57: else if(comneed && ( (q=name(yytext,1))==NULL || ((struct headbits *)q)->tag!=TDEFINE) ) ! 58: { RETP(COMNAME, mkcomm(yytext) ); } ! 59: else if(q = name(yytext,1)) switch(((struct headbits *)q)->tag) ! 60: { ! 61: case TDEFINE: ! 62: filelines[filedepth] = yylineno; ! 63: filemacs[filedepth] = efmacp; ! 64: pushchars[filedepth] = (yysptr>yysbuf? ! 65: *--yysptr : -1); ! 66: if(++filedepth >= MAXINCLUDEDEPTH) ! 67: fatal("macro or include too deep"); ! 68: filelines[filedepth] = yylineno = 1; ! 69: efmacp = ((struct defblock *)q->varp)->valp; ! 70: filenames[filedepth] = NULL; ! 71: break; /*now process new input */ ! 72: ! 73: case TSTRUCT: ! 74: RETP(STRUCTNAME, (int *)q); ! 75: ! 76: case TNAME: ! 77: RETP(NAME, (int *)q); ! 78: ! 79: case TKEYWORD: ! 80: if(((struct headbits *)q)->subtype == END) ! 81: { ! 82: register int c; ! 83: eofneed = YES; ! 84: while((c=input())!=';'&&c!='\n'&&c!=EOF) ! 85: ; ! 86: NLSTATE; ! 87: } ! 88: RET(((struct headbits *)q)->subtype); ! 89: ! 90: default: ! 91: fatal1("lex: impossible type code %d", ((struct headbits *)q)->tag); ! 92: } ! 93: else RETP(NAME, mkname(yytext) ); ! 94: } ! 95: ! 96: "," RET(COMMA); ! 97: ";" RET(EOS); ! 98: ! 99: "(" RET(LPAR); ! 100: ")" RET(RPAR); ! 101: ! 102: ! 103: "[" | ! 104: "{" RET(LBRACK); ! 105: ! 106: "]" | ! 107: "}" { if(iobrlevel>0) RET(RBRACK); rket = 1; RET(EOS); } ! 108: ! 109: "," RET(COMMA); ! 110: ":" RET(COLON); ! 111: ! 112: "$" RET(REPOP); ! 113: ! 114: <DOTSON>"."[oO][rR]"." | ! 115: "|" RETI(OR,OPOR); ! 116: <DOTSON>"."[cC][oO][rR]"." | ! 117: "||" RETI(OR,OP2OR); ! 118: <DOTSON>"."[aA][nN][dD]"." | ! 119: "&" RETI(AND,OPAND); ! 120: <DOTSON>"."[cC][aA][nN][dD]"." | ! 121: "&&" RETI(AND,OP2AND); ! 122: <DOTSON>"."[nN][oO][tT]"." | ! 123: "~" RETI(NOT,OPNOT); ! 124: "!" RETI(NOT,OPNOT); ! 125: ! 126: <DOTSON>"."[lL][tT]"." | ! 127: "<" REL(OPLT); ! 128: <DOTSON>"."[lL][eE]"." | ! 129: "<=" REL(OPLE); ! 130: <DOTSON>"."[gG][tT]"." | ! 131: ">" REL(OPGT); ! 132: <DOTSON>"."[gG][eE]"." | ! 133: ">=" REL(OPGE); ! 134: <DOTSON>"."[eE][qQ]"." | ! 135: "==" REL(OPEQ); ! 136: <DOTSON>"."[nN][eE]"." | ! 137: "~=" | ! 138: "!=" REL(OPNE); ! 139: ! 140: "->" RET(ARROW); ! 141: "." RET(QUALOP); ! 142: ! 143: "+" RETI(ADDOP, OPPLUS); ! 144: "-" RETI(ADDOP, OPMINUS); ! 145: "*" RETI(MULTOP, OPSTAR); ! 146: "/" RETI(MULTOP, OPSLASH); ! 147: ! 148: "**" | ! 149: "^" RETI(POWER, OPPOWER); ! 150: ! 151: "++" RETI(DOUBLEADDOP, OPPLUS); ! 152: "--" RETI(DOUBLEADDOP, OPMINUS); ! 153: ! 154: "=" AS(OPASGN); ! 155: "+=" AS(OPPLUS); ! 156: "-=" AS(OPMINUS); ! 157: "*=" AS(OPSTAR); ! 158: "/=" AS(OPSLASH); ! 159: "**=" | ! 160: "^=" AS(OPPOWER); ! 161: ! 162: "&=" AS(OPAND); ! 163: "&&=" AS(OP2AND); ! 164: "|=" AS(OPOR); ! 165: "||=" AS(OP2OR); ! 166: ! 167: \'[^\n']*\' | ! 168: \"[^\n"]*\" { yytext[yyleng-1] = '\0'; p = mkconst(TYCHAR,yytext+1); ! 169: RETP(CONST,p); } ! 170: ! 171: {D}+[hH] { /* nh construct */ ! 172: int i, n; char c; ! 173: yytext[yyleng-1] = '\0'; n = convci(yytext); ! 174: for(i = 0; i<n ; ++i) ! 175: if( (c=yytext[i]=input()) == '\n' || c=='\0') break; ! 176: yytext[i] = '\0'; ! 177: p = mkconst(TYCHAR,yytext); ! 178: ((struct exprblock /*|| struct varblock */ *)p)->vtypep = mkint(i); ! 179: RETP(CONST, p); ! 180: } ! 181: ! 182: {D}+ RETC(TYINT); ! 183: ! 184: {D}+"."{D}* | ! 185: {D}*"."{D}+ RETC(TYREAL); ! 186: ! 187: {D}+"."?{D}*{e} | ! 188: {D}*"."{D}+{e} RETC(TYREAL); ! 189: ! 190: {D}+"."?{D}*{d} | ! 191: {D}*"."{D}+{d} RETC(TYLREAL); ! 192: ! 193: {D}+{i} { yytext[yyleng-1] = '.'; ! 194: RETP(CONST,mkimcon(TYCOMPLEX,yytext)); } ! 195: ! 196: {D}+"."{D}*{i} | ! 197: {D}*"."{D}+{i} RETZ(TYCOMPLEX); ! 198: ! 199: {D}+"."?{D}*{e}{i} | ! 200: {D}*"."{D}+{e}{i} RETZ(TYCOMPLEX); ! 201: ! 202: {D}+"."?{D}*{d}{i} | ! 203: {D}*"."{D}+{d}{i} RETZ(TYLCOMPLEX); ! 204: ! 205: "#".* { if(! nocommentflag) goto litline; } ! 206: ! 207: ^"%".* { if(thisexec) ((struct execblock *)thisexec)->nftnst += 2; ! 208: if(inproc) ! 209: { ! 210: unput('\n'); ! 211: RETP(ESCAPE, (int *)copys(yytext)); ! 212: } ! 213: ! 214: litline: p = (int *)mkchain( copys(yytext), CHNULL); ! 215: if(inproc==0 && yytext[0]=='%') ! 216: prevcomments = (int *)hookup(prevcomments, p); ! 217: else ! 218: comments = (int *)hookup(comments,p); ! 219: } ! 220: ! 221: " " ; ! 222: \t ; ! 223: \f ; ! 224: ! 225: "_"[ \t]*\n ; ! 226: ! 227: \n { if(igeol) { igeol=0; prevv = NEWLINE; } ! 228: else if(prevv>=NAME || prevv==RPAR || prevv==RBRACK ! 229: || prevv== -1 || prevv==QUALOP) ! 230: RET(EOS); } ! 231: ! 232: . { char * linerr(); ! 233: fprintf(diagfile, "Bad input character %c %s\n", yytext[0], linerr()); ! 234: ++nerrs; ! 235: } ! 236: ! 237: ^[ \t]*[iI][nN][cC][lL][uU][dD][eE].*\n { /* Include statement */ ! 238: char *q1; ! 239: register char *q2; ! 240: for(q1=yytext ; *q1==' ' || *q1=='\t' ; ++q1) ; ! 241: quoted = NO; ! 242: for(q1 += 7 ; *q1==' ' || *q1=='\t' || ! 243: *q1=='\'' || *q1=='"' || *q1=='(' ; ++q1 ) ! 244: if(*q1=='"' || *q1=='\'') ! 245: quoted = YES; ! 246: for(q2=q1 ; *q2!='\0' && *q2!=' ' && *q2!='\n' && ! 247: *q2!='\'' && *q2!='"' && *q2!=')' ; ++q2 ) ! 248: ; ! 249: *q2 = '\0'; ! 250: if( ! quoted) ! 251: for(k=0; (q = name(q1,1)) && ((struct headbits *)q)->tag==TDEFINE ; ++k) ! 252: { ! 253: if(k > MAXINCLUDEDEPTH) ! 254: fatal1("Macros too deep for %s", yytext); ! 255: q1 = ((struct defblock *)q->varp)->valp; ! 256: } ! 257: if( (fd = opincl(&q1)) == NULL) ! 258: { ! 259: fprintf(diagfile, "Cannot open file %s. Stop.\n", q1); ! 260: exit(2); ! 261: } ! 262: filelines[filedepth] = yylineno; ! 263: pushchars[filedepth] = '\n'; ! 264: if(++filedepth >= MAXINCLUDEDEPTH) ! 265: fatal("macro or include too deep"); ! 266: fileptrs[filedepth] = yyin = fd; ! 267: filenames[filedepth] = copys(q1); ! 268: filelines[filedepth] = yylineno = 1; ! 269: filemacs[filedepth] = NULL; ! 270: } ! 271: ! 272: %% ! 273: ! 274: yywrap() ! 275: { ! 276: if(filedepth == 0) ! 277: { ! 278: ateof = 1; ! 279: return(1); ! 280: } ! 281: ! 282: if(efmacp == 0) ! 283: { ! 284: fclose(yyin); ! 285: cfree(filenames[filedepth]); ! 286: } ! 287: ! 288: --filedepth; ! 289: if( filemacs[filedepth] ) ! 290: efmacp = filemacs[filedepth]; ! 291: else { ! 292: yyin = fileptrs[filedepth]; ! 293: efmacp = 0; ! 294: } ! 295: yylineno = filelines[filedepth]; ! 296: if(pushchars[filedepth] != -1) ! 297: unput( pushchars[filedepth] ); ! 298: return(0); ! 299: } ! 300: ! 301: ! 302: ! 303: lower(s) /* replace upper with lower case letters */ ! 304: register char *s; ! 305: { ! 306: register char *t; ! 307: for(t=s ; *t ; ++t) ! 308: if( isupper(*t) ) ! 309: *s++ = tolower(*t); ! 310: else if(*t != '_') ! 311: *s++ = *t; ! 312: } ! 313: ! 314: ! 315: ! 316: ! 317: setdot(k) ! 318: int k; ! 319: { ! 320: if(k) ! 321: BEGIN DOTSON; ! 322: else BEGIN 0; ! 323: } ! 324: ! 325: ! 326: ! 327: ! 328: FILE *opincl(namep) ! 329: char **namep; ! 330: { ! 331: #ifndef unix ! 332: return( fopen(*namep, "r") ); ! 333: #else ! 334: ! 335: /* On Unix, follow the C include conventions */ ! 336: ! 337: register char *s, *lastslash; ! 338: char *dir, *name, temp[100]; ! 339: int i; ! 340: FILE *fp; ! 341: ! 342: name = *namep; ! 343: if(name[0] == '/') ! 344: return( fopen(name, "r") ); ! 345: ! 346: dir = basefile; ! 347: for(i = filedepth ; i>=0 ; --i) ! 348: if( filemacs[i] == NULL) ! 349: { ! 350: dir = filenames[i]; ! 351: break; ! 352: } ! 353: ! 354: lastslash = NULL; ! 355: for(s = dir ; *s ; ++s) ! 356: if(*s == '/') ! 357: lastslash = s; ! 358: if(lastslash) ! 359: { ! 360: *lastslash = '\0'; ! 361: sprintf(temp, "%s/%s", dir, name); ! 362: *lastslash = '/'; ! 363: if( fp = fopen(temp, "r") ) ! 364: *namep = temp; ! 365: } ! 366: else ! 367: fp = fopen(name, "r"); ! 368: ! 369: if(fp == NULL) ! 370: { ! 371: sprintf(temp, "/usr/include/%s", name); ! 372: fp = fopen(temp, "r"); ! 373: *namep = temp; ! 374: } ! 375: return(fp); ! 376: ! 377: #endif ! 378: } ! 379:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.