Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Nilsson
OwlCompiler
Commits
6e9a5503
Commit
6e9a5503
authored
Dec 01, 2006
by
Anders Nilsson
Browse files
Generated compiler can now run DumpTree on V08.owl
parent
a52e3838
Changes
3
Hide whitespace changes
Inline
Side-by-side
CompilerGeneration.jrag
View file @
6e9a5503
...
...
@@ -180,17 +180,21 @@ aspect GenRewrites {
// crasch from NullPointerException. Children should be filled
// in from rewrites instead
Restrictions restr = getRestrictions();
pStream.println(ind(3)+"List l;");
for (int i=0; i<restr.getNumOwlRestriction(); i++) {
OwlRestriction r = restr.getOwlRestriction(i);
pStream.println(ind(3)+"l = new List();");
pStream.println(ind(3)+"for (int i=0; i<getNumElement(); i++) {");
pStream.println(ind(4)+"if (getElement(i) instanceof "+r.name()+") {");
pStream.println(ind(5)+"l.add(getElement(i));");
pStream.println(ind(4)+"}");
pStream.println(ind(3)+"}");
if (r.allValuesFrom()) {
pStream.println(ind(3)+"node.set"+r.name()+"List(new List());");
// pStream.println(ind(3)+"node.set"+r.name().substring(0,1).toLowerCase()+
// r.name().substring(1)+"List(new List());");
pStream.println(ind(3)+"node.set"+r.name()+"List(l);");
// pStream.println(ind(3)+"node.set"+r.name()+"List(new List());");
} else {
pStream.println(ind(3)+r.name()+" c"+ix+" = new "+r.name()+"();");
pStream.println(ind(3)+"node.set"+r.name()+"(c"+(ix++)+");");
// pStream.println(ind(3)+"node.set"+r.name().substring(0,1).toLowerCase()+
// r.name().substring(1)+"(c"+(ix++)+");");
}
}
pStream.println(ind(3)+"return node;");
...
...
@@ -200,107 +204,6 @@ aspect GenRewrites {
}
// JavaCC grammar is not generated, but hand-written as general as is possible
// aspect JavaCCGen {
// public void ASTNode.genJavaCC(PrintStream pStream) {
// for (int i=0; i<getNumChild(); i++) {
// getChild(i).genAbsGrammar(pStream);
// }
// }
// public void Start.genJavaCC(PrintStream pStream) {
// genJavaCCHeader(pStream);
// pStream.println();
// genTokenDefs(pStream);
// pStream.println();
// genJavaCCLiterals(pStream);
// pStream.println();
// genJavaCCIdentifiers(pStream);
// pStream.println();
// genJavaCCSeparators(pStream);
// pStream.println();
// genJavaCCOperators(pStream);
// pStream.println();
// // OK, so now it's time to start generating some real grammar
// // productions.
// genJavaCCGrammar(pStream);
// }
// void ASTNode.genTokenDefs(PrintStream pStream) {
// for (int i=0; i<getNumChild(); i++) {
// getChild(i).genTokenDefs(pStream);
// }
// }
// void Start.genTokenDefs(PrintStream pStream) {
// pStream.println("<DEFAULT, BOUNDS> TOKEN : /* RESERVED WORDS */");
// pStream.println("{");
// pStream.println(" <XML \t : \"xml\" >");
// super.genTokenDefs(pStream);
// pStream.println("}");
// pStream.println();
// }
// void OwlClassDecl.genTokenDefs(PrintStream pStream) {
// pStream.println(" |<"+getId().toUpperCase()+" \t : \""+getId()+"\">");
// }
// void ASTNode.genJavaCCGrammar(PrintStream pStream) {
// for (int i=0; i<getNumChild(); i++) {
// getChild(i).genJavaCCGrammar(pStream);
// }
// }
// void Start.genJavaCCGrammar(PrintStream pStream) {
// pStream.println("Start Start() #Start : {}");
// pStream.println("{");
// pStream.println(" (Device())*");
// pStream.println(" { return jjtThis; }");
// pStream.println("}");
// pStream.println();
// super.genJavaCCGrammar(pStream);
// }
// void OwlClassDecl.genJavaCCGrammar(PrintStream pStream) {
// pStream.println("void "+getId()+"() : {}");
// pStream.println("{");
// if (getId().equals("Device")) {
// pStream.print(" \"<\"");
// // pStream.print("\"<\" ( <DEVICE> \">\"");
// // Restrictions restr = getRestrictions();
// // for (int i=0; i< getNumRestriction(); i++) {
// // OwlRestriction res = restr.getOwlRestriction(i);
// // pStream.print("("+res.getRestrictionClassId()+")"+
// // (res.allValuesFrom()?"*":"")+" ");
// // }
// // pStream.println(" #Device("+getNumRestriction()+"))");
// // // List all subclasses
// // Iterator subIter = getSubClasses().iterator();
// // while (subIter.hasNext()) {
// // OwlClassDecl subClass = (OwlClassDecl) subIter.next();
// // pStream.println("| "+subClass.getId()+"()");
// // }
// }
// pStream.print(" ( <"+getId().toUpperCase()+"> \">\"");
// Restrictions restr = getRestrictions();
// for (int i=0; i< getNumRestriction(); i++) {
// OwlRestriction res = restr.getOwlRestriction(i);
// pStream.print("("+res.getRestrictionClassId()+"())"+
// (res.allValuesFrom()?"*":"")+" ");
// }
// pStream.println(" #"+getId()+"("+getNumRestriction()+"))");
// // List all subclasses
// Iterator subIter = getSubClasses().iterator();
// while (subIter.hasNext()) {
// OwlClassDecl subClass = (OwlClassDecl) subIter.next();
// pStream.println(" | "+subClass.getId()+"()");
// }
// pStream.println("}");
// }
// }
aspect ParserGen {
public void Start.genParser(PrintStream pStream) {
...
...
Types.jrag
View file @
6e9a5503
...
...
@@ -109,7 +109,9 @@ aspect Restrictions {
}
void OwlRestriction.collectRestrictions(List l) {
l.add(this);
if (allValuesFrom()) {
l.add(this);
}
}
syn int OwlClassDecl.getNumRestriction() = getRestrictions().getNumOwlRestriction();
...
...
@@ -130,7 +132,9 @@ aspect Restrictions {
}
void OwlRestriction.collectOwnRestrictions(List l) {
l.add(this);
if (allValuesFrom()) {
l.add(this);
}
}
syn int OwlClassDecl.getNumOwnRestriction() =
...
...
owl.ast
View file @
6e9a5503
...
...
@@ -82,6 +82,6 @@ abstract OwlValuesFrom: ComplexElement;
Properties ::= Property:Element*;
Restrictions ::= OwlRestriction*;
//
Restrictions ::= OwlRestriction*;
abstract OwlProperty : ComplexElement;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment