| | package models.algebra; |
---|
| | |
---|
| | import java.util.List; |
---|
| | |
---|
| | public class Symbol { |
---|
| | protected String name; |
---|
| | protected String implName; |
---|
| |
---|
| | protected Symbol[] inverses = null; |
---|
| | 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; |
---|
| | this.implName = name; |
---|
| |
---|
| | this.implOperatorType = Type.GENERATIVE_WITH_SIDE_EFFECT; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | 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; |
---|
| | } |
---|
| | |
---|
| |
---|
| | return generator.generate(type, childrenTypes, childrenImpl, childrenSideEffects, sideEffect); |
---|
| | } |
---|
| | return null; |
---|
| | } |
---|
| | |
---|
| | public boolean isCalculatable() { |
---|
| | return (calculator != null); |
---|
| | } |
---|
| | |
---|
| | public Constant calculate(List<Constant> args) { |
---|
| | if (calculator != null) { |
---|
| | return calculator.calculate(args); |
---|
| | } |
---|
| | return null; |
---|
| | } |
---|
| | |
---|
| | public boolean equals(Object another) { |
---|
| | if (!(another instanceof Symbol)) return false; |
---|
| | return name.equals(((Symbol) another).name) && arity == ((Symbol) another).arity; |
---|
| |
---|
| | * @return the generated implementation |
---|
| | */ |
---|
| | public String generate(models.algebra.Type type, models.algebra.Type[] childrenTypes, String children[], String[] childrenSideEffects, String[] sideEffect); |
---|
| | } |
---|
| | |
---|
| | public interface ICalculator { |
---|
| | public Constant calculate(List<Constant> args); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |