xref: /original-bsd/old/lex/ncform (revision 4d1ce0b0)
1/*	ncform	4.1	83/08/11	*/
2
3int yylineno =1;
4# define YYU(x) x
5# define NLSTATE yyprevious=YYNEWLINE
6char yytext[YYLMAX];
7struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
8char yysbuf[YYLMAX];
9char *yysptr = yysbuf;
10int *yyfnd;
11extern struct yysvf *yyestate;
12int yyprevious = YYNEWLINE;
13yylook(){
14	register struct yysvf *yystate, **lsp;
15	register struct yywork *yyt;
16	struct yysvf *yyz;
17	int yych;
18	struct yywork *yyr;
19# ifdef LEXDEBUG
20	int debug;
21# endif
22	char *yylastch;
23	/* start off machines */
24# ifdef LEXDEBUG
25	debug = 0;
26# endif
27	if (!yymorfg)
28		yylastch = yytext;
29	else {
30		yymorfg=0;
31		yylastch = yytext+yyleng;
32		}
33	for(;;){
34		lsp = yylstate;
35		yyestate = yystate = yybgin;
36		if (yyprevious==YYNEWLINE) yystate++;
37		for (;;){
38# ifdef LEXDEBUG
39			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
40# endif
41			yyt = yystate->yystoff;
42			if(yyt == yycrank){		/* may not be any transitions */
43				yyz = yystate->yyother;
44				if(yyz == 0)break;
45				if(yyz->yystoff == yycrank)break;
46				}
47			*yylastch++ = yych = input();
48		tryagain:
49# ifdef LEXDEBUG
50			if(debug){
51				fprintf(yyout,"char ");
52				allprint(yych);
53				putchar('\n');
54				}
55# endif
56			yyr = yyt;
57			if ( (int)yyt > (int)yycrank){
58				yyt = yyr + yych;
59				if (yyt <= yytop && yyt->verify+yysvec == yystate){
60					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
61						{unput(*--yylastch);break;}
62					*lsp++ = yystate = yyt->advance+yysvec;
63					goto contin;
64					}
65				}
66# ifdef YYOPTIM
67			else if((int)yyt < (int)yycrank) {		/* r < yycrank */
68				yyt = yyr = yycrank+(yycrank-yyt);
69# ifdef LEXDEBUG
70				if(debug)fprintf(yyout,"compressed state\n");
71# endif
72				yyt = yyt + yych;
73				if(yyt <= yytop && yyt->verify+yysvec == yystate){
74					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
75						{unput(*--yylastch);break;}
76					*lsp++ = yystate = yyt->advance+yysvec;
77					goto contin;
78					}
79				yyt = yyr + YYU(yymatch[yych]);
80# ifdef LEXDEBUG
81				if(debug){
82					fprintf(yyout,"try fall back character ");
83					allprint(YYU(yymatch[yych]));
84					putchar('\n');
85					}
86# endif
87				if(yyt <= yytop && yyt->verify+yysvec == yystate){
88					if(yyt->advance+yysvec == YYLERR)	/* error transition */
89						{unput(*--yylastch);break;}
90					*lsp++ = yystate = yyt->advance+yysvec;
91					goto contin;
92					}
93				}
94			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
95# ifdef LEXDEBUG
96				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
97# endif
98				goto tryagain;
99				}
100# endif
101			else
102				{unput(*--yylastch);break;}
103		contin:
104# ifdef LEXDEBUG
105			if(debug){
106				fprintf(yyout,"state %d char ",yystate-yysvec-1);
107				allprint(yych);
108				putchar('\n');
109				}
110# endif
111			;
112			}
113# ifdef LEXDEBUG
114		if(debug){
115			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
116			allprint(yych);
117			putchar('\n');
118			}
119# endif
120		while (lsp-- > yylstate){
121			*yylastch-- = 0;
122			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
123				yyolsp = lsp;
124				if(yyextra[*yyfnd]){		/* must backup */
125					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
126						lsp--;
127						unput(*yylastch--);
128						}
129					}
130				yyprevious = YYU(*yylastch);
131				yylsp = lsp;
132				yyleng = yylastch-yytext+1;
133				yytext[yyleng] = 0;
134# ifdef LEXDEBUG
135				if(debug){
136					fprintf(yyout,"\nmatch ");
137					sprint(yytext);
138					fprintf(yyout," action %d\n",*yyfnd);
139					}
140# endif
141				return(*yyfnd++);
142				}
143			unput(*yylastch);
144			}
145		if (yytext[0] == 0  /* && feof(yyin) */)
146			{
147			yysptr=yysbuf;
148			return(0);
149			}
150		yyprevious = yytext[0] = input();
151		if (yyprevious>0)
152			output(yyprevious);
153		yylastch=yytext;
154# ifdef LEXDEBUG
155		if(debug)putchar('\n');
156# endif
157		}
158	}
159yyback(p, m)
160	int *p;
161{
162if (p==0) return(0);
163while (*p)
164	{
165	if (*p++ == m)
166		return(1);
167	}
168return(0);
169}
170	/* the following are only used in the lex library */
171yyinput(){
172	return(input());
173	}
174yyoutput(c)
175  int c; {
176	output(c);
177	}
178yyunput(c)
179   int c; {
180	unput(c);
181	}
182