1/* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Robert Paul Corbett. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 4. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if 0 34#ifndef lint 35static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95"; 36#endif 37#endif 38 39#include <sys/cdefs.h> 40__FBSDID("$FreeBSD$"); 41 42#include "defs.h" 43 44/* The definition of yysccsid in the banner should be replaced with */ 45/* a #pragma ident directive if the target C compiler supports */ 46/* #pragma ident directives. */ 47/* */ 48/* If the skeleton is changed, the banner should be changed so that */ 49/* the altered version can be easily distinguished from the original. */ 50/* */ 51/* The #defines included with the banner are there because they are */ 52/* useful in subsequent code. The macros #defined in the header or */ 53/* the body either are not useful outside of semantic actions or */ 54/* are conditional. */ 55 56const char *banner[] = 57{ 58 "#include <stdlib.h>", 59 "#include <string.h>", 60 "#ifndef lint", 61 "#ifdef __unused", 62 "__unused", 63 "#endif", 64 "static char const ", 65 "yyrcsid[] = \"$FreeBSD$\";", 66 "#endif", 67 "#define YYBYACC 1", 68 "#define YYMAJOR 1", 69 "#define YYMINOR 9", 70 "#define YYLEX yylex()", 71 "#define YYEMPTY -1", 72 "#define yyclearin (yychar=(YYEMPTY))", 73 "#define yyerrok (yyerrflag=0)", 74 "#define YYRECOVERING() (yyerrflag!=0)", 75 "#if defined(__cplusplus) || __STDC__", 76 "static int yygrowstack(void);", 77 "#else", 78 "static int yygrowstack();", 79 "#endif", 80 0 81}; 82 83 84const char *tables[] = 85{ 86 "extern const short yylhs[];", 87 "extern const short yylen[];", 88 "extern const short yydefred[];", 89 "extern const short yydgoto[];", 90 "extern const short yysindex[];", 91 "extern const short yyrindex[];", 92 "extern const short yygindex[];", 93 "extern const short yytable[];", 94 "extern const short yycheck[];", 95 "#if YYDEBUG", 96 "extern char *yyname[];", 97 "extern char *yyrule[];", 98 "#endif", 99 0 100}; 101 102 103const char *header[] = 104{ 105 "#if YYDEBUG", 106 "#include <stdio.h>", 107 "#endif", 108 "#ifdef YYSTACKSIZE", 109 "#undef YYMAXDEPTH", 110 "#define YYMAXDEPTH YYSTACKSIZE", 111 "#else", 112 "#ifdef YYMAXDEPTH", 113 "#define YYSTACKSIZE YYMAXDEPTH", 114 "#else", 115 "#define YYSTACKSIZE 10000", 116 "#define YYMAXDEPTH 10000", 117 "#endif", 118 "#endif", 119 "#define YYINITSTACKSIZE 200", 120 "int yydebug;", 121 "int yynerrs;", 122 "int yyerrflag;", 123 "int yychar;", 124 "short *yyssp;", 125 "YYSTYPE *yyvsp;", 126 "YYSTYPE yyval;", 127 "YYSTYPE yylval;", 128 "short *yyss;", 129 "short *yysslim;", 130 "YYSTYPE *yyvs;", 131 "int yystacksize;", 132 0 133}; 134 135 136const char *body[] = 137{ 138 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */", 139 "#if defined(__cplusplus) || __STDC__", 140 "static int yygrowstack(void)", 141 "#else", 142 "static int yygrowstack()", 143 "#endif", 144 "{", 145 " int newsize, i;", 146 " short *newss;", 147 " YYSTYPE *newvs;", 148 "", 149 " if ((newsize = yystacksize) == 0)", 150 " newsize = YYINITSTACKSIZE;", 151 " else if (newsize >= YYMAXDEPTH)", 152 " return -1;", 153 " else if ((newsize *= 2) > YYMAXDEPTH)", 154 " newsize = YYMAXDEPTH;", 155 " i = yyssp - yyss;", 156 " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :", 157 " (short *)malloc(newsize * sizeof *newss);", 158 " if (newss == NULL)", 159 " return -1;", 160 " yyss = newss;", 161 " yyssp = newss + i;", 162 " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :", 163 " (YYSTYPE *)malloc(newsize * sizeof *newvs);", 164 " if (newvs == NULL)", 165 " return -1;", 166 " yyvs = newvs;", 167 " yyvsp = newvs + i;", 168 " yystacksize = newsize;", 169 " yysslim = yyss + newsize - 1;", 170 " return 0;", 171 "}", 172 "", 173 "#define YYABORT goto yyabort", 174 "#define YYREJECT goto yyabort", 175 "#define YYACCEPT goto yyaccept", 176 "#define YYERROR goto yyerrlab", 177 "", 178 "#ifndef YYPARSE_PARAM", 179 "#if defined(__cplusplus) || __STDC__", 180 "#define YYPARSE_PARAM_ARG void", 181 "#define YYPARSE_PARAM_DECL", 182 "#else /* ! ANSI-C/C++ */", 183 "#define YYPARSE_PARAM_ARG", 184 "#define YYPARSE_PARAM_DECL", 185 "#endif /* ANSI-C/C++ */", 186 "#else /* YYPARSE_PARAM */", 187 "#ifndef YYPARSE_PARAM_TYPE", 188 "#define YYPARSE_PARAM_TYPE void *", 189 "#endif", 190 "#if defined(__cplusplus) || __STDC__", 191 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM", 192 "#define YYPARSE_PARAM_DECL", 193 "#else /* ! ANSI-C/C++ */", 194 "#define YYPARSE_PARAM_ARG YYPARSE_PARAM", 195 "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;", 196 "#endif /* ANSI-C/C++ */", 197 "#endif /* ! YYPARSE_PARAM */", 198 "", 199 "int", 200 "yyparse (YYPARSE_PARAM_ARG)", 201 " YYPARSE_PARAM_DECL", 202 "{", 203 " int yym, yyn, yystate;", 204 "#if YYDEBUG", 205 " const char *yys;", 206 "", 207 " if ((yys = getenv(\"YYDEBUG\")))", 208 " {", 209 " yyn = *yys;", 210 " if (yyn >= '0' && yyn <= '9')", 211 " yydebug = yyn - '0';", 212 " }", 213 "#endif", 214 "", 215 " yynerrs = 0;", 216 " yyerrflag = 0;", 217 " yychar = (-1);", 218 "", 219 " if (yyss == NULL && yygrowstack()) goto yyoverflow;", 220 " yyssp = yyss;", 221 " yyvsp = yyvs;", 222 " *yyssp = yystate = 0;", 223 "", 224 "yyloop:", 225 " if ((yyn = yydefred[yystate])) goto yyreduce;", 226 " if (yychar < 0)", 227 " {", 228 " if ((yychar = yylex()) < 0) yychar = 0;", 229 "#if YYDEBUG", 230 " if (yydebug)", 231 " {", 232 " yys = 0;", 233 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 234 " if (!yys) yys = \"illegal-symbol\";", 235 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",", 236 " YYPREFIX, yystate, yychar, yys);", 237 " }", 238 "#endif", 239 " }", 240 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&", 241 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", 242 " {", 243 "#if YYDEBUG", 244 " if (yydebug)", 245 " printf(\"%sdebug: state %d, shifting to state %d\\n\",", 246 " YYPREFIX, yystate, yytable[yyn]);", 247 "#endif", 248 " if (yyssp >= yysslim && yygrowstack())", 249 " {", 250 " goto yyoverflow;", 251 " }", 252 " *++yyssp = yystate = yytable[yyn];", 253 " *++yyvsp = yylval;", 254 " yychar = (-1);", 255 " if (yyerrflag > 0) --yyerrflag;", 256 " goto yyloop;", 257 " }", 258 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&", 259 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", 260 " {", 261 " yyn = yytable[yyn];", 262 " goto yyreduce;", 263 " }", 264 " if (yyerrflag) goto yyinrecovery;", 265 "#if defined(lint) || defined(__GNUC__)", 266 " goto yynewerror;", 267 "#endif", 268 "yynewerror:", 269 " yyerror(\"syntax error\");", 270 "#if defined(lint) || defined(__GNUC__)", 271 " goto yyerrlab;", 272 "#endif", 273 "yyerrlab:", 274 " ++yynerrs;", 275 "yyinrecovery:", 276 " if (yyerrflag < 3)", 277 " {", 278 " yyerrflag = 3;", 279 " for (;;)", 280 " {", 281 " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&", 282 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)", 283 " {", 284 "#if YYDEBUG", 285 " if (yydebug)", 286 " printf(\"%sdebug: state %d, error recovery shifting\\", 287 " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);", 288 "#endif", 289 " if (yyssp >= yysslim && yygrowstack())", 290 " {", 291 " goto yyoverflow;", 292 " }", 293 " *++yyssp = yystate = yytable[yyn];", 294 " *++yyvsp = yylval;", 295 " goto yyloop;", 296 " }", 297 " else", 298 " {", 299 "#if YYDEBUG", 300 " if (yydebug)", 301 " printf(\"%sdebug: error recovery discarding state %d\ 302\\n\",", 303 " YYPREFIX, *yyssp);", 304 "#endif", 305 " if (yyssp <= yyss) goto yyabort;", 306 " --yyssp;", 307 " --yyvsp;", 308 " }", 309 " }", 310 " }", 311 " else", 312 " {", 313 " if (yychar == 0) goto yyabort;", 314 "#if YYDEBUG", 315 " if (yydebug)", 316 " {", 317 " yys = 0;", 318 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 319 " if (!yys) yys = \"illegal-symbol\";", 320 " printf(\"%sdebug: state %d, error recovery discards token %d\ 321 (%s)\\n\",", 322 " YYPREFIX, yystate, yychar, yys);", 323 " }", 324 "#endif", 325 " yychar = (-1);", 326 " goto yyloop;", 327 " }", 328 "yyreduce:", 329 "#if YYDEBUG", 330 " if (yydebug)", 331 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",", 332 " YYPREFIX, yystate, yyn, yyrule[yyn]);", 333 "#endif", 334 " yym = yylen[yyn];", 335 " if (yym)", 336 " yyval = yyvsp[1-yym];", 337 " else", 338 " memset(&yyval, 0, sizeof yyval);", 339 " switch (yyn)", 340 " {", 341 0 342}; 343 344 345const char *trailer[] = 346{ 347 " }", 348 " yyssp -= yym;", 349 " yystate = *yyssp;", 350 " yyvsp -= yym;", 351 " yym = yylhs[yyn];", 352 " if (yystate == 0 && yym == 0)", 353 " {", 354 "#if YYDEBUG", 355 " if (yydebug)", 356 " printf(\"%sdebug: after reduction, shifting from state 0 to\\", 357 " state %d\\n\", YYPREFIX, YYFINAL);", 358 "#endif", 359 " yystate = YYFINAL;", 360 " *++yyssp = YYFINAL;", 361 " *++yyvsp = yyval;", 362 " if (yychar < 0)", 363 " {", 364 " if ((yychar = yylex()) < 0) yychar = 0;", 365 "#if YYDEBUG", 366 " if (yydebug)", 367 " {", 368 " yys = 0;", 369 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", 370 " if (!yys) yys = \"illegal-symbol\";", 371 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",", 372 " YYPREFIX, YYFINAL, yychar, yys);", 373 " }", 374 "#endif", 375 " }", 376 " if (yychar == 0) goto yyaccept;", 377 " goto yyloop;", 378 " }", 379 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&", 380 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)", 381 " yystate = yytable[yyn];", 382 " else", 383 " yystate = yydgoto[yym];", 384 "#if YYDEBUG", 385 " if (yydebug)", 386 " printf(\"%sdebug: after reduction, shifting from state %d \\", 387 "to state %d\\n\", YYPREFIX, *yyssp, yystate);", 388 "#endif", 389 " if (yyssp >= yysslim && yygrowstack())", 390 " {", 391 " goto yyoverflow;", 392 " }", 393 " *++yyssp = yystate;", 394 " *++yyvsp = yyval;", 395 " goto yyloop;", 396 "yyoverflow:", 397 " yyerror(\"yacc stack overflow\");", 398 "yyabort:", 399 " return (1);", 400 "yyaccept:", 401 " return (0);", 402 "}", 403 0 404}; 405 406 407void 408write_section(const char *section[]) 409{ 410 int c; 411 int i; 412 const char *s; 413 FILE *f; 414 415 f = code_file; 416 for (i = 0; (s = section[i]); ++i) 417 { 418 ++outline; 419 while ((c = *s)) 420 { 421 putc(c, f); 422 ++s; 423 } 424 putc('\n', f); 425 } 426} 427