Commit 24d5c10e authored by Anders Nilsson's avatar Anders Nilsson
Browse files

JavaCC generation almost(?) complete

parent 849be243
/* -*-Java-*- */
import java.io.*;
import java.util.*;
aspect AbsGrammarGeneration {
void ASTNode.genAbsGrammar(PrintStream pStream) {
......@@ -138,25 +139,35 @@ aspect JavaCCGen {
pStream.println("void "+getId()+"() : {}");
pStream.println("{");
if (getId().equals("Device")) {
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
pStream.println(")");
} else {
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()+")");
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("}");
}
......
/* -*-Java-*- */
aspect Misc {
syn Start ASTNode.goStart() = getParent().goStart();
eq Start.goStart() = this;
}
/* -*-Java-*- */
import java.util.ArrayList;
aspect Types {
syn lazy OClass OClass.getSuperClass();
eq OwlClassDecl.getSuperClass() {
......@@ -51,6 +53,25 @@ aspect Types {
// }
// return p;
}
syn lazy ArrayList OClass.getSubClasses();
eq OwlClassUse.getSubClasses() = decl().getSubClasses();
eq OwlClassDecl.getSubClasses() {
return goStart().getSubClasses(this,new ArrayList());
}
syn ArrayList ASTNode.getSubClasses(OwlClassDecl klass, ArrayList l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).getSubClasses(klass,l);
}
return l;
}
eq OwlClassDecl.getSubClasses(OwlClassDecl klass, ArrayList l) {
if (getSuperClass() == klass) {
l.add(this);
}
return l;
}
}
aspect Restrictions {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment