// start parsing
Parser p = new Parser(lexer,csf);
ParseNode pn = (ParseNode) p.parse().value;
-
- /*XMLElement e = (XMLElement)p.parse().value;
- // create XML output file
- XMLOutputFactory outFactory = XMLOutputFactory.newInstance();
- XMLStreamWriter sw = outFactory.createXMLStreamWriter(new FileOutputStream(args[1]), "UTF-8");
- // dump XML output to the file
- XMLElement.dump(lexer,sw,e,"expr","stmt");
-
- // transform the parse tree into an AST and a rendered HTML version
- Transformer transformer = TransformerFactory.newInstance()
- .newTransformer(new StreamSource(new File("tree.xsl")));
- Source text = new StreamSource(new File(args[1]));
- transformer.transform(text, new StreamResult(new File("output.xml")));
- transformer = TransformerFactory.newInstance()
- .newTransformer(new StreamSource(new File("tree-view.xsl")));
- text = new StreamSource(new File("output.xml"));
- transformer.transform(text, new StreamResult(new File("ast.html")));*/
}
:};
-terminal SEMICOLON, COMMA, DOT, LPAR, RPAR, BEGIN, END, ASSIGN;
+terminal SEMICOLON, COMMA, LPAR, RPAR, BEGIN, END, ASSIGN;
terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS;
terminal TYPE;
terminal IDENT, STRINGCONST;
-non terminal ParseNode policy, intface, methlist, meth, paramlist, param;
+non terminal ParseNode policy;
+non terminal ParseNode intface, methlist, meth, paramlist, param;
non terminal ParseNode capablist, capab, capabcont, cont;
non terminal ParseNode reqlist, require, capintlist;
/**
- * A policy file normally consists of 3 parts:
- * 1) Interface (in Java syntax)
- * 2) List of capabilities and their contents
- * 3) List of interface generation definitions
+ * A policy file normally consists of:
+ * 1) Interface
+ * - Interface definition
+ * - List of capabilities and their contents
+ *
+ * We also define "requires" statements for users
+ * to declare their required capabilities in the
+ * generated interfaces
+ * 2) List of generated interfaces (requires)
*/
-policy ::=
- intface:in capablist:cap reqlist:rl
+policy ::= intface:in
{:
ParseNode pn = new ParseNode("policy");
pn.addChild(in);
- pn.addChild(cap);
+ RESULT = pn;
+ :}
+ | reqlist:rl
+ {:
+ ParseNode pn = new ParseNode("policy");
pn.addChild(rl);
RESULT = pn;
:}
;
-// Interface class definition
-intface ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml END
+//1) Interface class definition
+// 1) Interface definition
+// 2) Library list
+// 3) Driver list
+
+// Interface
+intface ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml capablist:cl END
{:
ParseNode pn = new ParseNode("interface");
pn.addChild("intface_ident").setLiteral(idint);
pn.addChild(ml);
- RESULT = pn;
- :}
- | /* empty */
- {:
- ParseNode pn = new ParseNode("interface");
+ pn.addChild(cl);
RESULT = pn;
:}
;
pn.addChild(pl);
RESULT = pn;
:}
+ | PUBLIC IDENT:clsmeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
+ {:
+ ParseNode pn = new ParseNode("method");
+ pn.addChild("method_class").setLiteral(clsmeth);
+ pn.addChild("method_ident").setLiteral(idmeth);
+ pn.addChild(pl);
+ RESULT = pn;
+ :}
;
paramlist ::= paramlist:pl param:p
{:
:}
;
-// List of capabilities and their respective contents, i.e. description, method, etc.
-capablist ::= capablist:clist capab:cap
+//2) List of capabilities and their respective contents, i.e. description, method, etc.
+capablist ::= capablist:cl capab:cap
{:
- clist.addChild(cap);
- RESULT = clist;
+ cl.addChild(cap);
+ RESULT = cl;
:}
| /* empty */
{:
RESULT = pn;
:}
;
-capab ::= CAPABILITY IDENT:idint DOT IDENT:idcap BEGIN capabcont:ccont END
+capab ::= CAPABILITY IDENT:idcap BEGIN capabcont:ccont END
{:
ParseNode pn = new ParseNode("capability");
- pn.addChild("intface_ident").setLiteral(idint);
pn.addChild("capab_ident").setLiteral(idcap);
pn.addChild(ccont);
RESULT = pn;
RESULT = pn;
:}
;
-cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST:str SEMICOLON
+cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST:strdsc SEMICOLON
{:
ParseNode pn = new ParseNode("capab_content");
- pn.addChild("capab_desc").setLiteral(str);
+ pn.addChild("capab_desc").setLiteral(strdsc);
RESULT = pn;
:}
- | METHOD:mtd ASSIGN IDENT:idmeth SEMICOLON
+ | METHOD:mtd ASSIGN STRINGCONST:strmeth SEMICOLON
{:
ParseNode pn = new ParseNode("capab_content");
- pn.addChild("capab_ident").setLiteral(idmeth);
+ pn.addChild("capab_meth").setLiteral(strmeth);
RESULT = pn;
:}
;
-// List of interface generation definitions
+//3) List of interface generation definitions ("requires" statements)
reqlist ::= reqlist:rl require:req
{:
rl.addChild(req);
:}
| /* empty */
{:
- ParseNode pn = new ParseNode("requires_list");
+ ParseNode pn = new ParseNode("reqlist");
RESULT = pn;
:}
;