Read expressions from file

main checkpoint-1
Ethan Reece 2023-09-08 01:31:07 -05:00
parent af50529dc1
commit 3388e3f97e
Signed by: me
GPG Key ID: D3993665FF92E1C3
1 changed files with 8 additions and 7 deletions

View File

@ -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