-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvaluatorMain.hs
25 lines (23 loc) · 888 Bytes
/
EvaluatorMain.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Prelude hiding (lex)
import System.Environment
import Control.Monad.State
import Parser
import Lexer
import Evaluator
import AST
-- Author: Aleksander Balicki
-- | This is a binary for running the evaluation, run by cat machinefile | ./smeval STARTINGSTATE, it randomizes the environment
main :: IO ()
main = do
cont <- getContents
let (ast, state) = runState (parse . lex $ cont) tagStart
args <- getArgs
case args of
(_:_:_) -> error "too many args supplied, use one Integer to set the machine state and pipe the machine to stdin"
[] -> error "no args supplied, use one Integer to set the machine state and pipe the machine to stdin"
[n] -> do
renv <- randomEnv ast
putStrLn $ "env: " ++ show renv
let (t, c) = runMachine (read n) ast renv
print t
putStrLn $ "cost " ++ show c