diff --git a/AlgebraicDataflowArchitectureModel/models/Game.model b/AlgebraicDataflowArchitectureModel/models/Game.model index 4ad4a36..bc6ae7b 100644 --- a/AlgebraicDataflowArchitectureModel/models/Game.model +++ b/AlgebraicDataflowArchitectureModel/models/Game.model @@ -1,19 +1,19 @@ channel CIO { - out force(f:Double, action(x)) == x + out force(f:Double, action(x:Double)) == x out time(t:Double, action(x)) == t + 0.01 out force(f, e) == x out time(t, e) == t + 0.01 } channel CIO2 { - out velocity(v:Double, setVel(x)) == x + out velocity(v:Double, setVel(x:Double)) == x out velocity(v, e) == x } channel C1 { in force(f, update1(y, m)) == y in mass(m:Double, update1(y, m)) == m - out acceleration(a:Double, update1(y, m)) == y / m + out acceleration(a: Double, update1(y, m)) == y / m } channel C2 { diff --git a/AlgebraicDataflowArchitectureModel/models/POS.model b/AlgebraicDataflowArchitectureModel/models/POS.model index eabfc49..4e61b45 100644 --- a/AlgebraicDataflowArchitectureModel/models/POS.model +++ b/AlgebraicDataflowArchitectureModel/models/POS.model @@ -1,5 +1,5 @@ channel CIO { - out payment(p:Int, purchase(x)) == x + out payment(p:Int, purchase(x:Int)) == x } channel C1 { diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java index b6e3ebb..e5bf77d 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java @@ -42,6 +42,10 @@ return children.get(n); } + public ArrayList getChildren() { + return children; + } + public HashMap getSubTerms(Class clazz) { HashMap subTerms = new HashMap<>(); if (clazz == this.getClass()) { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index e8b641e..c718d72 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -18,7 +18,7 @@ public static final Type typeInt = new Type("Int", "int"); public static final Type typeFloat = new Type("Float", "float"); public static final Type typeDouble = new Type("Double", "double"); - public static final Type typeList = new Type("List", "List"); + public static final Type typeList = new Type("List", "ArrayList"); public static final Type typeBoolean = new Type("Bool", "boolean"); public static final Symbol add = new Symbol(Parser.ADD, 2, Symbol.Type.INFIX); public static final Symbol mul = new Symbol(Parser.MUL, 2, Symbol.Type.INFIX);; @@ -38,6 +38,7 @@ div.setInverses(new Symbol[] {mul}); minus.setInverses(new Symbol[] {minus}); cons.setInverses(new Symbol[] {head, body}); + cons.setSignature(new Type[] {typeList, null, typeList}); } public DataConstraintModel() { diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index eb41993..d8307eb 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -137,12 +137,27 @@ stateTransition.setMessageExpression(((Term) leftTerm).getChild(1)); stateTransition.setNextStateExpression(rightTerm); channelMember.setStateTransition(stateTransition); + // for type definition if (identifier.getResourceStateType() == null && ((Term) leftTerm).getChild(0) instanceof Variable) { Variable stateVar = (Variable) ((Term) leftTerm).getChild(0); if (stateVar.getType() != null) { identifier.setResourceStateType(stateVar.getType()); } } + if (((Term) leftTerm).getChild(1) instanceof Term) { + Term messageTerm = (Term) ((Term) leftTerm).getChild(1); + if (messageTerm.getSymbol().getSignature() == null && messageTerm.getChildren().size() > 0) { + Type[] signature = new Type[messageTerm.getChildren().size() + 1]; + int i = 1; + for (Expression e: messageTerm.getChildren()) { + if (e instanceof Variable && ((Variable) e).getType() != null) { + signature[i] = ((Variable) e).getType(); + } + i++; + } + messageTerm.getSymbol().setSignature(signature); + } + } return channelMember; } @@ -168,6 +183,7 @@ } Expression exp = null; if (stream.checkNext() != null && stream.checkNext().equals(LEFT_BRACKET)) { + // a function symbol Symbol symbol = model.getSymbol(symbolName); if (symbol == null) { symbol = new Symbol(symbolName); @@ -192,13 +208,15 @@ Double d = Double.parseDouble(symbolName); exp = new Constant(symbolName); } catch (NumberFormatException e) { - if (symbolName.contains(COLON)) { - String variable[] = symbolName.split(COLON); - Type type = model.getType(variable[1]); + if (stream.checkNext() != null && stream.checkNext().equals(COLON)) { + // when a type is specified. + stream.next(); + String typeName = stream.next(); + Type type = model.getType(typeName); if (type == null) { - type = new Type(variable[1], variable[1]); + type = new Type(typeName, typeName); } - exp = new Variable(variable[0], type); + exp = new Variable(symbolName, type); } else { exp = new Variable(symbolName); } @@ -288,17 +306,20 @@ splitBy( splitBy( splitBy( - Arrays.asList(line.split("[ \t]")), - ADD, - ADD_REGX), - MUL, - MUL_REGX), - SUB, - SUB_REGX), - DIV, - DIV_REGX), - COMMA, - COMMA), + splitBy( + Arrays.asList(line.split("[ \t]")), + ADD, + ADD_REGX), + MUL, + MUL_REGX), + SUB, + SUB_REGX), + DIV, + DIV_REGX), + COMMA, + COMMA), + COLON, + COLON), LEFT_BRACKET, LEFT_BRACKET_REGX), RIGHT_BRACKET,