]> git.saurik.com Git - bison.git/blame - src/bison.hairy
Regen.
[bison.git] / src / bison.hairy
CommitLineData
9b3add5b 1%%{section} %%{body} %%".c" %%{yacc}
1b177bd7 2 /* -*- C -*- */
f791019c 3
1b177bd7
AD
4/* YYERROR and YYCOST are set by guards. If yyerror is set to a
5 nonzero value by a guard, the reduction with which the guard is
6 associated is not performed, and the error recovery mechanism is
7 invoked. Yycost indicates the cost of performing the reduction
8 given the attributes of the symbols. */
9static int yyerror;
10static int yycost;
f791019c 11
1b177bd7
AD
12/* YYMAXDEPTH indicates the size of the parser's state and value
13 stacks. */
f791019c
RS
14
15#ifndef YYMAXDEPTH
1b177bd7 16# define YYMAXDEPTH 500
f791019c
RS
17#endif
18
1b177bd7
AD
19/* YYMAXRULES must be at least as large as the number of rules that
20 could be placed in the rule queue. That number could be determined
21 from the grammar and the size of the stack, but, as yet, it is not.
22 */
f791019c
RS
23
24#ifndef YYMAXRULES
1b177bd7 25# define YYMAXRULES 100
f791019c
RS
26#endif
27
28#ifndef YYMAXBACKUP
1b177bd7 29# define YYMAXBACKUP 100
f791019c
RS
30#endif
31
32
1b177bd7
AD
33/* The state stack. */
34static short yyss[YYMAXDEPTH];
35/* The semantic value stack. */
36static YYSTYPE yyvs[YYMAXDEPTH];
37/* The location stack. */
38static YYLTYPE yyls[YYMAXDEPTH];
39/* The rule queue. */
40static short yyrq[YYMAXRULES];
41/* The lookahead symbol. */
42static int yychar;
f791019c 43
1b177bd7
AD
44/* the semantic value of the lookahead symbol. */
45static YYSTYPE yylval;
f791019c 46
1b177bd7
AD
47/* the semantic value for the state at the top of the state stack. */
48static YYSTYPE yytval;
f791019c 49
1b177bd7
AD
50/* the variable used to return semantic values from the action
51 routines. */
52static YYSTYPE yyval;
f791019c 53
1b177bd7
AD
54/* location data for the lookahead symbol. */
55static YYLTYPE yylloc;
f791019c 56
1b177bd7
AD
57/* location data for the state at the top of the state stack. */
58static YYLTYPE yytloc;
f791019c
RS
59
60
1b177bd7
AD
61static int yynunlexed;
62static short yyunchar[YYMAXBACKUP];
63static YYSTYPE yyunval[YYMAXBACKUP];
64static YYLTYPE yyunloc[YYMAXBACKUP];
f791019c 65
1b177bd7
AD
66/* a pointer to the top of the state stack; only set during error
67 recovery. */
68static short *yygssp;
f791019c 69
1b177bd7
AD
70/* a pointer to the top of the value stack; only set during error
71 recovery. */
72static YYSTYPE *yygvsp;
f791019c 73
1b177bd7
AD
74/* a pointer to the top of the location stack; only set during error
75 recovery. */
76static YYLTYPE *yyglsp;
f791019c
RS
77
78
1b177bd7
AD
79/*--------------------------------------------------------------------.
80| Yyget is an interface between the parser and the lexical analyzer. |
81| It is costly to provide such an interface, but it avoids requiring |
82| the lexical analyzer to be able to back up the scan. |
83`--------------------------------------------------------------------*/
f791019c 84
1b177bd7
AD
85static inline void
86yyget (void)
f791019c
RS
87{
88 if (yynunlexed > 0)
89 {
90 yynunlexed--;
91 yychar = yyunchar[yynunlexed];
92 yylval = yyunval[yynunlexed];
93 yylloc = yyunloc[yynunlexed];
94 }
95 else if (yychar <= 0)
96 yychar = 0;
97 else
98 {
1b177bd7 99 yychar = yylex ();
f791019c
RS
100 if (yychar < 0)
101 yychar = 0;
1b177bd7
AD
102 else
103 yychar = YYTRANSLATE (yychar);
f791019c
RS
104 }
105}
106
107
1b177bd7
AD
108static inline void
109yyunlex (int chr, YYSTYPE val, YYLTYPE loc)
f791019c
RS
110{
111 yyunchar[yynunlexed] = chr;
112 yyunval[yynunlexed] = val;
113 yyunloc[yynunlexed] = loc;
114 yynunlexed++;
115}
116
117
1b177bd7
AD
118static inline void
119yyrestore (short *first, short *last)
f791019c 120{
1b177bd7
AD
121 short *ssp;
122 short *rp;
123 int symbol;
124 int state;
125 int tvalsaved;
f791019c
RS
126
127 ssp = yygssp;
1b177bd7 128 yyunlex (yychar, yylval, yylloc);
f791019c
RS
129
130 tvalsaved = 0;
131 while (first != last)
132 {
133 symbol = yystos[*ssp];
134 if (symbol < YYNTBASE)
135 {
1b177bd7 136 yyunlex (symbol, yytval, yytloc);
f791019c
RS
137 tvalsaved = 1;
138 ssp--;
139 }
140
141 ssp--;
142
143 if (first == yyrq)
144 first = yyrq + YYMAXRULES;
145
146 first--;
147
148 for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
149 {
150 if (symbol < YYNTBASE)
151 state = yytable[yypact[*ssp] + symbol];
152 else
153 {
154 state = yypgoto[symbol - YYNTBASE] + *ssp;
155
156 if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
157 state = yytable[state];
158 else
159 state = yydefgoto[symbol - YYNTBASE];
160 }
161
162 *++ssp = state;
163 }
164 }
165
1b177bd7 166 if (!tvalsaved && ssp > yyss)
f791019c 167 {
1b177bd7 168 yyunlex (yystos[*ssp], yytval, yytloc);
f791019c
RS
169 ssp--;
170 }
171
172 yygssp = ssp;
173}
174
175
176
177int
1b177bd7 178yyparse (void)
f791019c 179{
1b177bd7
AD
180 int yystate;
181 int yyn;
182 short *yyssp;
183 short *yyrq0;
184 short *yyptr;
185 YYSTYPE *yyvsp;
f791019c
RS
186
187 int yylen;
188 YYLTYPE *yylsp;
189 short *yyrq1;
190 short *yyrq2;
191
192 yystate = 0;
193 yyssp = yyss - 1;
194 yyvsp = yyvs - 1;
195 yylsp = yyls - 1;
196 yyrq0 = yyrq;
197 yyrq1 = yyrq0;
198 yyrq2 = yyrq0;
199
1b177bd7 200 yychar = yylex ();
f791019c
RS
201 if (yychar < 0)
202 yychar = 0;
1b177bd7
AD
203 else
204 yychar = YYTRANSLATE (yychar);
f791019c
RS
205
206yynewstate:
207
208 if (yyssp >= yyss + YYMAXDEPTH - 1)
209 {
1b177bd7 210 yyabort ("Parser Stack Overflow");
f791019c
RS
211 YYABORT;
212 }
213
214 *++yyssp = yystate;
215
216yyresume:
217
218 yyn = yypact[yystate];
219 if (yyn == YYFLAG)
220 goto yydefault;
221
222 yyn += yychar;
223 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
224 goto yydefault;
225
226 yyn = yytable[yyn];
227 if (yyn < 0)
228 {
229 yyn = -yyn;
230 goto yyreduce;
231 }
232 else if (yyn == 0)
233 goto yyerrlab;
234
235 yystate = yyn;
236
237 yyptr = yyrq2;
238 while (yyptr != yyrq1)
239 {
240 yyn = *yyptr++;
241 yylen = yyr2[yyn];
242 yyvsp -= yylen;
243 yylsp -= yylen;
244
1b177bd7 245 yyguard (yyn, yyvsp, yylsp);
f791019c
RS
246 if (yyerror)
247 goto yysemerr;
248
1b177bd7 249 yyaction (yyn, yyvsp, yylsp);
f791019c
RS
250 *++yyvsp = yyval;
251
252 yylsp++;
253 if (yylen == 0)
254 {
f791019c
RS
255 yylsp->first_line = yytloc.first_line;
256 yylsp->first_column = yytloc.first_column;
1b177bd7
AD
257 yylsp->last_line = (yylsp - 1)->last_line;
258 yylsp->last_column = (yylsp - 1)->last_column;
f791019c
RS
259 yylsp->text = 0;
260 }
261 else
262 {
1b177bd7
AD
263 yylsp->last_line = (yylsp + yylen - 1)->last_line;
264 yylsp->last_column = (yylsp + yylen - 1)->last_column;
f791019c 265 }
573c1d9f 266
f791019c 267 if (yyptr == yyrq + YYMAXRULES)
1b177bd7 268 yyptr = yyrq;
f791019c
RS
269 }
270
271 if (yystate == YYFINAL)
272 YYACCEPT;
273
274 yyrq2 = yyptr;
275 yyrq1 = yyrq0;
276
277 *++yyvsp = yytval;
278 *++yylsp = yytloc;
279 yytval = yylval;
280 yytloc = yylloc;
1b177bd7 281 yyget ();
f791019c
RS
282
283 goto yynewstate;
284
285yydefault:
286
287 yyn = yydefact[yystate];
288 if (yyn == 0)
289 goto yyerrlab;
290
291yyreduce:
292
293 *yyrq0++ = yyn;
294
295 if (yyrq0 == yyrq + YYMAXRULES)
296 yyrq0 = yyrq;
297
298 if (yyrq0 == yyrq2)
299 {
1b177bd7 300 yyabort ("Parser Rule Queue Overflow");
f791019c
RS
301 YYABORT;
302 }
303
304 yyssp -= yyr2[yyn];
305 yyn = yyr1[yyn];
306
307 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
308 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
309 yystate = yytable[yystate];
310 else
311 yystate = yydefgoto[yyn - YYNTBASE];
312
313 goto yynewstate;
314
315yysemerr:
316 *--yyptr = yyn;
317 yyrq2 = yyptr;
318 yyvsp += yyr2[yyn];
319
320yyerrlab:
321
322 yygssp = yyssp;
323 yygvsp = yyvsp;
324 yyglsp = yylsp;
1b177bd7
AD
325 yyrestore (yyrq0, yyrq2);
326 yyrecover ();
f791019c
RS
327 yystate = *yygssp;
328 yyssp = yygssp;
329 yyvsp = yygvsp;
330 yyrq0 = yyrq;
331 yyrq1 = yyrq0;
332 yyrq2 = yyrq0;
333 goto yyresume;
334}
335
9b3add5b 336%%{actions}