Blame


1 c72688ef 2003-12-04 devnull #define YYFLAG -1000
2 c72688ef 2003-12-04 devnull #define yyclearin yychar = -1
3 c72688ef 2003-12-04 devnull #define yyerrok yyerrflag = 0
4 c72688ef 2003-12-04 devnull
5 c72688ef 2003-12-04 devnull #ifdef yydebug
6 c72688ef 2003-12-04 devnull #include "y.debug"
7 c72688ef 2003-12-04 devnull #else
8 c72688ef 2003-12-04 devnull #define yydebug 0
9 c72688ef 2003-12-04 devnull char* yytoknames[1]; /* for debugging */
10 c72688ef 2003-12-04 devnull char* yystates[1]; /* for debugging */
11 c72688ef 2003-12-04 devnull #endif
12 c72688ef 2003-12-04 devnull
13 c72688ef 2003-12-04 devnull /* parser for yacc output */
14 c72688ef 2003-12-04 devnull
15 c72688ef 2003-12-04 devnull int yynerrs = 0; /* number of errors */
16 c72688ef 2003-12-04 devnull int yyerrflag = 0; /* error recovery flag */
17 c72688ef 2003-12-04 devnull
18 c72688ef 2003-12-04 devnull extern int fprint(int, char*, ...);
19 c72688ef 2003-12-04 devnull extern int sprint(char*, char*, ...);
20 c72688ef 2003-12-04 devnull
21 c72688ef 2003-12-04 devnull char*
22 c72688ef 2003-12-04 devnull yytokname(int yyc)
23 c72688ef 2003-12-04 devnull {
24 c72688ef 2003-12-04 devnull static char x[10];
25 c72688ef 2003-12-04 devnull
26 c72688ef 2003-12-04 devnull if(yyc > 0 && yyc <= sizeof(yytoknames)/sizeof(yytoknames[0]))
27 c72688ef 2003-12-04 devnull if(yytoknames[yyc-1])
28 c72688ef 2003-12-04 devnull return yytoknames[yyc-1];
29 c72688ef 2003-12-04 devnull sprint(x, "<%d>", yyc);
30 c72688ef 2003-12-04 devnull return x;
31 c72688ef 2003-12-04 devnull }
32 c72688ef 2003-12-04 devnull
33 c72688ef 2003-12-04 devnull char*
34 c72688ef 2003-12-04 devnull yystatname(int yys)
35 c72688ef 2003-12-04 devnull {
36 c72688ef 2003-12-04 devnull static char x[10];
37 c72688ef 2003-12-04 devnull
38 c72688ef 2003-12-04 devnull if(yys >= 0 && yys < sizeof(yystates)/sizeof(yystates[0]))
39 c72688ef 2003-12-04 devnull if(yystates[yys])
40 c72688ef 2003-12-04 devnull return yystates[yys];
41 c72688ef 2003-12-04 devnull sprint(x, "<%d>\n", yys);
42 c72688ef 2003-12-04 devnull return x;
43 c72688ef 2003-12-04 devnull }
44 c72688ef 2003-12-04 devnull
45 c72688ef 2003-12-04 devnull long
46 c72688ef 2003-12-04 devnull yylex1(void)
47 c72688ef 2003-12-04 devnull {
48 c72688ef 2003-12-04 devnull long yychar;
49 c72688ef 2003-12-04 devnull long *t3p;
50 c72688ef 2003-12-04 devnull int c;
51 c72688ef 2003-12-04 devnull
52 c72688ef 2003-12-04 devnull yychar = yylex();
53 c72688ef 2003-12-04 devnull if(yychar <= 0) {
54 c72688ef 2003-12-04 devnull c = yytok1[0];
55 c72688ef 2003-12-04 devnull goto out;
56 c72688ef 2003-12-04 devnull }
57 c72688ef 2003-12-04 devnull if(yychar < sizeof(yytok1)/sizeof(yytok1[0])) {
58 c72688ef 2003-12-04 devnull c = yytok1[yychar];
59 c72688ef 2003-12-04 devnull goto out;
60 c72688ef 2003-12-04 devnull }
61 c72688ef 2003-12-04 devnull if(yychar >= YYPRIVATE)
62 c72688ef 2003-12-04 devnull if(yychar < YYPRIVATE+sizeof(yytok2)/sizeof(yytok2[0])) {
63 c72688ef 2003-12-04 devnull c = yytok2[yychar-YYPRIVATE];
64 c72688ef 2003-12-04 devnull goto out;
65 c72688ef 2003-12-04 devnull }
66 c72688ef 2003-12-04 devnull for(t3p=yytok3;; t3p+=2) {
67 c72688ef 2003-12-04 devnull c = t3p[0];
68 c72688ef 2003-12-04 devnull if(c == yychar) {
69 c72688ef 2003-12-04 devnull c = t3p[1];
70 c72688ef 2003-12-04 devnull goto out;
71 c72688ef 2003-12-04 devnull }
72 c72688ef 2003-12-04 devnull if(c == 0)
73 c72688ef 2003-12-04 devnull break;
74 c72688ef 2003-12-04 devnull }
75 c72688ef 2003-12-04 devnull c = 0;
76 c72688ef 2003-12-04 devnull
77 c72688ef 2003-12-04 devnull out:
78 c72688ef 2003-12-04 devnull if(c == 0)
79 c72688ef 2003-12-04 devnull c = yytok2[1]; /* unknown char */
80 c72688ef 2003-12-04 devnull if(yydebug >= 3)
81 c72688ef 2003-12-04 devnull fprint(2, "lex %.4lux %s\n", yychar, yytokname(c));
82 c72688ef 2003-12-04 devnull return c;
83 c72688ef 2003-12-04 devnull }
84 c72688ef 2003-12-04 devnull
85 c72688ef 2003-12-04 devnull int
86 c72688ef 2003-12-04 devnull yyparse(void)
87 c72688ef 2003-12-04 devnull {
88 c72688ef 2003-12-04 devnull struct
89 c72688ef 2003-12-04 devnull {
90 c72688ef 2003-12-04 devnull YYSTYPE yyv;
91 c72688ef 2003-12-04 devnull int yys;
92 c72688ef 2003-12-04 devnull } yys[YYMAXDEPTH], *yyp, *yypt;
93 c72688ef 2003-12-04 devnull short *yyxi;
94 c72688ef 2003-12-04 devnull int yyj, yym, yystate, yyn, yyg;
95 c72688ef 2003-12-04 devnull long yychar;
96 c72688ef 2003-12-04 devnull YYSTYPE save1, save2;
97 c72688ef 2003-12-04 devnull int save3, save4;
98 c72688ef 2003-12-04 devnull
99 c72688ef 2003-12-04 devnull save1 = yylval;
100 c72688ef 2003-12-04 devnull save2 = yyval;
101 c72688ef 2003-12-04 devnull save3 = yynerrs;
102 c72688ef 2003-12-04 devnull save4 = yyerrflag;
103 c72688ef 2003-12-04 devnull
104 c72688ef 2003-12-04 devnull yystate = 0;
105 c72688ef 2003-12-04 devnull yychar = -1;
106 c72688ef 2003-12-04 devnull yynerrs = 0;
107 c72688ef 2003-12-04 devnull yyerrflag = 0;
108 c72688ef 2003-12-04 devnull yyp = &yys[-1];
109 c72688ef 2003-12-04 devnull goto yystack;
110 c72688ef 2003-12-04 devnull
111 c72688ef 2003-12-04 devnull ret0:
112 c72688ef 2003-12-04 devnull yyn = 0;
113 c72688ef 2003-12-04 devnull goto ret;
114 c72688ef 2003-12-04 devnull
115 c72688ef 2003-12-04 devnull ret1:
116 c72688ef 2003-12-04 devnull yyn = 1;
117 c72688ef 2003-12-04 devnull goto ret;
118 c72688ef 2003-12-04 devnull
119 c72688ef 2003-12-04 devnull ret:
120 c72688ef 2003-12-04 devnull yylval = save1;
121 c72688ef 2003-12-04 devnull yyval = save2;
122 c72688ef 2003-12-04 devnull yynerrs = save3;
123 c72688ef 2003-12-04 devnull yyerrflag = save4;
124 c72688ef 2003-12-04 devnull return yyn;
125 c72688ef 2003-12-04 devnull
126 c72688ef 2003-12-04 devnull yystack:
127 c72688ef 2003-12-04 devnull /* put a state and value onto the stack */
128 c72688ef 2003-12-04 devnull if(yydebug >= 4)
129 c72688ef 2003-12-04 devnull fprint(2, "char %s in %s", yytokname(yychar), yystatname(yystate));
130 c72688ef 2003-12-04 devnull
131 c72688ef 2003-12-04 devnull yyp++;
132 c72688ef 2003-12-04 devnull if(yyp >= &yys[YYMAXDEPTH]) {
133 c72688ef 2003-12-04 devnull yyerror("yacc stack overflow");
134 c72688ef 2003-12-04 devnull goto ret1;
135 c72688ef 2003-12-04 devnull }
136 c72688ef 2003-12-04 devnull yyp->yys = yystate;
137 c72688ef 2003-12-04 devnull yyp->yyv = yyval;
138 c72688ef 2003-12-04 devnull
139 c72688ef 2003-12-04 devnull yynewstate:
140 c72688ef 2003-12-04 devnull yyn = yypact[yystate];
141 c72688ef 2003-12-04 devnull if(yyn <= YYFLAG)
142 c72688ef 2003-12-04 devnull goto yydefault; /* simple state */
143 c72688ef 2003-12-04 devnull if(yychar < 0)
144 c72688ef 2003-12-04 devnull yychar = yylex1();
145 c72688ef 2003-12-04 devnull yyn += yychar;
146 c72688ef 2003-12-04 devnull if(yyn < 0 || yyn >= YYLAST)
147 c72688ef 2003-12-04 devnull goto yydefault;
148 c72688ef 2003-12-04 devnull yyn = yyact[yyn];
149 c72688ef 2003-12-04 devnull if(yychk[yyn] == yychar) { /* valid shift */
150 c72688ef 2003-12-04 devnull yychar = -1;
151 c72688ef 2003-12-04 devnull yyval = yylval;
152 c72688ef 2003-12-04 devnull yystate = yyn;
153 c72688ef 2003-12-04 devnull if(yyerrflag > 0)
154 c72688ef 2003-12-04 devnull yyerrflag--;
155 c72688ef 2003-12-04 devnull goto yystack;
156 c72688ef 2003-12-04 devnull }
157 c72688ef 2003-12-04 devnull
158 c72688ef 2003-12-04 devnull yydefault:
159 c72688ef 2003-12-04 devnull /* default state action */
160 c72688ef 2003-12-04 devnull yyn = yydef[yystate];
161 c72688ef 2003-12-04 devnull if(yyn == -2) {
162 c72688ef 2003-12-04 devnull if(yychar < 0)
163 c72688ef 2003-12-04 devnull yychar = yylex1();
164 c72688ef 2003-12-04 devnull
165 c72688ef 2003-12-04 devnull /* look through exception table */
166 c72688ef 2003-12-04 devnull for(yyxi=yyexca;; yyxi+=2)
167 c72688ef 2003-12-04 devnull if(yyxi[0] == -1 && yyxi[1] == yystate)
168 c72688ef 2003-12-04 devnull break;
169 c72688ef 2003-12-04 devnull for(yyxi += 2;; yyxi += 2) {
170 c72688ef 2003-12-04 devnull yyn = yyxi[0];
171 c72688ef 2003-12-04 devnull if(yyn < 0 || yyn == yychar)
172 c72688ef 2003-12-04 devnull break;
173 c72688ef 2003-12-04 devnull }
174 c72688ef 2003-12-04 devnull yyn = yyxi[1];
175 c72688ef 2003-12-04 devnull if(yyn < 0)
176 c72688ef 2003-12-04 devnull goto ret0;
177 c72688ef 2003-12-04 devnull }
178 c72688ef 2003-12-04 devnull if(yyn == 0) {
179 c72688ef 2003-12-04 devnull /* error ... attempt to resume parsing */
180 c72688ef 2003-12-04 devnull switch(yyerrflag) {
181 c72688ef 2003-12-04 devnull case 0: /* brand new error */
182 c72688ef 2003-12-04 devnull yyerror("syntax error");
183 c72688ef 2003-12-04 devnull yynerrs++;
184 c72688ef 2003-12-04 devnull if(yydebug >= 1) {
185 c72688ef 2003-12-04 devnull fprint(2, "%s", yystatname(yystate));
186 c72688ef 2003-12-04 devnull fprint(2, "saw %s\n", yytokname(yychar));
187 c72688ef 2003-12-04 devnull }
188 c72688ef 2003-12-04 devnull
189 c72688ef 2003-12-04 devnull case 1:
190 c72688ef 2003-12-04 devnull case 2: /* incompletely recovered error ... try again */
191 c72688ef 2003-12-04 devnull yyerrflag = 3;
192 c72688ef 2003-12-04 devnull
193 c72688ef 2003-12-04 devnull /* find a state where "error" is a legal shift action */
194 c72688ef 2003-12-04 devnull while(yyp >= yys) {
195 c72688ef 2003-12-04 devnull yyn = yypact[yyp->yys] + YYERRCODE;
196 c72688ef 2003-12-04 devnull if(yyn >= 0 && yyn < YYLAST) {
197 c72688ef 2003-12-04 devnull yystate = yyact[yyn]; /* simulate a shift of "error" */
198 c72688ef 2003-12-04 devnull if(yychk[yystate] == YYERRCODE)
199 c72688ef 2003-12-04 devnull goto yystack;
200 c72688ef 2003-12-04 devnull }
201 c72688ef 2003-12-04 devnull
202 c72688ef 2003-12-04 devnull /* the current yyp has no shift onn "error", pop stack */
203 c72688ef 2003-12-04 devnull if(yydebug >= 2)
204 c72688ef 2003-12-04 devnull fprint(2, "error recovery pops state %d, uncovers %d\n",
205 c72688ef 2003-12-04 devnull yyp->yys, (yyp-1)->yys );
206 c72688ef 2003-12-04 devnull yyp--;
207 c72688ef 2003-12-04 devnull }
208 c72688ef 2003-12-04 devnull /* there is no state on the stack with an error shift ... abort */
209 c72688ef 2003-12-04 devnull goto ret1;
210 c72688ef 2003-12-04 devnull
211 c72688ef 2003-12-04 devnull case 3: /* no shift yet; clobber input char */
212 c72688ef 2003-12-04 devnull if(yydebug >= 2)
213 c72688ef 2003-12-04 devnull fprint(2, "error recovery discards %s\n", yytokname(yychar));
214 c72688ef 2003-12-04 devnull if(yychar == YYEOFCODE)
215 c72688ef 2003-12-04 devnull goto ret1;
216 c72688ef 2003-12-04 devnull yychar = -1;
217 c72688ef 2003-12-04 devnull goto yynewstate; /* try again in the same state */
218 c72688ef 2003-12-04 devnull }
219 c72688ef 2003-12-04 devnull }
220 c72688ef 2003-12-04 devnull
221 c72688ef 2003-12-04 devnull /* reduction by production yyn */
222 c72688ef 2003-12-04 devnull if(yydebug >= 2)
223 c72688ef 2003-12-04 devnull fprint(2, "reduce %d in:\n\t%s", yyn, yystatname(yystate));
224 c72688ef 2003-12-04 devnull
225 c72688ef 2003-12-04 devnull yypt = yyp;
226 c72688ef 2003-12-04 devnull yyp -= yyr2[yyn];
227 c72688ef 2003-12-04 devnull yyval = (yyp+1)->yyv;
228 c72688ef 2003-12-04 devnull yym = yyn;
229 c72688ef 2003-12-04 devnull
230 c72688ef 2003-12-04 devnull /* consult goto table to find next state */
231 c72688ef 2003-12-04 devnull yyn = yyr1[yyn];
232 c72688ef 2003-12-04 devnull yyg = yypgo[yyn];
233 c72688ef 2003-12-04 devnull yyj = yyg + yyp->yys + 1;
234 c72688ef 2003-12-04 devnull
235 c72688ef 2003-12-04 devnull if(yyj >= YYLAST || yychk[yystate=yyact[yyj]] != -yyn)
236 c72688ef 2003-12-04 devnull yystate = yyact[yyg];
237 c72688ef 2003-12-04 devnull switch(yym) {
238 c72688ef 2003-12-04 devnull $A
239 c72688ef 2003-12-04 devnull }
240 c72688ef 2003-12-04 devnull goto yystack; /* stack new state and value */
241 c72688ef 2003-12-04 devnull }