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