1 /* $NetBSD: grammar.y,v 1.7 1999/07/26 21:14:21 hubertf 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.7 1999/07/26 21:14:21 hubertf 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;
268 '[' '(' ConstOp ConstOp ')' '(' ConstOp ConstOp ')' ']'
270 if (sp->num_lines % REALLOC == 0) {
271 if (sp->line == NULL)
272 sp->line = (LINE *) malloc((sp->num_lines +
273 REALLOC) * sizeof (LINE));
275 sp->line = (LINE *) realloc(sp->line,
276 (sp->num_lines + REALLOC) *
278 if (sp->line == NULL)
279 return (yyerror("No memory available."));
281 sp->line[sp->num_lines].p1.x = $3;
282 sp->line[sp->num_lines].p1.y = $4;
283 sp->line[sp->num_lines].p2.x = $7;
284 sp->line[sp->num_lines].p2.y = $8;
285 check_line($3, $4, $7, $8);
295 if (!(x == 0) && !(x == sp->width - 1) &&
296 !(y == 0) && !(y == sp->height - 1))
297 yyerror("edge value not on edge.");
304 if (x < 1 || x >= sp->width - 1)
305 yyerror("X value out of range.");
306 if (y < 1 || y >= sp->height - 1)
307 yyerror("Y value out of range.");
311 check_linepoint(x, y)
314 if (x < 0 || x >= sp->width)
315 yyerror("X value out of range.");
316 if (y < 0 || y >= sp->height)
317 yyerror("Y value out of range.");
321 check_line(x1, y1, x2, y2)
326 check_linepoint(x1, y1);
327 check_linepoint(x2, y2);
332 if (!(d1 == d2) && !(d1 == 0) && !(d2 == 0))
333 yyerror("Bad line endpoints.");
340 fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
347 check_edir(x, y, dir)
352 if (x == sp->width - 1)
356 if (y == sp->height - 1)
361 switch (x * 10 + y) {
362 case 00: if (dir != 3) bad++; break;
363 case 01: if (dir < 1 || dir > 3) bad++; break;
364 case 02: if (dir != 1) bad++; break;
365 case 10: if (dir < 3 || dir > 5) bad++; break;
367 case 12: if (dir > 1 && dir < 7) bad++; break;
368 case 20: if (dir != 5) bad++; break;
369 case 21: if (dir < 5) bad++; break;
370 case 22: if (dir != 7) bad++; break;
372 yyerror("Unknown value in checkdir! Get help!");
376 yyerror("Bad direction for entrance at exit.");
384 if (sp->width == 0) {
385 yyerror("'width' undefined.");
388 if (sp->height == 0) {
389 yyerror("'height' undefined.");
392 if (sp->update_secs == 0) {
393 yyerror("'update' undefined.");
396 if (sp->newplane_time == 0) {
397 yyerror("'newplane' undefined.");