xref: /original-bsd/old/htable/parse.y (revision d0e3910b)
1 %{
2 /*
3  * Copyright (c) 1983 Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that this notice is preserved and that due credit is given
8  * to the University of California at Berkeley. The name of the University
9  * may not be used to endorse or promote products derived from this
10  * software without specific prior written permission. This software
11  * is provided ``as is'' without express or implied warranty.
12  */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)parse.y	5.3 (Berkeley) 02/23/88";
16 #endif /* not lint */
17 
18 #include "htable.h"
19 %}
20 
21 %union {
22 	int	number;
23 	struct	addr *addrlist;
24 	struct	name *namelist;
25 }
26 %start Table
27 
28 %token			END
29 %token <number>		NUMBER KEYWORD
30 %token <namelist>	NAME
31 
32 %type <namelist>	Names Cputype Opsys Protos Proto
33 %type <addrlist>	Addresses Address
34 %%
35 Table	:	Entry
36 	|	Table Entry
37 	;
38 
39 Entry	:	KEYWORD ':' Addresses ':' Names ':' END
40 	= {
41 		do_entry($1, $3, $5, NONAME, NONAME, NONAME);
42 	}
43 	|	KEYWORD ':' Addresses ':' Names ':' Cputype ':' END
44 	= {
45 		do_entry($1, $3, $5, $7, NONAME, NONAME);
46 	}
47 	|	KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' END
48 	= {
49 		do_entry($1, $3, $5, $7, $9, NONAME);
50 	}
51 	|	KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' ':' END
52 	= {
53 		do_entry($1, $3, $5, $7, $9, NONAME);
54 	}
55 	|	KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' Protos ':' END
56 	= {
57 		do_entry($1, $3, $5, $7, $9, $11);
58 	}
59 	|	error END
60 	|	END		/* blank line */
61 	;
62 
63 Addresses:	Address
64 	= {
65 		$$ = $1;
66 	}
67 	|	Address ',' Addresses
68 	= {
69 		$1->addr_link = $3;
70 		$$ = $1;
71 	}
72 	;
73 
74 Address	:	NUMBER '.' NUMBER '.' NUMBER '.' NUMBER
75 	= {
76 		char *a;
77 
78 		$$ = (struct addr *)malloc(sizeof (struct addr));
79 		a = (char *)&($$->addr_val);
80 		a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
81 		$$->addr_link = NOADDR;
82 	}
83 	;
84 
85 Names	:	NAME
86 	= {
87 		$$ = $1;
88 	}
89 	|	NAME ',' Names
90 	= {
91 		$1->name_link = $3;
92 		$$ = $1;
93 	}
94 	;
95 
96 Cputype :	/* empty */
97 	= {
98 		$$ = NONAME;
99 	}
100 	|	NAME
101 	= {
102 		$$ = $1;
103 	}
104 	;
105 
106 Opsys	:	/* empty */
107 	= {
108 		$$ = NONAME;
109 	}
110 	|	NAME
111 	= {
112 		$$ = $1;
113 	}
114 	;
115 
116 Protos	:	Proto
117 	= {
118 		$$ = $1;
119 	}
120 	|	Proto ',' Protos
121 	= {
122 		$1->name_link = $3;
123 		$$ = $1;
124 	}
125 	;
126 
127 Proto	:	NAME
128 	= {
129 		$$ = $1;
130 	}
131 	;
132 %%
133 
134 #include <stdio.h>
135 
136 extern int yylineno;
137 
138 yyerror(msg)
139 	char *msg;
140 {
141 	fprintf(stderr, "\"%s\", line %d: %s\n", infile, yylineno, msg);
142 }
143