|
|
1.1 ! root 1: # include "ldefs.c" ! 2: # include "once.c" ! 3: ! 4: /* lex [-[drcyvntf]] [file] ... [file] */ ! 5: ! 6: /* Copyright 1976, Bell Telephone Laboratories, Inc., ! 7: written by Eric Schmidt, August 27, 1976 */ ! 8: ! 9: main(argc,argv) ! 10: int argc; ! 11: char **argv; { ! 12: register int i; ! 13: # ifdef DEBUG ! 14: signal(10,buserr); ! 15: signal(11,segviol); ! 16: # endif ! 17: while (argc > 1 && argv[1][0] == '-' ){ ! 18: i = 0; ! 19: while(argv[1][++i]){ ! 20: switch (argv[1][i]){ ! 21: # ifdef DEBUG ! 22: case 'd': debug++; break; ! 23: case 'y': yydebug = TRUE; break; ! 24: # endif ! 25: case 'r': case 'R': ! 26: warning("Ratfor not currently supported with lex"); ! 27: ratfor=TRUE; break; ! 28: case 'c': case 'C': ! 29: ratfor=FALSE; break; ! 30: case 't': case 'T': ! 31: fout = stdout; ! 32: errorf = stderr; ! 33: break; ! 34: case 'v': case 'V': ! 35: report = 1; ! 36: break; ! 37: case 'n': case 'N': ! 38: report = 0; ! 39: break; ! 40: default: ! 41: warning("Unknown option %c",argv[1][i]); ! 42: } ! 43: } ! 44: argc--; ! 45: argv++; ! 46: } ! 47: sargc = argc; ! 48: sargv = argv; ! 49: if (argc > 1){ ! 50: fin = fopen(argv[++fptr], "r"); /* open argv[1] */ ! 51: infile = argv[fptr]; ! 52: sargc--; ! 53: sargv++; ! 54: } ! 55: else { ! 56: fin = stdin; ! 57: infile = "-"; ! 58: } ! 59: if(fin == NULL) ! 60: error ("Can't read input file %s",argc>1?argv[1]:"standard input"); ! 61: gch(); ! 62: /* may be gotten: def, subs, sname, schar, ccl, dchar */ ! 63: get1core(); ! 64: /* may be gotten: name, left, right, nullstr, parent */ ! 65: scopy("INITIAL",sp); ! 66: sname[0] = sp; ! 67: sp += slength("INITIAL") + 1; ! 68: sname[1] = 0; ! 69: if(yyparse(0)) exit(1); /* error return code */ ! 70: /* may be disposed of: def, subs, dchar */ ! 71: free1core(); ! 72: /* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */ ! 73: get2core(); ! 74: ptail(); ! 75: mkmatch(); ! 76: # ifdef DEBUG ! 77: if(debug) pccl(); ! 78: # endif ! 79: sect = ENDSECTION; ! 80: if(tptr>0)cfoll(tptr-1); ! 81: # ifdef DEBUG ! 82: if(debug)pfoll(); ! 83: # endif ! 84: cgoto(); ! 85: # ifdef DEBUG ! 86: if(debug){ ! 87: printf("Print %d states:\n",stnum+1); ! 88: for(i=0;i<=stnum;i++)stprt(i); ! 89: } ! 90: # endif ! 91: /* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, schar, sname */ ! 92: /* may be gotten: verify, advance, stoff */ ! 93: free2core(); ! 94: get3core(); ! 95: layout(); ! 96: /* may be disposed of: verify, advance, stoff, nexts, nchar, ! 97: gotof, atable, ccpackflg, sfall */ ! 98: # ifdef DEBUG ! 99: free3core(); ! 100: # endif ! 101: if (ZCH>NCH) cname="/usr/lib/lex/ebcform"; ! 102: fother = fopen(ratfor?ratname:cname,"r"); ! 103: if(fother == NULL) ! 104: error("Lex driver missing, file %s",ratfor?ratname:cname); ! 105: while ( (i=getc(fother)) != EOF) ! 106: putc(i,fout); ! 107: ! 108: fclose(fother); ! 109: fclose(fout); ! 110: if( ! 111: # ifdef DEBUG ! 112: debug || ! 113: # endif ! 114: report == 1)statistics(); ! 115: fclose(stdout); ! 116: fclose(stderr); ! 117: exit(0); /* success return code */ ! 118: } ! 119: get1core(){ ! 120: register int i, val; ! 121: register char *p; ! 122: ccptr = ccl = myalloc(CCLSIZE,sizeof(*ccl)); ! 123: pcptr = pchar = myalloc(pchlen, sizeof(*pchar)); ! 124: def = (char **)myalloc(DEFSIZE,sizeof(*def)); ! 125: subs = (char **)myalloc(DEFSIZE,sizeof(*subs)); ! 126: dp = dchar = myalloc(DEFCHAR,sizeof(*dchar)); ! 127: sname = (char **)myalloc(STARTSIZE,sizeof(*sname)); ! 128: sp = schar = myalloc(STARTCHAR,sizeof(*schar)); ! 129: if(ccl == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || schar == 0) ! 130: error("Too little core to begin"); ! 131: } ! 132: free1core(){ ! 133: cfree((char *)def,DEFSIZE,sizeof(*def)); ! 134: cfree((char *)subs,DEFSIZE,sizeof(*subs)); ! 135: cfree((char *)dchar,DEFCHAR,sizeof(*dchar)); ! 136: } ! 137: get2core(){ ! 138: register int i, val; ! 139: register char *p; ! 140: gotof = (int *)myalloc(nstates,sizeof(*gotof)); ! 141: nexts = (int *)myalloc(ntrans,sizeof(*nexts)); ! 142: nchar = myalloc(ntrans,sizeof(*nchar)); ! 143: state = (int **)myalloc(nstates,sizeof(*state)); ! 144: atable = (int *)myalloc(nstates,sizeof(*atable)); ! 145: sfall = (int *)myalloc(nstates,sizeof(*sfall)); ! 146: cpackflg = myalloc(nstates,sizeof(*cpackflg)); ! 147: tmpstat = myalloc(tptr+1,sizeof(*tmpstat)); ! 148: foll = (int **)myalloc(tptr+1,sizeof(*foll)); ! 149: nxtpos = positions = (int *)myalloc(maxpos,sizeof(*positions)); ! 150: if(tmpstat == 0 || foll == 0 || positions == 0 || ! 151: gotof == 0 || nexts == 0 || nchar == 0 || state == 0 || atable == 0 || sfall == 0 || cpackflg == 0 ) ! 152: error("Too little core for state generation"); ! 153: for(i=0;i<=tptr;i++)foll[i] = 0; ! 154: } ! 155: free2core(){ ! 156: cfree((char *)positions,maxpos,sizeof(*positions)); ! 157: cfree((char *)tmpstat,tptr+1,sizeof(*tmpstat)); ! 158: cfree((char *)foll,tptr+1,sizeof(*foll)); ! 159: cfree((char *)name,treesize,sizeof(*name)); ! 160: cfree((char *)left,treesize,sizeof(*left)); ! 161: cfree((char *)right,treesize,sizeof(*right)); ! 162: cfree((char *)parent,treesize,sizeof(*parent)); ! 163: cfree((char *)nullstr,treesize,sizeof(*nullstr)); ! 164: cfree((char *)state,nstates,sizeof(*state)); ! 165: cfree((char *)sname,STARTSIZE,sizeof(*sname)); ! 166: cfree((char *)schar,STARTCHAR,sizeof(*schar)); ! 167: cfree((char *)ccl,CCLSIZE,sizeof(*ccl)); ! 168: } ! 169: get3core(){ ! 170: register int i, val; ! 171: register char *p; ! 172: verify = (int *)myalloc(outsize,sizeof(*verify)); ! 173: advance = (int *)myalloc(outsize,sizeof(*advance)); ! 174: stoff = (int *)myalloc(stnum+2,sizeof(*stoff)); ! 175: if(verify == 0 || advance == 0 || stoff == 0) ! 176: error("Too little core for final packing"); ! 177: } ! 178: # ifdef DEBUG ! 179: free3core(){ ! 180: cfree((char *)advance,outsize,sizeof(*advance)); ! 181: cfree((char *)verify,outsize,sizeof(*verify)); ! 182: cfree((char *)stoff,stnum+1,sizeof(*stoff)); ! 183: cfree((char *)gotof,nstates,sizeof(*gotof)); ! 184: cfree((char *)nexts,ntrans,sizeof(*nexts)); ! 185: cfree((char *)nchar,ntrans,sizeof(*nchar)); ! 186: cfree((char *)atable,nstates,sizeof(*atable)); ! 187: cfree((char *)sfall,nstates,sizeof(*sfall)); ! 188: cfree((char *)cpackflg,nstates,sizeof(*cpackflg)); ! 189: } ! 190: # endif ! 191: char *myalloc(a,b) ! 192: int a,b; { ! 193: register int i; ! 194: i = (int)calloc(a, b); ! 195: if(i==0) ! 196: warning("OOPS - calloc returns a 0"); ! 197: else if(i == -1){ ! 198: # ifdef DEBUG ! 199: warning("calloc returns a -1"); ! 200: # endif ! 201: return(0); ! 202: } ! 203: return((char *)i); ! 204: } ! 205: # ifdef DEBUG ! 206: buserr(){ ! 207: fflush(errorf); ! 208: fflush(fout); ! 209: fflush(stdout); ! 210: fprintf(errorf,"Bus error\n"); ! 211: if(report == 1)statistics(); ! 212: fflush(errorf); ! 213: } ! 214: segviol(){ ! 215: fflush(errorf); ! 216: fflush(fout); ! 217: fflush(stdout); ! 218: fprintf(errorf,"Segmentation violation\n"); ! 219: if(report == 1)statistics(); ! 220: fflush(errorf); ! 221: } ! 222: # endif ! 223: ! 224: yyerror(s) ! 225: char *s; ! 226: { ! 227: fprintf(stderr, "line %d: %s\n", yyline, s); ! 228: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.