summaryrefslogtreecommitdiff
path: root/sys/src/liblex/reject.c
blob: 24e8bee1fa90719d479f3c61d85f83fc4edef1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include	<u.h>
#include	<libc.h>
#include	<stdio.h>

extern	FILE*	yyout;
extern	FILE*	yyin;
extern	int	yyprevious, *yyfnd;
extern	char	yyextra[];
extern	char	yytext[];
extern	int	yyleng;

extern
struct
{
	int *yyaa, *yybb;
	int *yystops;
} *yylstate [], **yylsp, **yyolsp;

int	yyback(int *p, int m);
int	yyinput(void);
void	yyoutput(int c);
void	yyunput(int c);

int
yyracc(int m)
{

	yyolsp = yylsp;
	if(yyextra[m]) {
		while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) {
			yylsp--;
			yyunput(yytext[--yyleng]);
		}
	}
	yyprevious = yytext[yyleng-1];
	yytext[yyleng] = 0;
	return m;
}

int
yyreject(void)
{
	for(; yylsp < yyolsp; yylsp++)
		yytext[yyleng++] = yyinput();
	if(*yyfnd > 0)
		return yyracc(*yyfnd++);
	while(yylsp-- > yylstate) {
		yyunput(yytext[yyleng-1]);
		yytext[--yyleng] = 0;
		if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0)
			return yyracc(*yyfnd++);
	}
	if(yytext[0] == 0)
		return 0;
	yyoutput(yyprevious = yyinput());
	yyleng = 0;
	return -1;
}