Skip to content
Snippets Groups Projects
Commit fd5a73da authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Synch

parent 0497c0a9
Branches
No related tags found
No related merge requests found
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import xdfAST.XmlParser;
import xdfAST.ParseException;
import xdfAST.Start;
public class XdfParser {
protected static Start parse(String args[]) {
Reader r = getReader(args);
Start ast = null;
try {
XmlParser parser = new XmlParser(r);
ast = parser.Start();
} catch (ParseException e) {
System.out.println(e.getMessage());
}
return ast;
}
private static Reader getReader(String[] args) {
Reader r = null;
if (args.length != 1) {
r = new InputStreamReader(System.in);
} else {
try {
r = new FileReader(args[0]);
} catch (FileNotFoundException e1) {
System.err.println("Dumper: file " + args[0] + " not found");
}
}
return r;
}
}
import xdfAST.Start;
public class XdfPrettyPrint extends XdfParser {
public static void main(String args[]) {
Start ast = parse(args);
// Dump the AST
ast.prettyPrint(" ", System.out);
}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import xlimAST.XmlParser;
import xlimAST.ParseException;
import xlimAST.Start;
public class XlimParser {
protected static Start parse(String args[]) {
Reader r = getReader(args);
Start ast = null;
try {
XmlParser parser = new XmlParser(r);
ast = parser.Start();
} catch (ParseException e) {
System.out.println(e.getMessage());
}
return ast;
}
private static Reader getReader(String[] args) {
Reader r = null;
if (args.length != 1) {
r = new InputStreamReader(System.in);
} else {
try {
r = new FileReader(args[0]);
} catch (FileNotFoundException e1) {
System.err.println("Dumper: file " + args[0] + " not found");
}
}
return r;
}
}
import xlimAST.Start;
public class XlimPrettyPrint extends XlimParser {
public static void main(String args[]) {
Start ast = parse(args);
// Dump the AST
ast.prettyPrint(" ", System.out);
}
}
<!--
Targets for working from terminal window:
build (default) - generates java files and compiles them
clean - removes all generated files and class files
Targets for working from Eclipse:
gen - generates java files
genClean - removes all generated files and their class files
-->
<project name="Actors model compiler" default="build" basedir=".">
<!-- "tools" is the directory where generators and libraries are located. -->
<property name="tools" value="../../tools"/>
<property name="javacc.home" value="${tools}/javacc-4.0"/>
<!-- compile sources -->
<target name="build" depends="xdf,xlim">
<javac debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="tools/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/>
</target>
<target name="xdf">
<ant antfile="./xlim/build.xml" target="gen" inheritAll="false"/>
</target>
<target name="xlim">
<ant antfile="./xdf/build.xml" target="gen" inheritAll="false"/>
</target>
<!-- remove generated source files and .class files -->
<target name="clean" depends="cleanGen">
<!-- delete all .class files recursively -->
<delete>
<fileset dir="." includes="**/*.class" excludes="beaver/*.class"/>
</delete>
</target>
<!-- <target name="jar" depends="build"> -->
<!-- <jar destfile="X3DCompiler.jar" basedir="." includes="**/*.class" excludes="test/**"> -->
<!-- <manifest> -->
<!-- <attribute name="Main-Class" value="GenOntology"/> -->
<!-- </manifest> -->
<!-- </jar> -->
<!-- </target> -->
<!-- remove generated source files and their .class files -->
<target name="cleanGen">
<delete dir="xlimAST"/>
<delete dir="xdfAST"/>
</target>
</project>
......@@ -7,8 +7,10 @@
*/
import java.io.PrintStream;
import java.io.FileReader;
import java.util.LinkedList;
aspect SSR {
void ASTNode.genSSR(java.io.PrintStream out) {
......@@ -26,7 +28,16 @@ aspect SSR {
}
aspect SDF {
syn boolean Instance.isSDF() = true;
syn boolean Instance.isSDF() = xlim().isSDF();
syn xlimAST.Start Instance.xlim() {
try {
xlimAST.XmlParser parser = new xlimAST.XmlParser(new FileReader(name()));
return parser.Start();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
aspect StaticSchedule {
......@@ -105,7 +116,7 @@ aspect misc {
}
eq Instance.getInstance(String s) {
// System.out.println(name()+" == "+s);
if (name().equals(s)) {
if (id().equals(s)) {
return this;
} else {
return super.getInstance(s);
......@@ -113,9 +124,48 @@ aspect misc {
}
syn String ComplexElement.name() = "";
eq Instance.name() = id();
eq Instance.name() = getUIDNote().value();
Note Instance.getUIDNote() {
for (Element e : getElements()) {
if (e instanceof Note) {
System.out.println("Checking "+e.kind());
if (e.kind().equals("UID")) {
System.out.println(" Yes");
return (Note) e;
}
}
}
return new Note(); // Probably better than returning null
}
syn String Element.kind() = "";
eq Note.kind() {
for (Attribute a : getAttributes()) {
System.out.println(" checking: "+a);
if (a.isKind()) {
System.out.println(" found "+value());
return value();
}
}
return "";
}
syn boolean Attribute.isKind() = false;
eq kind.isKind() = true;
syn String Element.value() = "";
eq Note.value() {
for (Attribute a : getAttributes()) {
if (a instanceof value) {
return fix(a.getAttrValue().getLITERAL());
}
}
return "";
}
String Instance.id() {
syn String ComplexElement.id() = "";
eq Instance.id() {
for (int i=0; i<getNumAttribute(); i++) {
Attribute a = getAttribute(i);
if (a instanceof id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment