module Calculator.Evaluator.Base (evaluate, evalTest) where -------------------------------------------------------------------------------- import Calculator.Evaluator.Statement (evalStat) import Calculator.Parser.Statement (parseStat) import Calculator.Prim.Bindings (Bindings, mkBind) import Calculator.Prim.Result (Result (..)) -------------------------------------------------------------------------------- import Control.Applicative ((<*)) import Text.ParserCombinators.Parsec (eof, parse, spaces) -------------------------------------------------------------------------------- evaluate :: Bindings -> String -> Result evaluate b i = case parse (spaces >> parseStat <* spaces <* eof) "Statement" i of Left e -> Error . show $ e Right s -> evalStat b s -------------------------------------------------------------------------------- evalTest :: String -> String evalTest s = case evaluate (mkBind [] []) s of Value n -> show n _ -> "" --------------------------------------------------------------------------------