@@ -6,12 +6,12 @@ module Main (main) where
66import System.Environment (getArgs )
77
88import WhileParser (tokenize , readFileContent , runASTParser ) -- WhileAST(..),
9- import WhileEvaluation (eval , evalT , evalM , getVST , runEvalM )
10- -- , evalM, VarName, VarVal, VarState, VarStateWorld)
9+ import WhileEvaluation (eval , evalT , evalM , getVarState , runEvalM )
10+ -- VarName, VarVal, VarState, VarStateWorld)
1111
1212
1313-- | Define a data type to represent the command-line options
14- newtype Options = Options { getFileName :: FilePath }
14+ newtype Options = Options { getFileName :: FilePath } deriving Show
1515
1616
1717-- | Parse command-line arguments manually
@@ -26,31 +26,21 @@ runInterpreter options = do
2626
2727 putStrLn $ " \ESC [92m[Interpreting file]\ESC [0m " ++ getFileName options
2828
29- -- Read the content of the specified file
30- whileLines <- readFileContent $ getFileName options
31- let tokens = tokenize whileLines
32-
33- putStrLn " \ESC [92m[DONE TOKENIZE]\ESC [0m"
34- -- print tokens
35-
36- let ast = runASTParser tokens
37- putStrLn " \ESC [92m[DONE PARSING AST]\ESC [0m"
38- -- print ast
39-
40- putStrLn " \ESC [92m[RESULT OF EVALUATION]\ESC [0m"
29+ -- ast tokens lines of code file name
30+ ast <- runASTParser . tokenize <$> (readFileContent . getFileName) options
4131
4232 -- print $ eval ast [] -- eval v1
4333 -- print $ evalT ast [] -- eval v2
4434
4535 let program = evalM ast -- Monad eval
46- print $ getVST program []
36+ print $ getVarState program []
4737
4838 -- eg.
49- -- let program2 = evalM ast >> evalM ast
50- -- print $ getVST program2 []
39+ -- let program2 = evalM ast_1 >> evalM ast_2 >> ...
40+ -- print $ getVarState program2 []
5141
5242 -- or use:
53- -- print $ runEvalM ast []
43+ -- print $ runEvalM ast []
5444
5545 putStrLn $ " \n " ++ concat (replicate 40 " = " ) ++ " =\n "
5646
0 commit comments