1 /* $NetBSD: grammar.y,v 1.12 2015/06/19 06:02:31 dholland Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
38 * Copy permission is hereby granted provided that this notice is
39 * retained on all partial or complete copies.
41 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
44 %token <ival> HeightOp
46 %token <ival> UpdateOp
47 %token <ival> NewplaneOp
51 %token <ival> AirportOp
52 %token <ival> BeaconOp
60 #include <sys/cdefs.h>
63 static char sccsid[] = "@(#)grammar.y 8.1 (Berkeley) 5/31/93";
65 __RCSID("$NetBSD: grammar.y,v 1.12 2015/06/19 06:02:31 dholland Exp $");
78 static int errors = 0;
80 static int yyerror(const char *);
85 bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines
87 if (sp->num_exits + sp->num_airports < 2)
88 yyerror("Need at least 2 airports and/or exits.");
106 UpdateOp '=' ConstOp ';'
108 if (sp->update_secs != 0)
109 return (yyerror("Redefinition of 'update'."));
111 return (yyerror("'update' is too small."));
113 sp->update_secs = $3;
118 NewplaneOp '=' ConstOp ';'
120 if (sp->newplane_time != 0)
121 return (yyerror("Redefinition of 'newplane'."));
123 return (yyerror("'newplane' is too small."));
125 sp->newplane_time = $3;
130 HeightOp '=' ConstOp ';'
133 return (yyerror("Redefinition of 'height'."));
135 return (yyerror("'height' is too small."));
142 WidthOp '=' ConstOp ';'
145 return (yyerror("Redefinition of 'width'."));
147 return (yyerror("'width' is too small."));
161 BeaconOp ':' Bpoint_list ';'
163 | ExitOp ':' Epoint_list ';'
165 | LineOp ':' Lline_list ';'
167 | AirportOp ':' Apoint_list ';'
179 '(' ConstOp ConstOp ')'
181 if (sp->num_beacons % REALLOC == 0) {
182 if (sp->beacon == NULL)
183 sp->beacon = malloc((sp->num_beacons
184 + REALLOC) * sizeof (BEACON));
186 sp->beacon = realloc(sp->beacon,
187 (sp->num_beacons + REALLOC) *
189 if (sp->beacon == NULL)
190 return (yyerror("No memory available."));
192 sp->beacon[sp->num_beacons].x = $2;
193 sp->beacon[sp->num_beacons].y = $3;
207 '(' ConstOp ConstOp DirOp ')'
211 if (sp->num_exits % REALLOC == 0) {
212 if (sp->exit == NULL)
213 sp->exit = malloc((sp->num_exits +
214 REALLOC) * sizeof (EXIT));
216 sp->exit = realloc(sp->exit,
217 (sp->num_exits + REALLOC) *
219 if (sp->exit == NULL)
220 return (yyerror("No memory available."));
223 sp->exit[sp->num_exits].x = $2;
224 sp->exit[sp->num_exits].y = $3;
225 sp->exit[sp->num_exits].dir = dir;
227 check_edir($2, $3, dir);
240 '(' ConstOp ConstOp DirOp ')'
244 if (sp->num_airports % REALLOC == 0) {
245 if (sp->airport == NULL)
246 sp->airport = malloc((sp->num_airports
247 + REALLOC) * sizeof(AIRPORT));
249 sp->airport = realloc(sp->airport,
250 (sp->num_airports + REALLOC) *
252 if (sp->airport == NULL)
253 return (yyerror("No memory available."));
256 sp->airport[sp->num_airports].x = $2;
257 sp->airport[sp->num_airports].y = $3;
258 sp->airport[sp->num_airports].dir = dir;
272 '[' '(' ConstOp ConstOp ')' '(' ConstOp ConstOp ')' ']'
274 if (sp->num_lines % REALLOC == 0) {
275 if (sp->line == NULL)
276 sp->line = malloc((sp->num_lines +
277 REALLOC) * sizeof (LINE));
279 sp->line = realloc(sp->line,
280 (sp->num_lines + REALLOC) *
282 if (sp->line == NULL)
283 return (yyerror("No memory available."));
285 sp->line[sp->num_lines].p1.x = $3;
286 sp->line[sp->num_lines].p1.y = $4;
287 sp->line[sp->num_lines].p2.x = $7;
288 sp->line[sp->num_lines].p2.y = $8;
289 check_line($3, $4, $7, $8);
296 check_edge(int x, int y)
298 if (!(x == 0) && !(x == sp->width - 1) &&
299 !(y == 0) && !(y == sp->height - 1))
300 yyerror("edge value not on edge.");
304 check_point(int x, int y)
306 if (x < 1 || x >= sp->width - 1)
307 yyerror("X value out of range.");
308 if (y < 1 || y >= sp->height - 1)
309 yyerror("Y value out of range.");
313 check_linepoint(int x, int y)
315 if (x < 0 || x >= sp->width)
316 yyerror("X value out of range.");
317 if (y < 0 || y >= sp->height)
318 yyerror("Y value out of range.");
322 check_line(int px1, int py1, int px2, int py2)
326 check_linepoint(px1, py1);
327 check_linepoint(px2, py2);
332 if (!(d1 == d2) && !(d1 == 0) && !(d2 == 0))
333 yyerror("Bad line endpoints.");
337 yyerror(const char *s)
339 fprintf(stderr, "\"%s\": line %d: %s\n", filename, line, s);
346 check_edir(int x, int y, int dir)
350 if (x == sp->width - 1)
354 if (y == sp->height - 1)
359 switch (x * 10 + y) {
360 case 00: if (dir != 3) bad++; break;
361 case 01: if (dir < 1 || dir > 3) bad++; break;
362 case 02: if (dir != 1) bad++; break;
363 case 10: if (dir < 3 || dir > 5) bad++; break;
365 case 12: if (dir > 1 && dir < 7) bad++; break;
366 case 20: if (dir != 5) bad++; break;
367 case 21: if (dir < 5) bad++; break;
368 case 22: if (dir != 7) bad++; break;
370 yyerror("Unknown value in checkdir! Get help!");
374 yyerror("Bad direction for entrance at exit.");
382 if (sp->width == 0) {
383 yyerror("'width' undefined.");
386 if (sp->height == 0) {
387 yyerror("'height' undefined.");
390 if (sp->update_secs == 0) {
391 yyerror("'update' undefined.");
394 if (sp->newplane_time == 0) {
395 yyerror("'newplane' undefined.");