import javax.xml.transform.*;
import javax.xml.transform.stream.*;
+
parser code {:
public Parser(Lexer lex, ComplexSymbolFactory sf) {
super(lex,sf);
ScannerBuffer lexer = new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csf));
// start parsing
Parser p = new Parser(lexer,csf);
- XMLElement e = (XMLElement)p.parse().value;
+ 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");
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")));
+ transformer.transform(text, new StreamResult(new File("ast.html")));*/
}
:};
terminal TYPE;
terminal IDENT, STRINGCONST;
-non terminal policy, intface, methlist, meth, paramlist, param;
-non terminal capablist, capab, capabcont, cont;
-non terminal reqlist, require, capintlist;
+non terminal ParseNode policy, 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:
* 2) List of capabilities and their contents
* 3) List of interface generation definitions
*/
-policy ::= intface:in capablist:cap reqlist:rl
+policy ::=
+ intface:in capablist:cap reqlist:rl
+ {:
+ ParseNode pn = new ParseNode("policy");
+ pn.addChild(in);
+ pn.addChild(cap);
+ pn.addChild(rl);
+ RESULT = pn;
+ :}
;
// Interface class definition
intface ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml END
+ {:
+ ParseNode pn = new ParseNode("interface");
+ pn.addChild("intface_ident").setLiteral(idint);
+ pn.addChild(ml);
+ RESULT = pn;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("interface");
+ RESULT = pn;
+ :}
;
methlist ::= methlist:ml meth:m
+ {:
+ ml.addChild(m);
+ RESULT = ml;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("method_list");
+ RESULT = pn;
+ :}
;
meth ::= PUBLIC TYPE:typemeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
+ {:
+ ParseNode pn = new ParseNode("method");
+ pn.addChild("method_type").setLiteral(typemeth);
+ pn.addChild("method_ident").setLiteral(idmeth);
+ pn.addChild(pl);
+ RESULT = pn;
+ :}
;
paramlist ::= paramlist:pl param:p
+ {:
+ pl.addChild(p);
+ RESULT = pl;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("param_list");
+ RESULT = pn;
+ :}
;
param ::= TYPE:typeprm IDENT:idprm COMMA
+ {:
+ ParseNode pn = new ParseNode("param");
+ pn.addChild("param_type").setLiteral(typeprm);
+ pn.addChild("param_ident").setLiteral(idprm);
+ RESULT = pn;
+ :}
| TYPE:typeprm IDENT:idprm
+ {:
+ ParseNode pn = new ParseNode("param");
+ pn.addChild("param_type").setLiteral(typeprm);
+ pn.addChild("param_ident").setLiteral(idprm);
+ RESULT = pn;
+ :}
| IDENT:clsprm IDENT:idprm COMMA
+ {:
+ ParseNode pn = new ParseNode("param");
+ pn.addChild("param_class").setLiteral(clsprm);
+ pn.addChild("param_ident").setLiteral(idprm);
+ RESULT = pn;
+ :}
| IDENT:clsprm IDENT:idprm
+ {:
+ ParseNode pn = new ParseNode("param");
+ pn.addChild("param_class").setLiteral(clsprm);
+ pn.addChild("param_ident").setLiteral(idprm);
+ RESULT = pn;
+ :}
;
// List of capabilities and their respective contents, i.e. description, method, etc.
capablist ::= capablist:clist capab:cap
+ {:
+ clist.addChild(cap);
+ RESULT = clist;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("capab_list");
+ RESULT = pn;
+ :}
;
capab ::= CAPABILITY IDENT:idint DOT 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;
+ :}
;
capabcont ::= capabcont:ccont cont:cnt
+ {:
+ ccont.addChild(cnt);
+ RESULT = ccont;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("capab_content");
+ RESULT = pn;
+ :}
;
-cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST SEMICOLON
+cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST:str SEMICOLON
+ {:
+ ParseNode pn = new ParseNode("capab_content");
+ pn.addChild("capab_desc").setLiteral(str);
+ RESULT = pn;
+ :}
| METHOD:mtd ASSIGN IDENT:idmeth SEMICOLON
+ {:
+ ParseNode pn = new ParseNode("capab_content");
+ pn.addChild("capab_ident").setLiteral(idmeth);
+ RESULT = pn;
+ :}
;
// List of interface generation definitions
reqlist ::= reqlist:rl require:req
+ {:
+ rl.addChild(req);
+ RESULT = rl;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("requires_list");
+ RESULT = pn;
+ :}
;
require ::= REQUIRES IDENT:idint WITH capintlist:cil AS INTERFACE IDENT:idnewint SEMICOLON
+ {:
+ ParseNode pn = new ParseNode("requires");
+ pn.addChild("intface_ident").setLiteral(idint);
+ pn.addChild(cil);
+ pn.addChild("new_intface_ident").setLiteral(idnewint);
+ RESULT = pn;
+ :}
;
capintlist ::= IDENT:idcap
+ {:
+ ParseNode pn = new ParseNode("capab_ident_list");
+ pn.addChild("capab_ident").setLiteral(idcap);
+ RESULT = pn;
+ :}
| capintlist:cil COMMA IDENT:idcap
+ {:
+ cil.addChild("capab_ident").setLiteral(idcap);
+ RESULT = cil;
+ :}
| /* empty */
+ {:
+ ParseNode pn = new ParseNode("capab_ident_list");
+ RESULT = pn;
+ :}
;