parent
af50529dc1
commit
3388e3f97e
13
app/Main.hs
13
app/Main.hs
|
@ -1,21 +1,22 @@
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
import Data.Either
|
import Data.Either
|
||||||
import Eval.Expression
|
import Eval.Expression
|
||||||
import Objects.Expression
|
import Objects.Expression
|
||||||
import Parser.Expression
|
import Parser.Expression
|
||||||
import System.Environment
|
import System.Environment
|
||||||
|
import System.IO
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
|
|
||||||
parseResult :: ParseResult
|
|
||||||
parseResult = parseExpr "2+3*4"
|
|
||||||
|
|
||||||
getRight :: ParseResult -> Expr
|
getRight :: ParseResult -> Expr
|
||||||
getRight (Right r) = r
|
getRight (Right r) = r
|
||||||
|
|
||||||
expr = getRight parseResult
|
getResult :: String -> Int
|
||||||
|
getResult str = evalExpr (getRight (parseExpr str))
|
||||||
result = evalExpr expr
|
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
|
fileName <- fmap head getArgs
|
||||||
|
contents <- readFile fileName
|
||||||
|
let result = getResult contents
|
||||||
print result
|
print result
|
Reference in New Issue