1 /* lex [-[dynvt]] [file] ... [file] */
3 /* Copyright 1976, Bell Telephone Laboratories, Inc.,
4 written by Eric Schmidt, August 27, 1976 */
10 int sect = DEFSECTION;
11 int prev = '\n'; /* previous input character */
12 int pres = '\n'; /* present input character */
13 int peek = '\n'; /* next input character */
14 uchar *pushptr = pushc;
23 int nstates = NSTATES, maxpos = MAXPOS;
24 int treesize = TREESIZE, ntrans = NTRANS;
26 int outsize = NOUTPUT;
29 int debug; /* 1 = on */
34 int yyline; /* line number of file */
40 int chset; /* 1 = char set modified */
50 uchar pushc[TOKENSIZE];
51 uchar slist[STARTSIZE];
52 uchar **def, **subs, *dchar;
53 uchar **sname, *stchar;
58 uchar *bptr; /* store input position */
68 int *sfall; /* fallback state num */
69 uchar *cpackflg; /* true if state has been character packed */
77 uchar extra[NACTIONS];
79 int pchlen = TOKENSIZE;
81 int *verify, *advance, *stoff;
85 static void free1core(void);
86 static void free2core(void);
88 static void free3core(void);
90 static void get1core(void);
91 static void get2core(void);
92 static void get3core(void);
95 main(int argc, char **argv)
99 cname = unsharp("#9/lib/lex.ncform");
103 case 'd': debug++; break;
104 case 'y': yydebug = TRUE; break;
107 Binit(&fout, 1, OWRITE);
121 warning("Unknown option %c", ARGC());
126 fin = Bopen(argv[fptr++], OREAD);
128 error ("Can't read input file %s",argv[0]);
133 fin = myalloc(sizeof(Biobuf), 1);
136 Binit(fin, 0, OREAD);
138 if(Bgetc(fin) == Beof) /* no input */
142 /* may be gotten: def, subs, sname, stchar, ccl, dchar */
144 /* may be gotten: name, left, right, nullstr, parent */
145 strcpy((char*)sp, "INITIAL");
147 sp += strlen("INITIAL") + 1;
149 if(yyparse()) exits("error"); /* error return code */
150 /* may be disposed of: def, subs, dchar */
152 /* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */
160 if(tptr>0)cfoll(tptr-1);
167 print("Print %d states:\n",stnum+1);
168 for(i=0;i<=stnum;i++)stprt(i);
171 /* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, stchar, sname */
172 /* may be gotten: verify, advance, stoff */
176 /* may be disposed of: verify, advance, stoff, nexts, nchar,
177 gotof, atable, ccpackflg, sfall */
181 fother = Bopen(cname,OREAD);
183 error("Lex driver missing, file %s",cname);
184 while ( (i=Bgetc(fother)) != Beof)
193 report == 1)statistics();
196 exits(0); /* success return code */
202 ccptr = ccl = myalloc(CCLSIZE,sizeof(*ccl));
203 pcptr = pchar = myalloc(pchlen, sizeof(*pchar));
204 def = myalloc(DEFSIZE,sizeof(*def));
205 subs = myalloc(DEFSIZE,sizeof(*subs));
206 dp = dchar = myalloc(DEFCHAR,sizeof(*dchar));
207 sname = myalloc(STARTSIZE,sizeof(*sname));
208 sp = stchar = myalloc(STARTCHAR,sizeof(*stchar));
209 if(ccl == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || stchar == 0)
210 error("Too little core to begin");
226 gotof = myalloc(nstates,sizeof(*gotof));
227 nexts = myalloc(ntrans,sizeof(*nexts));
228 nchar = myalloc(ntrans,sizeof(*nchar));
229 state = myalloc(nstates,sizeof(*state));
230 atable = myalloc(nstates,sizeof(*atable));
231 sfall = myalloc(nstates,sizeof(*sfall));
232 cpackflg = myalloc(nstates,sizeof(*cpackflg));
233 tmpstat = myalloc(tptr+1,sizeof(*tmpstat));
234 foll = myalloc(tptr+1,sizeof(*foll));
235 nxtpos = positions = myalloc(maxpos,sizeof(*positions));
236 if(tmpstat == 0 || foll == 0 || positions == 0 ||
237 gotof == 0 || nexts == 0 || nchar == 0 || state == 0 || atable == 0 || sfall == 0 || cpackflg == 0 )
238 error("Too little core for state generation");
239 for(i=0;i<=tptr;i++)foll[i] = 0;
262 verify = myalloc(outsize,sizeof(*verify));
263 advance = myalloc(outsize,sizeof(*advance));
264 stoff = myalloc(stnum+2,sizeof(*stoff));
265 if(verify == 0 || advance == 0 || stoff == 0)
266 error("Too little core for final packing");
283 myalloc(int a, int b)
288 warning("OOPS - calloc returns a 0");
295 fprint(2, "line %d: %s\n", yyline, s);