Perfecting 4th benchmark; adding needed MySQL config files; maturing Zigbee drivers
[iot2.git] / others / javacup / iotparser.cup
1 /* Minijava Grammar */
2 import java_cup.runtime.ComplexSymbolFactory;
3 import java_cup.runtime.ScannerBuffer;
4 import java_cup.runtime.XMLElement;
5 import javax.xml.stream.XMLOutputFactory;
6 import javax.xml.stream.XMLStreamWriter;
7 import java.io.*;
8
9 import javax.xml.transform.*;
10 import javax.xml.transform.stream.*;
11
12 parser code {:
13   public Parser(Lexer lex, ComplexSymbolFactory sf) {
14     super(lex,sf);
15   }
16   public static void main(String[] args) throws Exception {
17       // initialize the symbol factory
18       ComplexSymbolFactory csf = new ComplexSymbolFactory();
19       // create a buffering scanner wrapper
20       ScannerBuffer lexer = new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csf));
21       // start parsing
22       Parser p = new Parser(lexer,csf);
23       ParseNode pn = (ParseNode) p.parse().value;
24   }
25 :};
26
27 terminal SEMICOLON, COMMA, LPAR, RPAR, LANG, RANG, BEGIN, END, ASSIGN;
28 terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS, ENUM, STRUCT; 
29 terminal TYPE;
30 terminal IDENT, STRINGCONST;
31
32 non terminal ParseNode policy;
33 non terminal ParseNode intface, methlist, meth, paramlist, param, paramtype;
34 non terminal ParseNode capablist, capab, capabcont, cont;
35 non terminal ParseNode reqlist, require, capintlist;
36 non terminal ParseNode enumdeclist, enumdec, enumlist, enummem;
37 non terminal ParseNode structdeclist, structdec, structlist, structmem;
38
39
40 /**
41  * A policy file normally consists of:
42  * 1) Interface 
43  *    - Interface definition
44  *    - List of capabilities and their contents
45  *
46  * We also define "requires" statements for users
47  * to declare their required capabilities in the
48  * generated interfaces
49  * 2) List of generated interfaces (requires)
50  *
51  * Additionally we support declarations for these
52  * data types:
53  * 3) Enumeration
54  * 4) Struct
55  */
56 policy     ::= intface:in
57         {:
58                 ParseNode pn = new ParseNode("policy");
59                 pn.addChild(in);
60                 RESULT = pn;
61         :}
62         | reqlist:rl
63         {:
64                 ParseNode pn = new ParseNode("policy");
65                 pn.addChild(rl);
66                 RESULT = pn;
67         :}
68     ;
69
70 //1) Interface class definition
71 // 1) Interface definition
72 // 2) Library list
73 // 3) Driver list
74
75 // Interface
76 intface    ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml capablist:cl enumdeclist:el structdeclist:sl END
77         {:
78                 ParseNode pn = new ParseNode("interface");
79                 pn.addChild("intface_ident").setLiteral(idint);
80                 pn.addChild(ml);
81                 pn.addChild(cl);
82                 pn.addChild(el);
83                 pn.addChild(sl);
84                 RESULT = pn;
85         :}
86     ;
87 methlist   ::= methlist:ml meth:m
88         {:
89                 ml.addChild(m);
90                 RESULT = ml;
91         :}
92     | /* empty */
93         {:
94                 ParseNode pn = new ParseNode("method_list");
95                 RESULT = pn;
96         :}
97     ;
98 meth       ::= PUBLIC TYPE:typemeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
99         {:
100                 ParseNode pn = new ParseNode("method");
101                 pn.addChild("method_type").setLiteral(typemeth);
102                 pn.addChild("method_ident").setLiteral(idmeth);
103                 pn.addChild(pl);
104                 RESULT = pn;
105         :}
106     | PUBLIC IDENT:clsmeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
107         {:
108                 ParseNode pn = new ParseNode("method");
109                 pn.addChild("method_class").setLiteral(clsmeth);
110                 pn.addChild("method_ident").setLiteral(idmeth);
111                 pn.addChild(pl);
112                 RESULT = pn;
113         :}
114         /* generic/template return value with one type, e.g. set<int> */
115     | PUBLIC IDENT:clsmeth LANG TYPE:typegen RANG IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
116         {:
117                 ParseNode pn = new ParseNode("method");
118                 pn.addChild("method_class").setLiteral((String)clsmeth + "<" + typegen + ">");
119                 pn.addChild("method_ident").setLiteral(idmeth);
120                 pn.addChild(pl);
121                 RESULT = pn;
122         :}
123     | PUBLIC IDENT:clsmeth LANG IDENT:clsgen RANG IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
124         {:
125                 ParseNode pn = new ParseNode("method");
126                 pn.addChild("method_class").setLiteral((String)clsmeth + "<" + clsgen + ">");
127                 pn.addChild("method_ident").setLiteral(idmeth);
128                 pn.addChild(pl);
129                 RESULT = pn;
130         :}
131     ;
132 paramlist  ::= paramlist:pl param:p
133         {:
134                 pl.addChild(p);
135                 RESULT = pl;
136         :}
137     | /* empty */
138         {:
139                 ParseNode pn = new ParseNode("param_list");
140                 RESULT = pn;
141         :}
142     ;
143 param      ::= TYPE:typeprm IDENT:idprm COMMA
144         {:
145                 ParseNode pn = new ParseNode("param");
146                 pn.addChild("param_type").setLiteral(typeprm);
147                 pn.addChild("param_ident").setLiteral(idprm);
148                 RESULT = pn;
149         :}
150     | TYPE:typeprm IDENT:idprm
151         {:
152                 ParseNode pn = new ParseNode("param");
153                 pn.addChild("param_type").setLiteral(typeprm);
154                 pn.addChild("param_ident").setLiteral(idprm);
155                 RESULT = pn;
156         :}
157     | IDENT:clsprm IDENT:idprm COMMA
158         {:
159                 ParseNode pn = new ParseNode("param");
160                 pn.addChild("param_class").setLiteral(clsprm);
161                 pn.addChild("param_ident").setLiteral(idprm);
162                 RESULT = pn;
163         :}
164     | IDENT:clsprm IDENT:idprm
165         {:
166                 ParseNode pn = new ParseNode("param");
167                 pn.addChild("param_class").setLiteral(clsprm);
168                 pn.addChild("param_ident").setLiteral(idprm);
169                 RESULT = pn;
170         :}
171         /* generic/template with one type, e.g. set<int> */
172     | IDENT:clsprm LANG TYPE:typegen RANG IDENT:idprm
173         {:
174                 ParseNode pn = new ParseNode("param");
175                 pn.addChild("param_class").setLiteral((String)clsprm + "<" + typegen + ">");
176                 pn.addChild("param_ident").setLiteral(idprm);
177                 RESULT = pn;
178         :}
179     | IDENT:clsprm LANG IDENT:clsgen RANG IDENT:idprm
180         {:
181                 ParseNode pn = new ParseNode("param");
182                 pn.addChild("param_class").setLiteral((String)clsprm + "<" + clsgen + ">");
183                 pn.addChild("param_ident").setLiteral(idprm);
184                 RESULT = pn;
185         :}
186         /* Add comma at the end... */
187         /* generic/template with one type, e.g. set<int> */
188     | IDENT:clsprm LANG TYPE:typegen RANG IDENT:idprm COMMA
189         {:
190                 ParseNode pn = new ParseNode("param");
191                 pn.addChild("param_class").setLiteral((String)clsprm + "<" + typegen + ">");
192                 pn.addChild("param_ident").setLiteral(idprm);
193                 RESULT = pn;
194         :}
195     | IDENT:clsprm LANG IDENT:clsgen RANG IDENT:idprm COMMA
196         {:
197                 ParseNode pn = new ParseNode("param");
198                 pn.addChild("param_class").setLiteral((String)clsprm + "<" + clsgen + ">");
199                 pn.addChild("param_ident").setLiteral(idprm);
200                 RESULT = pn;
201         :}
202     ;
203
204 //2) List of capabilities and their respective contents, i.e. description, method, etc.
205 capablist  ::= capablist:cl capab:cap
206         {:
207                 cl.addChild(cap);
208                 RESULT = cl;
209         :}
210         | /* empty */
211         {:
212                 ParseNode pn = new ParseNode("capab_list");
213                 RESULT = pn;
214         :}
215         ;
216 capab      ::= CAPABILITY IDENT:idcap BEGIN capabcont:ccont END
217         {:
218                 ParseNode pn = new ParseNode("capability");
219                 pn.addChild("capab_ident").setLiteral(idcap);
220                 pn.addChild(ccont);
221                 RESULT = pn;
222         :}
223     ;
224 capabcont  ::= capabcont:ccont cont:cnt
225         {:
226                 ccont.addChild(cnt);
227                 RESULT = ccont;
228         :}
229         | /* empty */
230         {:
231                 ParseNode pn = new ParseNode("capab_content");
232                 RESULT = pn;
233         :}
234         ;
235 cont       ::= DESCRIPTION:dsc ASSIGN STRINGCONST:strdsc SEMICOLON
236         {:
237                 ParseNode pn = new ParseNode("capab_content");
238                 pn.addChild("capab_desc").setLiteral(strdsc);
239                 RESULT = pn;
240         :}
241         | METHOD:mtd ASSIGN STRINGCONST:strmeth SEMICOLON
242         {:
243                 ParseNode pn = new ParseNode("capab_content");
244                 pn.addChild("capab_meth").setLiteral(strmeth);
245                 RESULT = pn;
246         :}
247         ;
248
249 //3) List of interface generation definitions ("requires" statements)
250 reqlist    ::= reqlist:rl require:req
251         {:
252                 rl.addChild(req);
253                 RESULT = rl;
254         :}
255         | /* empty */
256         {:
257                 ParseNode pn = new ParseNode("reqlist");
258                 RESULT = pn;
259         :}
260         ;
261 require    ::= REQUIRES IDENT:idint WITH capintlist:cil AS INTERFACE IDENT:idnewint SEMICOLON
262         {:
263                 ParseNode pn = new ParseNode("requires");
264                 pn.addChild("intface_ident").setLiteral(idint);
265                 pn.addChild(cil);
266                 pn.addChild("new_intface_ident").setLiteral(idnewint);
267                 RESULT = pn;
268         :}
269         ;
270 capintlist ::= IDENT:idcap
271         {:
272                 ParseNode pn = new ParseNode("capab_ident_list");
273                 pn.addChild("capab_ident").setLiteral(idcap);
274                 RESULT = pn;
275         :}
276         | capintlist:cil COMMA IDENT:idcap
277         {:
278                 cil.addChild("capab_ident").setLiteral(idcap);
279                 RESULT = cil;
280         :}
281         | /* empty */
282         {:
283                 ParseNode pn = new ParseNode("capab_ident_list");
284                 RESULT = pn;
285         :}
286         ;
287
288 //4) Enumeration declaration list
289 enumdeclist  ::= enumdeclist:el enumdec:ed
290         {:
291                 el.addChild(ed);
292                 RESULT = el;
293         :}
294         | /* empty */
295         {:
296                 ParseNode pn = new ParseNode("enum_dec_list");
297                 RESULT = pn;
298         :}
299         ;
300 enumdec         ::= ENUM IDENT:idenumdec BEGIN enumlist:el END
301         {:
302                 ParseNode pn = new ParseNode("enum_dec");
303                 pn.addChild("enum_dec_ident").setLiteral(idenumdec);
304                 pn.addChild(el);
305                 RESULT = pn;
306         :}
307         ;
308 enumlist        ::= enumlist:el enummem:e
309         {:
310                 el.addChild(e);
311                 RESULT = el;
312         :}
313     | /* empty */
314         {:
315                 ParseNode pn = new ParseNode("enum_list");
316                 RESULT = pn;
317         :}
318     ;
319 enummem         ::= IDENT:idenum COMMA
320         {:
321                 ParseNode pn = new ParseNode("enum_mem");
322                 pn.addChild("enum_ident").setLiteral(idenum);
323                 RESULT = pn;
324         :}
325     | IDENT:idenum
326         {:
327                 ParseNode pn = new ParseNode("enum_mem");
328                 pn.addChild("enum_ident").setLiteral(idenum);
329                 RESULT = pn;
330         :}
331     ;
332
333 //5) Struct declaration list
334 structdeclist  ::= structdeclist:sl structdec:sd
335         {:
336                 sl.addChild(sd);
337                 RESULT = sl;
338         :}
339         | /* empty */
340         {:
341                 ParseNode pn = new ParseNode("struct_dec_list");
342                 RESULT = pn;
343         :}
344         ;
345 structdec       ::= STRUCT IDENT:idstructdec BEGIN structlist:sl END
346         {:
347                 ParseNode pn = new ParseNode("struct_dec");
348                 pn.addChild("struct_dec_ident").setLiteral(idstructdec);
349                 pn.addChild(sl);
350                 RESULT = pn;
351         :}
352     ;
353 structlist      ::= structlist:sl structmem:s
354         {:
355                 sl.addChild(s);
356                 RESULT = sl;
357         :}
358     | /* empty */
359         {:
360                 ParseNode pn = new ParseNode("struct_list");
361                 RESULT = pn;
362         :}
363     ;
364 structmem       ::= TYPE:typestr IDENT:idstr SEMICOLON
365         {:
366                 ParseNode pn = new ParseNode("struct_mem");
367                 pn.addChild("struct_type").setLiteral(typestr);
368                 pn.addChild("struct_ident").setLiteral(idstr);
369                 RESULT = pn;
370         :}
371     | IDENT:clsstr IDENT:idstr SEMICOLON
372         {:
373                 ParseNode pn = new ParseNode("struct_mem");
374                 pn.addChild("struct_class").setLiteral(clsstr);
375                 pn.addChild("struct_ident").setLiteral(idstr);
376                 RESULT = pn;
377         :}
378     | IDENT:clsstr LANG IDENT:clsgen RANG IDENT:idstr SEMICOLON
379         {:
380                 ParseNode pn = new ParseNode("struct_mem");
381                 pn.addChild("struct_class").setLiteral((String)clsstr + "<" + clsgen + ">");
382                 pn.addChild("struct_ident").setLiteral(idstr);
383                 RESULT = pn;
384         :}
385     ;