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 */
49 uchar pushc[TOKENSIZE];
50 uchar slist[STARTSIZE];
51 uchar **def, **subs, *dchar;
52 uchar **sname, *stchar;
57 uchar *bptr; /* store input position */
67 int *sfall; /* fallback state num */
68 uchar *cpackflg; /* true if state has been character packed */
76 uchar extra[NACTIONS];
78 int pchlen = TOKENSIZE;
80 int *verify, *advance, *stoff;
84 static void free1core(void);
85 static void free2core(void);
87 static void free3core(void);
89 static void get1core(void);
90 static void get2core(void);
91 static void get3core(void);
94 main(int argc, char **argv)
98 cname = unsharp("#9/lib/lex.ncform");
102 case 'd': debug++; break;
103 case 'y': yydebug = TRUE; break;
106 Binit(&fout, 1, OWRITE);
120 warning("Unknown option %c", ARGC());
125 fin = Bopen(argv[fptr++], OREAD);
127 error ("Can't read input file %s",argv[0]);
132 fin = myalloc(sizeof(Biobuf), 1);
135 Binit(fin, 0, OREAD);
137 if(Bgetc(fin) == Beof) /* no input */
141 /* may be gotten: def, subs, sname, stchar, ccl, dchar */
143 /* may be gotten: name, left, right, nullstr, parent */
144 strcpy((char*)sp, "INITIAL");
146 sp += strlen("INITIAL") + 1;
148 if(yyparse()) exits("error"); /* error return code */
149 /* may be disposed of: def, subs, dchar */
151 /* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */
159 if(tptr>0)cfoll(tptr-1);
166 print("Print %d states:\n",stnum+1);
167 for(i=0;i<=stnum;i++)stprt(i);
170 /* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, stchar, sname */
171 /* may be gotten: verify, advance, stoff */
175 /* may be disposed of: verify, advance, stoff, nexts, nchar,
176 gotof, atable, ccpackflg, sfall */
180 fother = Bopen(cname,OREAD);
182 error("Lex driver missing, file %s",cname);
183 while ( (i=Bgetc(fother)) != Beof)
192 report == 1)statistics();
194 exits(0); /* success return code */
200 ccptr = ccl = myalloc(CCLSIZE,sizeof(*ccl));
201 pcptr = pchar = myalloc(pchlen, sizeof(*pchar));
202 def = myalloc(DEFSIZE,sizeof(*def));
203 subs = myalloc(DEFSIZE,sizeof(*subs));
204 dp = dchar = myalloc(DEFCHAR,sizeof(*dchar));
205 sname = myalloc(STARTSIZE,sizeof(*sname));
206 sp = stchar = myalloc(STARTCHAR,sizeof(*stchar));
207 if(ccl == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || stchar == 0)
208 error("Too little core to begin");
224 gotof = myalloc(nstates,sizeof(*gotof));
225 nexts = myalloc(ntrans,sizeof(*nexts));
226 nchar = myalloc(ntrans,sizeof(*nchar));
227 state = myalloc(nstates,sizeof(*state));
228 atable = myalloc(nstates,sizeof(*atable));
229 sfall = myalloc(nstates,sizeof(*sfall));
230 cpackflg = myalloc(nstates,sizeof(*cpackflg));
231 tmpstat = myalloc(tptr+1,sizeof(*tmpstat));
232 foll = myalloc(tptr+1,sizeof(*foll));
233 nxtpos = positions = myalloc(maxpos,sizeof(*positions));
234 if(tmpstat == 0 || foll == 0 || positions == 0 ||
235 gotof == 0 || nexts == 0 || nchar == 0 || state == 0 || atable == 0 || sfall == 0 || cpackflg == 0 )
236 error("Too little core for state generation");
237 for(i=0;i<=tptr;i++)foll[i] = 0;
260 verify = myalloc(outsize,sizeof(*verify));
261 advance = myalloc(outsize,sizeof(*advance));
262 stoff = myalloc(stnum+2,sizeof(*stoff));
263 if(verify == 0 || advance == 0 || stoff == 0)
264 error("Too little core for final packing");
281 myalloc(int a, int b)
286 warning("OOPS - calloc returns a 0");
293 fprint(2, "line %d: %s\n", yyline, s);