]> git.saurik.com Git - bison.git/blame - src/bison.hairy
* src/gram.c (ritem_print): Be sure to subtract 1 when displaying
[bison.git] / src / bison.hairy
CommitLineData
1b177bd7 1 /* -*- C -*- */
f791019c 2
1b177bd7
AD
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;
f791019c 10
1b177bd7
AD
11/* YYMAXDEPTH indicates the size of the parser's state and value
12 stacks. */
f791019c
RS
13
14#ifndef YYMAXDEPTH
1b177bd7 15# define YYMAXDEPTH 500
f791019c
RS
16#endif
17
1b177bd7
AD
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 */
f791019c
RS
22
23#ifndef YYMAXRULES
1b177bd7 24# define YYMAXRULES 100
f791019c
RS
25#endif
26
27#ifndef YYMAXBACKUP
1b177bd7 28# define YYMAXBACKUP 100
f791019c
RS
29#endif
30
31
1b177bd7
AD
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;
f791019c 42
1b177bd7
AD
43/* the semantic value of the lookahead symbol. */
44static YYSTYPE yylval;
f791019c 45
1b177bd7
AD
46/* the semantic value for the state at the top of the state stack. */
47static YYSTYPE yytval;
f791019c 48
1b177bd7
AD
49/* the variable used to return semantic values from the action
50 routines. */
51static YYSTYPE yyval;
f791019c 52
1b177bd7
AD
53/* location data for the lookahead symbol. */
54static YYLTYPE yylloc;
f791019c 55
1b177bd7
AD
56/* location data for the state at the top of the state stack. */
57static YYLTYPE yytloc;
f791019c
RS
58
59
1b177bd7
AD
60static int yynunlexed;
61static short yyunchar[YYMAXBACKUP];
62static YYSTYPE yyunval[YYMAXBACKUP];
63static YYLTYPE yyunloc[YYMAXBACKUP];
f791019c 64
1b177bd7
AD
65/* a pointer to the top of the state stack; only set during error
66 recovery. */
67static short *yygssp;
f791019c 68
1b177bd7
AD
69/* a pointer to the top of the value stack; only set during error
70 recovery. */
71static YYSTYPE *yygvsp;
f791019c 72
1b177bd7
AD
73/* a pointer to the top of the location stack; only set during error
74 recovery. */
75static YYLTYPE *yyglsp;
f791019c
RS
76
77
1b177bd7
AD
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`--------------------------------------------------------------------*/
f791019c 83
1b177bd7
AD
84static inline void
85yyget (void)
f791019c
RS
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 {
1b177bd7 98 yychar = yylex ();
f791019c
RS
99 if (yychar < 0)
100 yychar = 0;
1b177bd7
AD
101 else
102 yychar = YYTRANSLATE (yychar);
f791019c
RS
103 }
104}
105
106
1b177bd7
AD
107static inline void
108yyunlex (int chr, YYSTYPE val, YYLTYPE loc)
f791019c
RS
109{
110 yyunchar[yynunlexed] = chr;
111 yyunval[yynunlexed] = val;
112 yyunloc[yynunlexed] = loc;
113 yynunlexed++;
114}
115
116
1b177bd7
AD
117static inline void
118yyrestore (short *first, short *last)
f791019c 119{
1b177bd7
AD
120 short *ssp;
121 short *rp;
122 int symbol;
123 int state;
124 int tvalsaved;
f791019c
RS
125
126 ssp = yygssp;
1b177bd7 127 yyunlex (yychar, yylval, yylloc);
f791019c
RS
128
129 tvalsaved = 0;
130 while (first != last)
131 {
132 symbol = yystos[*ssp];
133 if (symbol < YYNTBASE)
134 {
1b177bd7 135 yyunlex (symbol, yytval, yytloc);
f791019c
RS
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
1b177bd7 165 if (!tvalsaved && ssp > yyss)
f791019c 166 {
1b177bd7 167 yyunlex (yystos[*ssp], yytval, yytloc);
f791019c
RS
168 ssp--;
169 }
170
171 yygssp = ssp;
172}
173
174
175
176int
1b177bd7 177yyparse (void)
f791019c 178{
1b177bd7
AD
179 int yystate;
180 int yyn;
181 short *yyssp;
182 short *yyrq0;
183 short *yyptr;
184 YYSTYPE *yyvsp;
f791019c
RS
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
1b177bd7 199 yychar = yylex ();
f791019c
RS
200 if (yychar < 0)
201 yychar = 0;
1b177bd7
AD
202 else
203 yychar = YYTRANSLATE (yychar);
f791019c
RS
204
205yynewstate:
206
207 if (yyssp >= yyss + YYMAXDEPTH - 1)
208 {
1b177bd7 209 yyabort ("Parser Stack Overflow");
f791019c
RS
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
1b177bd7 244 yyguard (yyn, yyvsp, yylsp);
f791019c
RS
245 if (yyerror)
246 goto yysemerr;
247
1b177bd7 248 yyaction (yyn, yyvsp, yylsp);
f791019c
RS
249 *++yyvsp = yyval;
250
251 yylsp++;
252 if (yylen == 0)
253 {
f791019c
RS
254 yylsp->first_line = yytloc.first_line;
255 yylsp->first_column = yytloc.first_column;
1b177bd7
AD
256 yylsp->last_line = (yylsp - 1)->last_line;
257 yylsp->last_column = (yylsp - 1)->last_column;
f791019c
RS
258 yylsp->text = 0;
259 }
260 else
261 {
1b177bd7
AD
262 yylsp->last_line = (yylsp + yylen - 1)->last_line;
263 yylsp->last_column = (yylsp + yylen - 1)->last_column;
f791019c 264 }
573c1d9f 265
f791019c 266 if (yyptr == yyrq + YYMAXRULES)
1b177bd7 267 yyptr = yyrq;
f791019c
RS
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;
1b177bd7 280 yyget ();
f791019c
RS
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 {
1b177bd7 299 yyabort ("Parser Rule Queue Overflow");
f791019c
RS
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;
1b177bd7
AD
324 yyrestore (yyrq0, yyrq2);
325 yyrecover ();
f791019c
RS
326 yystate = *yygssp;
327 yyssp = yygssp;
328 yyvsp = yygvsp;
329 yyrq0 = yyrq;
330 yyrq1 = yyrq0;
331 yyrq2 = yyrq0;
332 goto yyresume;
333}
334
1b177bd7 335%%actions