1 /* $NetBSD: grammar.y,v 1.4 1997/10/10 02:07:08 lukem 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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
42 * Copy permission is hereby granted provided that this notice is
43 * retained on all partial or complete copies.
45 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
48 %token <ival> HeightOp
50 %token <ival> UpdateOp
51 %token <ival> NewplaneOp
55 %token <ival> AirportOp
56 %token <ival> BeaconOp
66 #include <sys/cdefs.h>
69 static char sccsid[] = "@(#)grammar.y 8.1 (Berkeley) 5/31/93";
71 __RCSID("$NetBSD: grammar.y,v 1.4 1997/10/10 02:07:08 lukem Exp $");
81 bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines
83 if (sp->num_exits + sp->num_airports < 2)
84 yyerror("Need at least 2 airports and/or exits.");
102 UpdateOp '=' ConstOp ';'
104 if (sp->update_secs != 0)
105 return (yyerror("Redefinition of 'update'."));
107 return (yyerror("'update' is too small."));
109 sp->update_secs = $3;
114 NewplaneOp '=' ConstOp ';'
116 if (sp->newplane_time != 0)
117 return (yyerror("Redefinition of 'newplane'."));
119 return (yyerror("'newplane' is too small."));
121 sp->newplane_time = $3;
126 HeightOp '=' ConstOp ';'
129 return (yyerror("Redefinition of 'height'."));
131 return (yyerror("'height' is too small."));
138 WidthOp '=' ConstOp ';'
141 return (yyerror("Redefinition of 'width'."));
143 return (yyerror("'width' is too small."));
157 BeaconOp ':' Bpoint_list ';'
159 | ExitOp ':' Epoint_list ';'
161 | LineOp ':' Lline_list ';'
163 | AirportOp ':' Apoint_list ';'
175 '(' ConstOp ConstOp ')'
177 if (sp->num_beacons % REALLOC == 0) {
178 if (sp->beacon == NULL)
179 sp->beacon = (BEACON *) malloc((sp->num_beacons
180 + REALLOC) * sizeof (BEACON));
182 sp->beacon = (BEACON *) realloc(sp->beacon,
183 (sp->num_beacons + REALLOC) *
185 if (sp->beacon == NULL)
186 return (yyerror("No memory available."));
188 sp->beacon[sp->num_beacons].x = $2;
189 sp->beacon[sp->num_beacons].y = $3;
203 '(' ConstOp ConstOp DirOp ')'
207 if (sp->num_exits % REALLOC == 0) {
208 if (sp->exit == NULL)
209 sp->exit = (EXIT *) malloc((sp->num_exits +
210 REALLOC) * sizeof (EXIT));
212 sp->exit = (EXIT *) realloc(sp->exit,
213 (sp->num_exits + REALLOC) *
215 if (sp->exit == NULL)
216 return (yyerror("No memory available."));
219 sp->exit[sp->num_exits].x = $2;
220 sp->exit[sp->num_exits].y = $3;
221 sp->exit[sp->num_exits].dir = dir;
223 check_edir($2, $3, dir);
236 '(' ConstOp ConstOp DirOp ')'
240 if (sp->num_airports % REALLOC == 0) {
241 if (sp->airport == NULL)
242 sp->airport=(AIRPORT *)malloc((sp->num_airports
243 + REALLOC) * sizeof(AIRPORT));
245 sp->airport = (AIRPORT *) realloc(sp->airport,
246 (sp->num_airports + REALLOC) *
248 if (sp->airport == NULL)
249 return (yyerror("No memory available."));
252 sp->airport[sp->num_airports].x = $2;
253 sp->airport[sp->num_airports].y = $3;
254 sp->airport[sp->num_airports].dir = dir;
256 check_adir($2, $3, dir);
269 '[' '(' ConstOp ConstOp ')' '(' ConstOp ConstOp ')' ']'
271 if (sp->num_lines % REALLOC == 0) {
272 if (sp->line == NULL)
273 sp->line = (LINE *) malloc((sp->num_lines +
274 REALLOC) * sizeof (LINE));
276 sp->line = (LINE *) realloc(sp->line,
277 (sp->num_lines + REALLOC) *
279 if (sp->line == NULL)
280 return (yyerror("No memory available."));
282 sp->line[sp->num_lines].p1.x = $3;
283 sp->line[sp->num_lines].p1.y = $4;
284 sp->line[sp->num_lines].p2.x = $7;
285 sp->line[sp->num_lines].p2.y = $8;
286 check_line($3, $4, $7, $8);
296 if (!(x == 0) && !(x == sp->width - 1) &&
297 !(y == 0) && !(y == sp->height - 1))
298 yyerror("edge value not on edge.");
305 if (x < 1 || x >= sp->width - 1)
306 yyerror("X value out of range.");
307 if (y < 1 || y >= sp->height - 1)
308 yyerror("Y value out of range.");
312 check_linepoint(x, 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(x1, y1, x2, y2)
327 check_linepoint(x1, y1);
328 check_linepoint(x2, y2);
333 if (!(d1 == d2) && !(d1 == 0) && !(d2 == 0))
334 yyerror("Bad line endpoints.");
341 fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
348 check_edir(x, y, dir)
353 if (x == sp->width - 1)
357 if (y == sp->height - 1)
362 switch (x * 10 + y) {
363 case 00: if (dir != 3) bad++; break;
364 case 01: if (dir < 1 || dir > 3) bad++; break;
365 case 02: if (dir != 1) bad++; break;
366 case 10: if (dir < 3 || dir > 5) bad++; break;
368 case 12: if (dir > 1 && dir < 7) bad++; break;
369 case 20: if (dir != 5) bad++; break;
370 case 21: if (dir < 5) bad++; break;
371 case 22: if (dir != 7) bad++; break;
373 yyerror("Unknown value in checkdir! Get help!");
377 yyerror("Bad direction for entrance at exit.");
381 check_adir(x, y, dir)
391 if (sp->width == 0) {
392 yyerror("'width' undefined.");
395 if (sp->height == 0) {
396 yyerror("'height' undefined.");
399 if (sp->update_secs == 0) {
400 yyerror("'update' undefined.");
403 if (sp->newplane_time == 0) {
404 yyerror("'newplane' undefined.");