]> git.saurik.com Git - bison.git/blob - data/bison.hairy
* src/output.c (output_rule_data): Don't output NULL, it might
[bison.git] / data / bison.hairy
1 %%{section} %%{output-prefix} %%{output-infix} %%".c"
2 /* -*- C -*- */
3
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. */
9 static int yyerror;
10 static int yycost;
11
12 /* YYMAXDEPTH indicates the size of the parser's state and value
13 stacks. */
14
15 #ifndef YYMAXDEPTH
16 # define YYMAXDEPTH 500
17 #endif
18
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 */
23
24 #ifndef YYMAXRULES
25 # define YYMAXRULES 100
26 #endif
27
28 #ifndef YYMAXBACKUP
29 # define YYMAXBACKUP 100
30 #endif
31
32
33 /* The state stack. */
34 static short yyss[YYMAXDEPTH];
35 /* The semantic value stack. */
36 static YYSTYPE yyvs[YYMAXDEPTH];
37 /* The location stack. */
38 static YYLTYPE yyls[YYMAXDEPTH];
39 /* The rule queue. */
40 static short yyrq[YYMAXRULES];
41 /* The lookahead symbol. */
42 static int yychar;
43
44 /* the semantic value of the lookahead symbol. */
45 static YYSTYPE yylval;
46
47 /* the semantic value for the state at the top of the state stack. */
48 static YYSTYPE yytval;
49
50 /* the variable used to return semantic values from the action
51 routines. */
52 static YYSTYPE yyval;
53
54 /* location data for the lookahead symbol. */
55 static YYLTYPE yylloc;
56
57 /* location data for the state at the top of the state stack. */
58 static YYLTYPE yytloc;
59
60
61 static int yynunlexed;
62 static short yyunchar[YYMAXBACKUP];
63 static YYSTYPE yyunval[YYMAXBACKUP];
64 static YYLTYPE yyunloc[YYMAXBACKUP];
65
66 /* a pointer to the top of the state stack; only set during error
67 recovery. */
68 static short *yygssp;
69
70 /* a pointer to the top of the value stack; only set during error
71 recovery. */
72 static YYSTYPE *yygvsp;
73
74 /* a pointer to the top of the location stack; only set during error
75 recovery. */
76 static YYLTYPE *yyglsp;
77
78
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 `--------------------------------------------------------------------*/
84
85 static inline void
86 yyget (void)
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 {
99 yychar = yylex ();
100 if (yychar < 0)
101 yychar = 0;
102 else
103 yychar = YYTRANSLATE (yychar);
104 }
105 }
106
107
108 static inline void
109 yyunlex (int chr, YYSTYPE val, YYLTYPE loc)
110 {
111 yyunchar[yynunlexed] = chr;
112 yyunval[yynunlexed] = val;
113 yyunloc[yynunlexed] = loc;
114 yynunlexed++;
115 }
116
117
118 static inline void
119 yyrestore (short *first, short *last)
120 {
121 short *ssp;
122 short *rp;
123 int symbol;
124 int state;
125 int tvalsaved;
126
127 ssp = yygssp;
128 yyunlex (yychar, yylval, yylloc);
129
130 tvalsaved = 0;
131 while (first != last)
132 {
133 symbol = yystos[*ssp];
134 if (symbol < YYNTBASE)
135 {
136 yyunlex (symbol, yytval, yytloc);
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
166 if (!tvalsaved && ssp > yyss)
167 {
168 yyunlex (yystos[*ssp], yytval, yytloc);
169 ssp--;
170 }
171
172 yygssp = ssp;
173 }
174
175
176
177 int
178 yyparse (void)
179 {
180 int yystate;
181 int yyn;
182 short *yyssp;
183 short *yyrq0;
184 short *yyptr;
185 YYSTYPE *yyvsp;
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
200 yychar = yylex ();
201 if (yychar < 0)
202 yychar = 0;
203 else
204 yychar = YYTRANSLATE (yychar);
205
206 yynewstate:
207
208 if (yyssp >= yyss + YYMAXDEPTH - 1)
209 {
210 yyabort ("Parser Stack Overflow");
211 YYABORT;
212 }
213
214 *++yyssp = yystate;
215
216 yyresume:
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
245 yyguard (yyn, yyvsp, yylsp);
246 if (yyerror)
247 goto yysemerr;
248
249 yyaction (yyn, yyvsp, yylsp);
250 *++yyvsp = yyval;
251
252 yylsp++;
253 if (yylen == 0)
254 {
255 yylsp->first_line = yytloc.first_line;
256 yylsp->first_column = yytloc.first_column;
257 yylsp->last_line = (yylsp - 1)->last_line;
258 yylsp->last_column = (yylsp - 1)->last_column;
259 yylsp->text = 0;
260 }
261 else
262 {
263 yylsp->last_line = (yylsp + yylen - 1)->last_line;
264 yylsp->last_column = (yylsp + yylen - 1)->last_column;
265 }
266
267 if (yyptr == yyrq + YYMAXRULES)
268 yyptr = yyrq;
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;
281 yyget ();
282
283 goto yynewstate;
284
285 yydefault:
286
287 yyn = yydefact[yystate];
288 if (yyn == 0)
289 goto yyerrlab;
290
291 yyreduce:
292
293 *yyrq0++ = yyn;
294
295 if (yyrq0 == yyrq + YYMAXRULES)
296 yyrq0 = yyrq;
297
298 if (yyrq0 == yyrq2)
299 {
300 yyabort ("Parser Rule Queue Overflow");
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
315 yysemerr:
316 *--yyptr = yyn;
317 yyrq2 = yyptr;
318 yyvsp += yyr2[yyn];
319
320 yyerrlab:
321
322 yygssp = yyssp;
323 yygvsp = yyvsp;
324 yyglsp = yylsp;
325 yyrestore (yyrq0, yyrq2);
326 yyrecover ();
327 yystate = *yygssp;
328 yyssp = yygssp;
329 yyvsp = yygvsp;
330 yyrq0 = yyrq;
331 yyrq1 = yyrq0;
332 yyrq2 = yyrq0;
333 goto yyresume;
334 }
335
336 %%{actions}