diff --git a/src/main/java/edu/kit/typicalc/model/Model.java b/src/main/java/edu/kit/typicalc/model/Model.java new file mode 100644 index 0000000..4f35f16 --- /dev/null +++ b/src/main/java/edu/kit/typicalc/model/Model.java @@ -0,0 +1,21 @@ +package edu.kit.typicalc.model; + +import java.util.Map; + +import edu.kit.typicalc.model.parser.ParseError; +import edu.kit.typicalc.util.Result; + +/** + * This interface accepts user input and returns a type inference result. + */ +public interface Model { + /** + * Given the user input, an implementation of this method should compute the type + * inference results. + * @param lambdaTerm the lambda term to type-infer + * @param typeAssumptions the type assumptions to use + * @return either an error or a TypeInfererInterface on success + */ + Result getTypeInferer(String lambdaTerm, + Map typeAssumptions); +} diff --git a/src/main/java/edu/kit/typicalc/model/ModelImpl.java b/src/main/java/edu/kit/typicalc/model/ModelImpl.java new file mode 100644 index 0000000..5c74773 --- /dev/null +++ b/src/main/java/edu/kit/typicalc/model/ModelImpl.java @@ -0,0 +1,39 @@ +package edu.kit.typicalc.model; + +import edu.kit.typicalc.model.parser.LambdaParser; +import edu.kit.typicalc.model.parser.ParseError; +import edu.kit.typicalc.model.term.LambdaTerm; +import edu.kit.typicalc.util.Result; + +import java.util.Map; + +/** + * Accepts user input and returns a type inference result. + */ +public class ModelImpl implements Model { + + /** + *Parses the user input given as the lambdaTerm and typeAssumptions and creates + * a TypeInferer object. + * @param lambdaTerm the lambda term to type-infer + * @param typeAssumptions the type assumptions to use + * @return A TypeInferer object that has calculated the type Inference for the given Lambda Term + * and type Assumptions + * + */ + @Override + public Result getTypeInferer(String lambdaTerm, + Map typeAssumptions) { + // Parse Lambda Term + LambdaParser parser = new LambdaParser(lambdaTerm); + Result result = parser.parse(); + if (result.isError()) { + return new Result<>(null, result.unwrapError()); + } + //TODO: Parse Type Assumptions and add list to typeInferer + + //Create and return TypeInferer + TypeInferer typeInferer = new TypeInferer(result.unwrap(), null); + return new Result<>(typeInferer, null); + } +}