Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / netiso / xebec / xebec.bnf
blobec8304145e4c809d2d1e1f717ae45a652def866a
1 /* $NetBSD: xebec.bnf,v 1.5.22.1 2005/02/15 21:33:40 skrll Exp $ */
3 #include "main.h"
4 #include "sets.h"
5 #include "procs.h"
6 #include <stdio.h>
8 extern FILE *eventfile_h, *actfile;
11 *fmq
13 novocab
14 nobnf
15 nofirst
16 nofollow
17 noparsetable
18 noerrortables
19 nos
20 noe
22 *terminals
24 ID 0 0 { char *address; }
25 STRUCT 0 0
26 SYNONYM 0 0
27 PREDICATE 0 0 { char *address; }
28 ACTION 0 0 { char *address; }
30 FSTRING 0 0 { char *address; }
32 PROTOCOL 0 0
33 LBRACK 0 0
34 RBRACK 0 0
35 LANGLE 0 0
36 EQUAL 0 0
37 COMMA 0 0
38 STAR 0 0
39 EVENTS 0 0
40 TRANSITIONS 0 0
41 INCLUDE 0 0
42 STATES 0 0
43 SEMI 0 0
44 PCB 0 0 { char *address; }
45 DEFAULT 0 0
46 NULLACTION 0 0
47 SAME 0 0
49 *nonterminals
51 pcb { char *address; int isevent; }
52 syn { int type; }
53 setlist { struct Object *setnum; }
54 setlisttail { struct Object *setnum; }
55 part { unsigned char type; }
56 parttail { unsigned char type; }
57 partrest { unsigned char type; char *address; }
58 setstruct { struct Object *object; }
59 setdef { unsigned char type,keep; char *address; struct Object *object; }
60 translist
61 transition
62 event { struct Object *object; }
63 oldstate { struct Object *object; }
64 newstate { struct Object *object; }
65 predicatepart { char *string; }
66 actionpart { char *string; struct Object *oldstate; struct Object *newstate; }
68 *productions
70 program ::=
71 STAR PROTOCOL ID
73 if(strlen($ID.address) > 50 ) {
74 fprintf(stderr,
75 "Protocol name may not exceed 50 chars in length.\n");
76 Exit(-1);
78 strcpy(protocol, $ID.address);
79 openfiles(protocol);
81 STAR includelist
82 PCB
84 $$pcb.isevent = 0;
86 pcb
88 fprintf(actfile, "\ntypedef %s %s%s;\n",
89 $pcb[7].address,protocol, PCBNAME);
90 $$syn.type = PCB_SYN;
92 syn
93 STAR STATES { $$part.type = (unsigned char) STATESET; } part
94 STAR { end_states(eventfile_h); } EVENTS
95 { $$pcb.isevent = 1; }
96 pcb
98 fprintf(eventfile_h, "\t"); /* fmq gags on single chars */
99 includecode(eventfile_h, $pcb[14].address);
100 fprintf(eventfile_h, "\n"); /* fmq gags on single chars */
101 $$syn.type = EVENT_SYN;
103 syn
105 $$part.type = (unsigned char)EVENTSET;
107 part
108 STAR { end_events(); }
109 TRANSITIONS
111 putincludes();
112 putdriver(actfile, 9);
114 translist
116 pcb ::= STRUCT
117 { if($pcb.isevent) {
118 fprintf(stderr,
119 "Event is a list of objects enclosed by \"{}\"\n");
120 Exit(-1);
122 fprintf(eventfile_h, "struct ");
124 ACTION { $pcb.address = $ACTION.address; }
125 optsemi
126 ::= ACTION
127 { if( ! $pcb.isevent) {
128 fprintf(stderr,
129 "Pcb requires a type or structure definition.\"{}\"\n");
130 Exit(-1);
132 $pcb.address = $ACTION.address;
134 optsemi
135 ::= ID { $pcb.address = $ID.address; } optsemi
138 syn ::= SYNONYM ID { synonyms[$syn.type] = stash( $ID.address ); }
139 ::=
142 optsemi ::= SEMI
143 ::=
145 includelist ::= INCLUDE ACTION { includecode(actfile, $ACTION.address);} STAR
148 part ::= ID
150 $$partrest.address = $ID.address;
151 $$partrest.type = $part.type;
153 partrest
154 { $$parttail.type = $part.type; }
155 parttail
157 parttail ::= { $$part.type = $parttail.type; } part
158 ::=
160 partrest ::= EQUAL
162 if( lookup( $partrest.type, $partrest.address ) ) {
163 fprintf(stderr, "bnf:trying to redefine obj type 0x%x, adr %s\n",
164 $partrest.type, $partrest.address);
165 Exit(-1);
167 $$setdef.type = $partrest.type;
168 $$setdef.address = stash( $partrest.address );
169 $$setdef.keep = 1;
170 } setdef { $$setstruct.object = $setdef.object; } setstruct
172 ::= ACTION
174 defineitem($partrest.type,
175 $partrest.address, $ACTION.address);
178 ::= {
179 defineitem($partrest.type, $partrest.address, (char *)0);
183 setstruct ::= ACTION
185 if($setstruct.object) {
186 /* WHEN COULD THIS BE FALSE??
187 * isn't it supposed to be setstruct.object???
188 * (it used to be $ACTION.address)
191 $setstruct.object->obj_struc = $ACTION.address;
192 fprintf(eventfile_h,
193 "struct %s %s%s;\n\n", $ACTION.address,
194 EV_PREFIX, $setstruct.object->obj_name);
200 setdef ::= LBRACK
202 $$setlist.setnum =
203 defineset($setdef.type, $setdef.address, $setdef.keep);
204 } setlist RBRACK { $setdef.object = $setlist.setnum; }
207 setlist ::= ID
209 member($setlist.setnum, $ID.address);
210 $$setlisttail.setnum = $setlist.setnum;
211 } setlisttail
214 setlisttail ::= COMMA { $$setlist.setnum = $setlisttail.setnum; } setlist
217 translist ::= transition translisttail
219 translisttail ::= translist
220 ::=
222 transition ::= newstate { transno++; } LANGLE EQUAL EQUAL oldstate
223 event
225 CurrentEvent /* GAG! */ = $event.object;
227 predicatepart
229 $$actionpart.string = $predicatepart.string;
230 $$actionpart.newstate = $newstate.object;
231 $$actionpart.oldstate = $oldstate.object;
233 actionpart
234 SEMI
237 predicatepart ::= PREDICATE
239 $predicatepart.string = stash ( $PREDICATE.address );
241 ::= DEFAULT
243 $predicatepart.string = (char *)0;
247 actionpart ::=
248 ACTION
250 statetable( $actionpart.string, $actionpart.oldstate,
251 $actionpart.newstate,
252 acttable(actfile, $ACTION.address ),
253 CurrentEvent );
254 if( print_trans ) {
255 dump_trans( $actionpart.string, $actionpart.oldstate,
256 $actionpart.newstate,
257 $ACTION.address, CurrentEvent );
260 ::= NULLACTION
262 statetable($actionpart.string, $actionpart.oldstate, $actionpart.newstate,
263 0, CurrentEvent ); /* KLUDGE - remove this */
264 if( print_trans ) {
265 dump_trans( $actionpart.string, $actionpart.oldstate,
266 $actionpart.newstate,
267 "NULLACTION", CurrentEvent );
272 oldstate ::= ID
274 $oldstate.object = Lookup(STATESET, $ID.address);
276 ::= {
277 $$setdef.address = (char *)0;
278 $$setdef.type = (unsigned char)STATESET;
279 $$setdef.keep = 0;
281 setdef
283 $oldstate.object = $setdef.object;
287 newstate ::= ID
289 $newstate.object = Lookup(STATESET, $ID.address);
293 newstate ::= SAME
295 extern struct Object *SameState;
297 $newstate.object = SameState;
301 event ::= ID
303 $event.object = Lookup(EVENTSET, $ID.address);
305 ::=
307 $$setdef.address = (char *)0;
308 $$setdef.type = (unsigned char)EVENTSET;
309 $$setdef.keep = 0;
311 setdef
313 $event.object = $setdef.object;
317 *end