diff --git a/resources/testAll.rosetta b/resources/testAll.rosetta index 8966a13..78c563a 100644 --- a/resources/testAll.rosetta +++ b/resources/testAll.rosetta @@ -36,8 +36,8 @@ func EquityPriceObservation: <"Function specification for the observation of an func Something: <"asd"> inputs: equity1 boolean (1..1) - something1 boolean (1..1) + determinationMethod ObservationPrimitive (1..1) output: - valuation ObservationPrimitive (1..1) + valuation ObservationPrimitive (0..1) - assign-output: if True and False then determinationMethod else determinationMethod \ No newline at end of file + assign-output: if True and False then determinationMethod \ No newline at end of file diff --git a/src/Semantic/ExpressionChecker.hs b/src/Semantic/ExpressionChecker.hs index 4b222d7..f2f65fd 100644 --- a/src/Semantic/ExpressionChecker.hs +++ b/src/Semantic/ExpressionChecker.hs @@ -59,13 +59,12 @@ defaultMap = [ -- |Checks whether a function is valid (inputs, outputs are of valid type and all variables are defined) and adds it to the symbol table addFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] [Symbol] addFunction (definedTypes, definedSymbols) (MakeFunction name _ inps out _) - | null (lefts checkedInputs) && isRight checkedOutput = Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : allSymbols + | null (lefts checkedInputs) && isRight checkedOutput = Right $ Func name (map typeAndCardinality (rights checkedInputs)) (attributeType $ fromRightUnsafe checkedOutput, Model.Type.cardinality out) : definedSymbols | isLeft checkedOutput = Left [fromLeftUnsafe checkedOutput] | otherwise = Left $ lefts checkedInputs where checkedInputs = checkAttributes definedTypes inps checkedOutput = head $ checkAttributes definedTypes [out] - allSymbols = addVariables definedSymbols inps -- |Adds a newly defined variable to the symbol table addVariables :: [Symbol] -> [TypeAttribute] -> [Symbol] diff --git a/src/Semantic/FunctionChecker.hs b/src/Semantic/FunctionChecker.hs index 4830cc4..0eb2adc 100644 --- a/src/Semantic/FunctionChecker.hs +++ b/src/Semantic/FunctionChecker.hs @@ -9,13 +9,14 @@ import Data.Char -- |Checks if all the inputs and the out of a function call have valid types, and then checks that the assign-output expression is valid checkFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] Function -checkFunction (definedTypes, definedFunctions) (MakeFunction name desc inp out ex) +checkFunction (definedTypes, symbols) (MakeFunction name desc inp out ex) | isRight checkedEx && isRight checkedOut && null (lefts checkedIn) = case typeMatch (attributeType $ fromRightUnsafe checkedOut, Model.Type.cardinality out) (fromRightUnsafe checkedEx) of Right _ -> Right $ MakeFunction (toLower (head name) : tail name) desc (rights checkedIn) (fromRightUnsafe checkedOut) ex Left err -> Left [err] | otherwise = Left $ lefts [checkedOut] ++ lefts checkedIn ++ lefts [checkedEx] where - checkedEx = checkExpression definedFunctions ex + localEnv = addVariables symbols inp + checkedEx = checkExpression localEnv ex checkedIn = checkAttributes definedTypes inp checkedOut = head $ checkAttributes definedTypes [out] \ No newline at end of file