Berkeley YACC
1993-03-03
Berkeley's version of Yet Another Compiler Compiler
Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Groups
skeleton.c
Go to the documentation of this file.
1
#include "
defs.h
"
2
3
/* The definition of yysccsid in the banner should be replaced with */
4
/* a #pragma ident directive if the target C compiler supports */
5
/* #pragma ident directives. */
6
/* */
7
/* If the skeleton is changed, the banner should be changed so that */
8
/* the altered version can be easily distinguished from the original. */
9
/* */
10
/* The #defines included with the banner are there because they are */
11
/* useful in subsequent code. The macros #defined in the header or */
12
/* the body either are not useful outside of semantic actions or */
13
/* are conditional. */
14
15
char
*
banner
[] =
16
{
17
"#ifndef lint"
,
18
"static char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";"
,
19
"#endif"
,
20
"#define YYBYACC 1"
,
21
"#define YYMAJOR 1"
,
22
"#define YYMINOR 9"
,
23
"#define yyclearin (yychar=(-1))"
,
24
"#define yyerrok (yyerrflag=0)"
,
25
"#define YYRECOVERING (yyerrflag!=0)"
,
26
0
27
};
28
29
30
char
*
tables
[] =
31
{
32
"extern short yylhs[];"
,
33
"extern short yylen[];"
,
34
"extern short yydefred[];"
,
35
"extern short yydgoto[];"
,
36
"extern short yysindex[];"
,
37
"extern short yyrindex[];"
,
38
"extern short yygindex[];"
,
39
"extern short yytable[];"
,
40
"extern short yycheck[];"
,
41
"#if YYDEBUG"
,
42
"extern char *yyname[];"
,
43
"extern char *yyrule[];"
,
44
"#endif"
,
45
0
46
};
47
48
49
char
*
header
[] =
50
{
51
"#ifdef YYSTACKSIZE"
,
52
"#undef YYMAXDEPTH"
,
53
"#define YYMAXDEPTH YYSTACKSIZE"
,
54
"#else"
,
55
"#ifdef YYMAXDEPTH"
,
56
"#define YYSTACKSIZE YYMAXDEPTH"
,
57
"#else"
,
58
"#define YYSTACKSIZE 500"
,
59
"#define YYMAXDEPTH 500"
,
60
"#endif"
,
61
"#endif"
,
62
"int yydebug;"
,
63
"int yynerrs;"
,
64
"int yyerrflag;"
,
65
"int yychar;"
,
66
"short *yyssp;"
,
67
"YYSTYPE *yyvsp;"
,
68
"YYSTYPE yyval;"
,
69
"YYSTYPE yylval;"
,
70
"short yyss[YYSTACKSIZE];"
,
71
"YYSTYPE yyvs[YYSTACKSIZE];"
,
72
"#define yystacksize YYSTACKSIZE"
,
73
0
74
};
75
76
77
char
*
body
[] =
78
{
79
"#define YYABORT goto yyabort"
,
80
"#define YYREJECT goto yyabort"
,
81
"#define YYACCEPT goto yyaccept"
,
82
"#define YYERROR goto yyerrlab"
,
83
"int"
,
84
"yyparse()"
,
85
"{"
,
86
" register int yym, yyn, yystate;"
,
87
"#if YYDEBUG"
,
88
" register char *yys;"
,
89
" extern char *getenv();"
,
90
""
,
91
" if (yys = getenv(\"YYDEBUG\"))"
,
92
" {"
,
93
" yyn = *yys;"
,
94
" if (yyn >= '0' && yyn <= '9')"
,
95
" yydebug = yyn - '0';"
,
96
" }"
,
97
"#endif"
,
98
""
,
99
" yynerrs = 0;"
,
100
" yyerrflag = 0;"
,
101
" yychar = (-1);"
,
102
""
,
103
" yyssp = yyss;"
,
104
" yyvsp = yyvs;"
,
105
" *yyssp = yystate = 0;"
,
106
""
,
107
"yyloop:"
,
108
" if (yyn = yydefred[yystate]) goto yyreduce;"
,
109
" if (yychar < 0)"
,
110
" {"
,
111
" if ((yychar = yylex()) < 0) yychar = 0;"
,
112
"#if YYDEBUG"
,
113
" if (yydebug)"
,
114
" {"
,
115
" yys = 0;"
,
116
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];"
,
117
" if (!yys) yys = \"illegal-symbol\";"
,
118
" printf(\"%sdebug: state %d, reading %d (%s)\\n\","
,
119
" YYPREFIX, yystate, yychar, yys);"
,
120
" }"
,
121
"#endif"
,
122
" }"
,
123
" if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&"
,
124
" yyn <= YYTABLESIZE && yycheck[yyn] == yychar)"
,
125
" {"
,
126
"#if YYDEBUG"
,
127
" if (yydebug)"
,
128
" printf(\"%sdebug: state %d, shifting to state %d\\n\","
,
129
" YYPREFIX, yystate, yytable[yyn]);"
,
130
"#endif"
,
131
" if (yyssp >= yyss + yystacksize - 1)"
,
132
" {"
,
133
" goto yyoverflow;"
,
134
" }"
,
135
" *++yyssp = yystate = yytable[yyn];"
,
136
" *++yyvsp = yylval;"
,
137
" yychar = (-1);"
,
138
" if (yyerrflag > 0) --yyerrflag;"
,
139
" goto yyloop;"
,
140
" }"
,
141
" if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&"
,
142
" yyn <= YYTABLESIZE && yycheck[yyn] == yychar)"
,
143
" {"
,
144
" yyn = yytable[yyn];"
,
145
" goto yyreduce;"
,
146
" }"
,
147
" if (yyerrflag) goto yyinrecovery;"
,
148
"#ifdef lint"
,
149
" goto yynewerror;"
,
150
"#endif"
,
151
"yynewerror:"
,
152
" yyerror(\"syntax error\");"
,
153
"#ifdef lint"
,
154
" goto yyerrlab;"
,
155
"#endif"
,
156
"yyerrlab:"
,
157
" ++yynerrs;"
,
158
"yyinrecovery:"
,
159
" if (yyerrflag < 3)"
,
160
" {"
,
161
" yyerrflag = 3;"
,
162
" for (;;)"
,
163
" {"
,
164
" if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&"
,
165
" yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)"
,
166
" {"
,
167
"#if YYDEBUG"
,
168
" if (yydebug)"
,
169
" printf(\"%sdebug: state %d, error recovery shifting\\"
,
170
" to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);"
,
171
"#endif"
,
172
" if (yyssp >= yyss + yystacksize - 1)"
,
173
" {"
,
174
" goto yyoverflow;"
,
175
" }"
,
176
" *++yyssp = yystate = yytable[yyn];"
,
177
" *++yyvsp = yylval;"
,
178
" goto yyloop;"
,
179
" }"
,
180
" else"
,
181
" {"
,
182
"#if YYDEBUG"
,
183
" if (yydebug)"
,
184
" printf(\"%sdebug: error recovery discarding state %d\
185
\\n\","
,
186
" YYPREFIX, *yyssp);"
,
187
"#endif"
,
188
" if (yyssp <= yyss) goto yyabort;"
,
189
" --yyssp;"
,
190
" --yyvsp;"
,
191
" }"
,
192
" }"
,
193
" }"
,
194
" else"
,
195
" {"
,
196
" if (yychar == 0) goto yyabort;"
,
197
"#if YYDEBUG"
,
198
" if (yydebug)"
,
199
" {"
,
200
" yys = 0;"
,
201
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];"
,
202
" if (!yys) yys = \"illegal-symbol\";"
,
203
" printf(\"%sdebug: state %d, error recovery discards token %d\
204
(%s)\\n\","
,
205
" YYPREFIX, yystate, yychar, yys);"
,
206
" }"
,
207
"#endif"
,
208
" yychar = (-1);"
,
209
" goto yyloop;"
,
210
" }"
,
211
"yyreduce:"
,
212
"#if YYDEBUG"
,
213
" if (yydebug)"
,
214
" printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\","
,
215
" YYPREFIX, yystate, yyn, yyrule[yyn]);"
,
216
"#endif"
,
217
" yym = yylen[yyn];"
,
218
" yyval = yyvsp[1-yym];"
,
219
" switch (yyn)"
,
220
" {"
,
221
0
222
};
223
224
225
char
*
trailer
[] =
226
{
227
" }"
,
228
" yyssp -= yym;"
,
229
" yystate = *yyssp;"
,
230
" yyvsp -= yym;"
,
231
" yym = yylhs[yyn];"
,
232
" if (yystate == 0 && yym == 0)"
,
233
" {"
,
234
"#if YYDEBUG"
,
235
" if (yydebug)"
,
236
" printf(\"%sdebug: after reduction, shifting from state 0 to\\"
,
237
" state %d\\n\", YYPREFIX, YYFINAL);"
,
238
"#endif"
,
239
" yystate = YYFINAL;"
,
240
" *++yyssp = YYFINAL;"
,
241
" *++yyvsp = yyval;"
,
242
" if (yychar < 0)"
,
243
" {"
,
244
" if ((yychar = yylex()) < 0) yychar = 0;"
,
245
"#if YYDEBUG"
,
246
" if (yydebug)"
,
247
" {"
,
248
" yys = 0;"
,
249
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];"
,
250
" if (!yys) yys = \"illegal-symbol\";"
,
251
" printf(\"%sdebug: state %d, reading %d (%s)\\n\","
,
252
" YYPREFIX, YYFINAL, yychar, yys);"
,
253
" }"
,
254
"#endif"
,
255
" }"
,
256
" if (yychar == 0) goto yyaccept;"
,
257
" goto yyloop;"
,
258
" }"
,
259
" if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&"
,
260
" yyn <= YYTABLESIZE && yycheck[yyn] == yystate)"
,
261
" yystate = yytable[yyn];"
,
262
" else"
,
263
" yystate = yydgoto[yym];"
,
264
"#if YYDEBUG"
,
265
" if (yydebug)"
,
266
" printf(\"%sdebug: after reduction, shifting from state %d \\"
,
267
"to state %d\\n\", YYPREFIX, *yyssp, yystate);"
,
268
"#endif"
,
269
" if (yyssp >= yyss + yystacksize - 1)"
,
270
" {"
,
271
" goto yyoverflow;"
,
272
" }"
,
273
" *++yyssp = yystate;"
,
274
" *++yyvsp = yyval;"
,
275
" goto yyloop;"
,
276
"yyoverflow:"
,
277
" yyerror(\"yacc stack overflow\");"
,
278
"yyabort:"
,
279
" return (1);"
,
280
"yyaccept:"
,
281
" return (0);"
,
282
"}"
,
283
0
284
};
285
286
287
write_section
(section)
288
char *section[];
289
{
290
register
int
c;
291
register
int
i;
292
register
char
*s;
293
register
FILE *f;
294
295
f =
code_file
;
296
for
(i = 0; s = section[i]; ++i)
297
{
298
++
outline
;
299
while
(c = *s)
300
{
301
putc(c, f);
302
++s;
303
}
304
putc(
'\n'
, f);
305
}
306
}
tables
char * tables[]
Definition:
skeleton.c:30
write_section
write_section(section)
Definition:
skeleton.c:287
body
char * body[]
Definition:
skeleton.c:77
defs.h
banner
char * banner[]
Definition:
skeleton.c:15
trailer
char * trailer[]
Definition:
skeleton.c:225
header
char * header[]
Definition:
skeleton.c:49
code_file
FILE * code_file
Definition:
main.c:29
outline
int outline
Definition:
main.c:16
byacc
skeleton.c
Generated on Thu Mar 16 2017 09:51:27 for Berkeley YACC by
1.8.6