Commit 3ccc538d authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Can now compile generated .ast and .jjt all the way to class files. Still...

Can now compile generated .ast and .jjt all the way to class files. Still missing a lot of JavaCC productions before it is possible to test the compiler
parent cf67d3ea
......@@ -135,12 +135,16 @@ aspect JavaCCGen {
}
void OwlClassDecl.genJavaCCGrammar(PrintStream pStream) {
pStream.println("void "+getId()+" : {}");
pStream.println("void "+getId()+"() : {}");
pStream.println("{");
if (getId().equals("Device")) {
pStream.print("\"<\" <DEVICE> \">\"");
pStream.print("Property()* Skill()* MainFunction() #");
pStream.println("Device(3)");
pStream.print("(Property())* (Skill())* MainFunction() #");
pStream.println("Device("+getNumRestriction()+")");
} else {
pStream.print(" <"+getId().toUpperCase()+"> \">\"");
pStream.print("(Property())* (Skill())* MainFunction() #");
pStream.println(getId()+"("+getNumRestriction()+")");
}
pStream.println("}");
}
......
......@@ -13,7 +13,7 @@ aspect JavaCCChunks {
pStream.println("} ");
pStream.println();
pStream.println("PARSER_BEGIN(SiarasParser)");
pStream.println(" package siaras.AST;");
pStream.println(" package AST;");
pStream.println(" public class SiarasParser {");
pStream.println("}");
pStream.println("PARSER_END(SiarasParser)");
......@@ -73,10 +73,10 @@ aspect JavaCCChunks {
pStream.println(" |");
pStream.println(" < CHARACTER_LITERAL:");
pStream.println(" \"\'\"");
pStream.println(" ( (~[\"\'\",\"\\\",\"\n\",\"\r\"])");
pStream.println(" ( (~[\"\'\",\"\\\\\",\"\\n\",\"\\r\"])");
pStream.println(" |");
pStream.println(" (\"\\\"");
pStream.println(" ( [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\",\"'\",\"\\\"\"]");
pStream.println(" (\"\\\\\"");
pStream.println(" ( [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\\\",\"'\",\"\\\"\"]");
pStream.println(" |");
pStream.println(" [\"0\"-\"7\"] ( [\"0\"-\"7\"] )?");
pStream.println(" |");
......@@ -89,10 +89,10 @@ aspect JavaCCChunks {
pStream.println(" |");
pStream.println(" < STRING_LITERAL:");
pStream.println(" \"\\\"\"");
pStream.println(" ( (~[\"\\\"\",\"\\\",\"\n\",\"\r\"])");
pStream.println(" ( (~[\"\\\"\",\"\\\\\",\"\\n\",\"\\r\"])");
pStream.println(" |");
pStream.println(" (\"\\\"");
pStream.println(" ( [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\",\"'\",\"\\\"\"]");
pStream.println(" (\"\\\\\"");
pStream.println(" ( [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\\\",\"'\",\"\\\"\"]");
pStream.println(" |");
pStream.println(" [\"0\"-\"7\"] ( [\"0\"-\"7\"] )?");
pStream.println(" |");
......
......@@ -3,142 +3,144 @@
aspect Types {
syn lazy OClass OClass.getSuperClass();
eq OwlClassDecl.getSuperClass() {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsSubClassOf) {
RdfsSubClassOf e = (RdfsSubClassOf) getElement(i);
if (e.getElement(0) instanceof OClass) {
return ((OClass) e.getElement(0)).decl();
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsSubClassOf) {
RdfsSubClassOf e = (RdfsSubClassOf) getElement(i);
if (e.getElement(0) instanceof OClass) {
return ((OClass) e.getElement(0)).decl();
}
}
}
}
}
// No super class found, return an owl Thing instead.
return new OwlClassDecl(new List(), new List(), "Thing");
// No super class found, return an owl Thing instead.
return new OwlClassDecl(new List(), new List(), "Thing");
}
eq OwlClassUse.getSuperClass() {
return decl().getSuperClass();
return decl().getSuperClass();
}
syn lazy OwlClassDecl OClass.decl();
eq OwlClassDecl.decl() = this;
eq OwlClassUse.decl() {
ComplexElement top = getTopElement();
for (int i=0; i<top.getNumElement(); i++) {
if (getId().equals(((ComplexElement) top.getElement(i)).getId())) {
return (OwlClassDecl) top.getElement(i);
}
}
// OK, then let's see if this class is declared by w3.org
String id = getId();
if (id.endsWith("Thing")) {
return new OwlClassDecl(new List(), new List(), "Thing");
}
// No decl found, so let's return null. Not sure if that's
// that the right thing to do though.
return new OwlClassDecl(new List(), new List(), "_Unknown_");
ComplexElement top = getTopElement();
for (int i=0; i<top.getNumElement(); i++) {
if (getId().equals(((ComplexElement) top.getElement(i)).getId())) {
return (OwlClassDecl) top.getElement(i);
}
}
// OK, then let's see if this class is declared by w3.org
String id = getId();
if (id.endsWith("Thing")) {
return new OwlClassDecl(new List(), new List(), "Thing");
}
// No decl found, so let's return null. Not sure if that's
// that the right thing to do though.
return new OwlClassDecl(new List(), new List(), "_Unknown_");
}
syn lazy Properties OwlClassDecl.getProperties() {
List l = new List();
// getTopElement().collectProperties(l);
collectProperties(l);
return new Properties(l);
// Properties p = new Properties();
// for (int i=0; i<l.getNumChild(); i++) {
// OwlProperty op = (OwlProperty) l.getChild(i);
// if (op.domainIncludes(this)) {
// p.addProperty(op);
// }
// }
// return p;
List l = new List();
// getTopElement().collectProperties(l);
collectProperties(l);
return new Properties(l);
// Properties p = new Properties();
// for (int i=0; i<l.getNumChild(); i++) {
// OwlProperty op = (OwlProperty) l.getChild(i);
// if (op.domainIncludes(this)) {
// p.addProperty(op);
// }
// }
// return p;
}
}
aspect Restrictions {
Restrictions OwlClassDecl.restrictions;
Restrictions OwlClassDecl.restrictions;
syn lazy Restrictions OwlClassDecl.getRestrictions() {
if (restrictions == null) {
List l = new List();
collectRestrictions(l);
restrictions = new Restrictions(l);
}
return restrictions;
}
syn lazy Restrictions OwlClassDecl.getRestrictions() {
if (restrictions == null) {
List l = new List();
collectRestrictions(l);
restrictions = new Restrictions(l);
}
return restrictions;
}
void ASTNode.collectRestrictions(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectRestrictions(l);
}
}
void ASTNode.collectRestrictions(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectRestrictions(l);
}
}
void OwlRestriction.collectRestrictions(List l) {
l.add(this);
}
void OwlRestriction.collectRestrictions(List l) {
l.add(this);
}
syn int OwlClassDecl.getNumRestriction() = getRestrictions().getNumOwlRestriction();
}
aspect Properties {
void ASTNode.collectProperties(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectProperties(l);
}
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectProperties(l);
}
}
void OwlProperty.collectProperties(List l) {
l.add(this);
l.add(this);
}
boolean ASTNode.domainIncludes(OClass clazz) {
return false;
return false;
}
boolean OwlObjectProperty.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsDomain) {
return ((RdfsDomain) getElement(i)).domainIncludes(clazz);
}
}
return false;
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsDomain) {
return ((RdfsDomain) getElement(i)).domainIncludes(clazz);
}
}
return false;
}
boolean RdfsDomain.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
boolean OwlUnionOf.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
boolean OClass.domainIncludes(OClass clazz) {
if (!getId().equals("_Unknown_")) {
return getId().equals(clazz.getId());
}
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
if (!getId().equals("_Unknown_")) {
return getId().equals(clazz.getId());
}
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
syn lazy RdfsRange Element.range() = null;
eq OwlObjectProperty.range() {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsRange) {
return (RdfsRange) getElement(i);
}
}
return null;
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsRange) {
return (RdfsRange) getElement(i);
}
}
return null;
}
}
......@@ -27,7 +27,7 @@
<!-- compile sources -->
<target name="build" depends="gen">
<javac compiler="jikes" debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="tools/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/>
<javac compiler="jikes" debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="tools/** siaras/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/>
</target>
<!-- generate compiler source files -->
......
Start ::= Device*;
abstract Thing ::=;
Displace : Move ::=;
Turn : Move ::=;
Move : ManipulationAndHandlingFunction ::=;
MagnetGripper : Gripper ::=;
Orient : Move ::=;
ParallelGripper : PincerGripper ::=;
Arrange : Move ::=;
Feed : Move ::=;
Gripper : ManipulationAndHandling ::=;
StorePartlyOrdered : Store ::=;
ManipulationAndHandlingFunction : MainFunction ::=;
Manufacturing : Device ::=;
Store : ManipulationAndHandlingFunction ::=;
Task : Thing ::=;
MainFunction : Skill ::=;
JointFingerGripper : FingerGripper ::=;
LineParallelGripper : ParallelGripper ::=;
Pass : Move ::=;
Pan : Move ::=;
PincerGripper : Gripper ::=;
ID : Property ::=;
CircularParallelGripper : ParallelGripper ::=;
Assembly : Device ::=;
StoreUnOrdered : Store ::=;
AdditionalFunction : Skill ::=;
Convey : Move ::=;
Device : Thing ::= property:Property* skill:Skill* mainFunction:MainFunction;
FingerGripper : Gripper ::=;
StoreInOrder : Store ::=;
GeneralParallelGripper : ParallelGripper ::=;
Property : Thing ::=;
AngleGripper : PincerGripper ::=;
ManipulationAndHandling : Device ::=;
VacuumGripper : Gripper ::=;
Cost : Property ::=;
IntelligentRobot : Thing ::=;
ElasticFingerGripper : FingerGripper ::=;
Position : Move ::=;
Skill : Thing ::= device:Device*;
options {
MULTI = true;
VISITOR = true;
NODE_DEFAULT_VOID = true;
NODE_SCOPE_HOOK = false;
NODE_PREFIX = "";
JAVA_UNICODE_ESCAPE = true;
STATIC = false;
}
PARSER_BEGIN(SiarasParser)
package AST;
public class SiarasParser {
}
PARSER_END(SiarasParser)
//----------------------------------------------//
// LEXICAL TOKENS //
//----------------------------------------------//
<DEFAULT, BOUNDS> SKIP : /* WHITE SPACE */
{
" "
|
"\t"
|
"\n"
|
"\r"
|
"\f"
}// WHITE SPACE
SPECIAL_TOKEN : /* COMMENTS */
{
< "<!--" ( ~["-"] | ( "-" ~["-"] ) )* "-->">
| < "<rdfs:comment" ( ~["<"] | ( "<" ~["/"] ) )* "</rdfs:comment>" >
}// COMMENTS
<DEFAULT, BOUNDS> TOKEN : /* RESERVED WORDS */
{
<XML : "xml" >
|<DISPLACE : "Displace">
|<TURN : "Turn">
|<MOVE : "Move">
|<MAGNETGRIPPER : "MagnetGripper">
|<ORIENT : "Orient">
|<PARALLELGRIPPER : "ParallelGripper">
|<ARRANGE : "Arrange">
|<FEED : "Feed">
|<GRIPPER : "Gripper">
|<STOREPARTLYORDERED : "StorePartlyOrdered">
|<MANIPULATIONANDHANDLINGFUNCTION : "ManipulationAndHandlingFunction">
|<MANUFACTURING : "Manufacturing">
|<STORE : "Store">
|<TASK : "Task">
|<MAINFUNCTION : "MainFunction">
|<JOINTFINGERGRIPPER : "JointFingerGripper">
|<LINEPARALLELGRIPPER : "LineParallelGripper">
|<PASS : "Pass">
|<PAN : "Pan">
|<PINCERGRIPPER : "PincerGripper">
|<ID : "ID">
|<CIRCULARPARALLELGRIPPER : "CircularParallelGripper">
|<ASSEMBLY : "Assembly">
|<STOREUNORDERED : "StoreUnOrdered">
|<ADDITIONALFUNCTION : "AdditionalFunction">
|<CONVEY : "Convey">
|<DEVICE : "Device">
|<FINGERGRIPPER : "FingerGripper">
|<STOREINORDER : "StoreInOrder">
|<GENERALPARALLELGRIPPER : "GeneralParallelGripper">
|<PROPERTY : "Property">
|<ANGLEGRIPPER : "AngleGripper">
|<MANIPULATIONANDHANDLING : "ManipulationAndHandling">
|<VACUUMGRIPPER : "VacuumGripper">
|<COST : "Cost">
|<INTELLIGENTROBOT : "IntelligentRobot">
|<ELASTICFINGERGRIPPER : "ElasticFingerGripper">
|<POSITION : "Position">
|<SKILL : "Skill">
}
<DEFAULT, BOUNDS> TOKEN : /* LITERALS */
{
< INTEGER_LITERAL:
<DECIMAL_LITERAL> (["l","L"])?
|
<HEX_LITERAL> (["l","L"])?
|
<OCTAL_LITERAL> (["l","L"])?
>
|
< #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
|
< #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
|
< #OCTAL_LITERAL: "0" (["0"-"7"])* >
|
< FLOAT_LITERAL:
(["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
|
"." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
|
(["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
|
(["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
>
|
< #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
< CHARACTER_LITERAL:
"'"
( (~["'","\\","\n","\r"])
|
("\\"
( ["n","t","b","r","f","\\","'","\""]
|
["0"-"7"] ( ["0"-"7"] )?
|
["0"-"3"] ["0"-"7"] ["0"-"7"]
)
)
)
"'"
>
|
< STRING_LITERAL:
"\""
( (~["\"","\\","\n","\r"])
|
("\\"
( ["n","t","b","r","f","\\","'","\""]
|
["0"-"7"] ( ["0"-"7"] )?
|
["0"-"3"] ["0"-"7"] ["0"-"7"]
)
)
)*
"\""
>
}// LITERALS
<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */
{
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|"-")* >
|
< #LETTER:
[
"\u0024",
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
"\u00c0"-"\u00d6",
"\u00d8"-"\u00f6",
"\u00f8"-"\u00ff",
"\u0100"-"\u1fff",
"\u3040"-"\u318f",
"\u3300"-"\u337f",
"\u3400"-"\u3d2d",
"\u4e00"-"\u9fff",
"\uf900"-"\ufaff"
]
>
|
< #DIGIT:
[
"\u0030"-"\u0039",
"\u0660"-"\u0669",
"\u06f0"-"\u06f9",
"\u0966"-"\u096f",
"\u09e6"-"\u09ef",
"\u0a66"-"\u0a6f",
"\u0ae6"-"\u0aef",
"\u0b66"-"\u0b6f",
"\u0be7"-"\u0bef",
"\u0c66"-"\u0c6f",
"\u0ce6"-"\u0cef",
"\u0d66"-"\u0d6f",
"\u0e50"-"\u0e59",
"\u0ed0"-"\u0ed9",
"\u1040"-"\u1049"
]
>
}// IDENTIFIERS
<DEFAULT,BOUNDS> TOKEN : /* SEPARATORS */
{
< LBRACE : "{" >
| < RBRACE : "}" >
| < LBRACKET : "[" >
| < RBRACKET : "]" >
| < SEMICOLON : ";" >
}// SEPARATORS
<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */
{
< ASSIGN : "=" >
}// OPERATORS
Start Start() #Start : {}
{
(Device())*
{ return jjtThis; }
}
void Displace() : {}
{
<DISPLACE> ">"(Property())* (Skill())* MainFunction() #Displace(0)
}
void Turn() : {}
{
<TURN> ">"(Property())* (Skill())* MainFunction() #Turn(0)
}
void Move() : {}
{
<MOVE> ">"(Property())* (Skill())* MainFunction() #Move(0)
}
void MagnetGripper() : {}
{
<MAGNETGRIPPER> ">"(Property())* (Skill())* MainFunction() #MagnetGripper(0)
}
void Orient() : {}
{
<ORIENT> ">"(Property())* (Skill())* MainFunction() #Orient(0)
}
void ParallelGripper() : {}
{
<PARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #ParallelGripper(0)
}
void Arrange() : {}
{
<ARRANGE> ">"(Property())* (Skill())* MainFunction() #Arrange(0)
}
void Feed() : {}
{
<FEED> ">"(Property())* (Skill())* MainFunction() #Feed(0)
}
void Gripper() : {}
{
<GRIPPER> ">"(Property())* (Skill())* MainFunction() #Gripper(0)
}
void StorePartlyOrdered() : {}
{
<STOREPARTLYORDERED> ">"(Property())* (Skill())* MainFunction() #StorePartlyOrdered(0)
}
void ManipulationAndHandlingFunction() : {}
{
<MANIPULATIONANDHANDLINGFUNCTION> ">"(Property())* (Skill())* MainFunction() #ManipulationAndHandlingFunction(0)
}
void Manufacturing() : {}
{
<MANUFACTURING> ">"(Property())* (Skill())* MainFunction() #Manufacturing(0)
}
void Store() : {}
{
<STORE> ">"(Property())* (Skill())* MainFunction() #Store(0)
}
void Task() : {}
{
<TASK> ">"(Property())* (Skill())* MainFunction() #Task(0)
}
void MainFunction() : {}
{
<MAINFUNCTION> ">"(Property())* (Skill())* MainFunction() #MainFunction(0)
}
void JointFingerGripper() : {}
{
<JOINTFINGERGRIPPER> ">"(Property())* (Skill())* MainFunction() #JointFingerGripper(0)
}
void LineParallelGripper() : {}
{
<LINEPARALLELGRIPPER> ">"(Property())* (Skill())* MainFunction() #LineParallelGripper(0)
}
void Pass() : {}
{
<PASS> ">"(Property())* (Skill())* MainFunction() #Pass(0)
}
void Pan() : {}
{
<PAN> ">"(Property())* (Skill())* MainFunction() #Pan(0)
}
void PincerGripper() : {}
{
<PINCERGRIPPER> ">"(Property())* (Skill())* MainFunction() #PincerGripper(0)
}
void ID() : {}
{
<ID> ">"(Property())* (Skill())* MainFunction() #ID(0)
}
void CircularParallelGripper() : {}
{