diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java index dcdba9f..047f906 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java @@ -1,5 +1,7 @@ package models.algebra; +import java.util.List; + public class Symbol { protected String name; protected String implName; @@ -10,6 +12,7 @@ protected models.algebra.Type[] signature = null; protected int[] implParamOrder = null; protected IImplGenerator generator = null; + protected ICalculator calculator = null; public Symbol(String name) { this.name = name; @@ -66,6 +69,37 @@ } } + public Symbol(String name, int arity, ICalculator calculator) { + this.name = name; + this.arity = arity; + this.calculator = calculator; + } + + public Symbol(String name, int arity, Type operatorType, ICalculator calculator) { + this.name = name; + this.arity = arity; + this.operatorType = operatorType; + this.calculator = calculator; + } + + public Symbol(String name, int arity, Type operatorType, IImplGenerator generator, ICalculator calculator) { + this.name = name; + this.arity = arity; + this.operatorType = operatorType; + this.generator = generator; + this.implOperatorType = Type.GENERATIVE; + this.calculator = calculator; + } + + public Symbol(String name, int arity, Type operatorType, String implName, Type implOperatorType, ICalculator calculator) { + this.name = name; + this.implName = implName; + this.arity = arity; + this.operatorType = operatorType; + this.implOperatorType = implOperatorType; + this.calculator = calculator; + } + public void setArity(int arity) { this.arity = arity; } @@ -171,6 +205,17 @@ } return null; } + + public boolean isCalculatable() { + return (calculator != null); + } + + public Constant calculate(List args) { + if (calculator != null) { + return calculator.calculate(args); + } + return null; + } public boolean equals(Object another) { if (!(another instanceof Symbol)) return false; @@ -232,4 +277,8 @@ */ public String generate(models.algebra.Type type, models.algebra.Type[] childrenTypes, String children[], String[] childrenSideEffects, String[] sideEffect); } + + public interface ICalculator { + public Constant calculate(List args); + } }