Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / sys / netiso / xebec / xebec.bnf
CommitLineData
54f672b5
C
1{
2#include "main.h"
3#include "sets.h"
4#include <stdio.h>
5
6extern FILE *eventfile_h, *actfile;
7}
8
9*fmq
10
11 novocab
12 nobnf
13 nofirst
14 nofollow
15 noparsetable
16 noerrortables
17 nos
18 noe
19
20*terminals
21
22ID 0 0 { char *address; }
23STRUCT 0 0
24SYNONYM 0 0
25PREDICATE 0 0 { char *address; }
26ACTION 0 0 { char *address; }
27/*
28FSTRING 0 0 { char *address; }
29*/
30PROTOCOL 0 0
31LBRACK 0 0
32RBRACK 0 0
33LANGLE 0 0
34EQUAL 0 0
35COMMA 0 0
36STAR 0 0
37EVENTS 0 0
38TRANSITIONS 0 0
39INCLUDE 0 0
40STATES 0 0
41SEMI 0 0
42PCB 0 0 { char *address; }
43DEFAULT 0 0
44NULLACTION 0 0
45SAME 0 0
46
47*nonterminals
48
49pcb { char *address; int isevent; }
50syn { int type; }
51setlist { struct Object *setnum; }
52setlisttail { struct Object *setnum; }
53part { unsigned char type; }
54parttail { unsigned char type; }
55partrest { unsigned char type; char *address; }
56setstruct { struct Object *object; }
57setdef { unsigned char type,keep; char *address; struct Object *object; }
58translist
59transition
60event { struct Object *object; }
61oldstate { struct Object *object; }
62newstate { struct Object *object; }
63predicatepart { char *string; }
64actionpart { char *string; struct Object *oldstate; struct Object *newstate; }
65
66*productions
67
68program ::=
69 STAR PROTOCOL ID
70 {
71 if(strlen($ID.address) > 50 ) {
72 fprintf(stderr,
73 "Protocol name may not exceed 50 chars in length.\n");
74 Exit(-1);
75 }
76 strcpy(protocol, $ID.address);
77 openfiles(protocol);
78 }
79 STAR includelist
80 PCB
81 {
82 $$pcb.isevent = 0;
83 }
84 pcb
85 {
86 fprintf(actfile, "\ntypedef %s %s%s;\n",
87 $pcb[7].address,protocol, PCBNAME);
88 $$syn.type = PCB_SYN;
89 }
90 syn
91 STAR STATES { $$part.type = (unsigned char) STATESET; } part
92 STAR { end_states(eventfile_h); } EVENTS
93 { $$pcb.isevent = 1; }
94 pcb
95 {
96 fprintf(eventfile_h, "\t"); /* fmq gags on single chars */
97 includecode(eventfile_h, $pcb[14].address);
98 fprintf(eventfile_h, "\n"); /* fmq gags on single chars */
99 $$syn.type = EVENT_SYN;
100 }
101 syn
102 {
103 $$part.type = (unsigned char)EVENTSET;
104 }
105 part
106 STAR { end_events(); }
107 TRANSITIONS
108 {
109 putincludes();
110 putdriver(actfile, 9);
111 }
112 translist
113;
114pcb ::= STRUCT
115 { if($pcb.isevent) {
116 fprintf(stderr,
117 "Event is a list of objects enclosed by \"{}\"\n");
118 Exit(-1);
119 }
120 fprintf(eventfile_h, "struct ");
121 }
122 ACTION { $pcb.address = $ACTION.address; }
123 optsemi
124 ::= ACTION
125 { if( ! $pcb.isevent) {
126 fprintf(stderr,
127 "Pcb requires a type or structure definition.\"{}\"\n");
128 Exit(-1);
129 }
130 $pcb.address = $ACTION.address;
131 }
132 optsemi
133 ::= ID { $pcb.address = $ID.address; } optsemi
134;
135
136syn ::= SYNONYM ID { synonyms[$syn.type] = stash( $ID.address ); }
137 ::=
138;
139
140optsemi ::= SEMI
141 ::=
142;
143includelist ::= INCLUDE ACTION { includecode(actfile, $ACTION.address);} STAR
144 ::=
145;
146part ::= ID
147 {
148 $$partrest.address = $ID.address;
149 $$partrest.type = $part.type;
150 }
151 partrest
152 { $$parttail.type = $part.type; }
153 parttail
154;
155parttail ::= { $$part.type = $parttail.type; } part
156 ::=
157;
158partrest ::= EQUAL
159 {
160 if( lookup( $partrest.type, $partrest.address ) ) {
161 fprintf(stderr, "bnf:trying to redefine obj type 0x%x, adr %s\n",
162 $partrest.type, $partrest.address);
163 Exit(-1);
164 }
165 $$setdef.type = $partrest.type;
166 $$setdef.address = stash( $partrest.address );
167 $$setdef.keep = 1;
168 } setdef { $$setstruct.object = $setdef.object; } setstruct
169
170 ::= ACTION
171 {
172 defineitem($partrest.type,
173 $partrest.address, $ACTION.address);
174 }
175
176 ::= {
177 defineitem($partrest.type, $partrest.address, (char *)0);
178 }
179;
180
181setstruct ::= ACTION
182 {
183 if($setstruct.object) {
184 /* WHEN COULD THIS BE FALSE??
185 * isn't it supposed to be setstruct.object???
186 * (it used to be $ACTION.address)
187 */
188
189 $setstruct.object->obj_struc = $ACTION.address;
190 fprintf(eventfile_h,
191 "struct %s %s%s;\n\n", $ACTION.address,
192 EV_PREFIX, $setstruct.object->obj_name);
193 }
194 }
195 ::=
196;
197
198setdef ::= LBRACK
199 {
200 $$setlist.setnum =
201 defineset($setdef.type, $setdef.address, $setdef.keep);
202 } setlist RBRACK { $setdef.object = $setlist.setnum; }
203;
204
205setlist ::= ID
206 {
207 member($setlist.setnum, $ID.address);
208 $$setlisttail.setnum = $setlist.setnum;
209 } setlisttail
210;
211
212setlisttail ::= COMMA { $$setlist.setnum = $setlisttail.setnum; } setlist
213 ::=
214;
215translist ::= transition translisttail
216;
217translisttail ::= translist
218 ::=
219;
220transition ::= newstate { transno ++; } LANGLE EQUAL EQUAL oldstate
221 event
222 {
223 CurrentEvent /* GAG! */ = $event.object;
224 }
225 predicatepart
226 {
227 $$actionpart.string = $predicatepart.string;
228 $$actionpart.newstate = $newstate.object;
229 $$actionpart.oldstate = $oldstate.object;
230 }
231 actionpart
232 SEMI
233;
234
235predicatepart ::= PREDICATE
236 {
237 $predicatepart.string = stash ( $PREDICATE.address );
238 }
239 ::= DEFAULT
240 {
241 $predicatepart.string = (char *)0;
242 }
243;
244
245actionpart ::=
246 ACTION
247 {
248 statetable( $actionpart.string, $actionpart.oldstate,
249 $actionpart.newstate,
250 acttable(actfile, $ACTION.address ),
251 CurrentEvent );
252 if( print_trans ) {
253 dump_trans( $actionpart.string, $actionpart.oldstate,
254 $actionpart.newstate,
255 $ACTION.address, CurrentEvent );
256 }
257 }
258 ::= NULLACTION
259 {
260 statetable($actionpart.string, $actionpart.oldstate, $actionpart.newstate,
261 0, CurrentEvent ); /* KLUDGE - remove this */
262 if( print_trans ) {
263 dump_trans( $actionpart.string, $actionpart.oldstate,
264 $actionpart.newstate,
265 "NULLACTION", CurrentEvent );
266 }
267 }
268;
269
270oldstate ::= ID
271 {
272 $oldstate.object = Lookup(STATESET, $ID.address);
273 }
274 ::= {
275 $$setdef.address = (char *)0;
276 $$setdef.type = (unsigned char)STATESET;
277 $$setdef.keep = 0;
278 }
279 setdef
280 {
281 $oldstate.object = $setdef.object;
282 }
283;
284
285newstate ::= ID
286 {
287 $newstate.object = Lookup(STATESET, $ID.address);
288 }
289;
290
291newstate ::= SAME
292 {
293 extern struct Object *SameState;
294
295 $newstate.object = SameState;
296 }
297;
298
299event ::= ID
300 {
301 $event.object = Lookup(EVENTSET, $ID.address);
302 }
303 ::=
304 {
305 $$setdef.address = (char *)0;
306 $$setdef.type = (unsigned char)EVENTSET;
307 $$setdef.keep = 0;
308 }
309 setdef
310 {
311 $event.object = $setdef.object;
312 }
313;
314
315*end