-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWilly.hs
87 lines (76 loc) · 2.81 KB
/
Willy.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{-
An Interpreter for the subject "Traductores e Interpretadores" (Translators and Interpreters)
of the Simon Bolivar University (USB).
Authors:
Neil Villamizar 15-11523
Jesus Wahrman 15-11540
-}
import System.IO
import System.Directory
import System.Environment
import Lexer
import Parser
import AST
import PrintParser
import PrintSymTable
import Control.Monad.State
import SymTable
import ContextChecker
import RunTask
import Text.Read
import qualified Data.Map as Hash
--Main function
main = do
args <- getArgs
case args of
[] -> do putStr ( "Archivo a Interpretar: " )
hFlush stdout
filePath <- getLine
putStr ( "Tarea a ejecutar (modo automatico): " )
hFlush stdout
taskName <- getLine
if (length $ words filePath) > 1 || (length $ words taskName) > 1
then do wrongFormatInput
else processFile filePath taskName "a"
[filePath, taskName, mode] -> do
if( mode == "-a" || mode == "--auto" )
then processFile filePath taskName "a"
else if ( mode == "-m" || mode == "--manual")
then processFile filePath taskName "m"
else wrongFormatInput
[filePath, taskName, mode, sec] -> do
if( mode /= "-a" && mode /= "--auto" ) then wrongFormatInput
else do
case (readMaybe sec :: Maybe Int) of
(Just x) -> processFile filePath taskName sec
otherwise -> wrongFormatInput
_ -> wrongFormatInput
-- Check if file exist and if so then run the project with that file
processFile :: FilePath -> String -> String-> IO ()
processFile filePath taskName mode = do
fileExists <- doesFileExist filePath
if fileExists then do
str <- readFile filePath
runProject str taskName mode
return ()
else do
putStrLn ( "Imposible abrir el archivo " ++ show filePath )
-- IO action that output a message of error in case of wrong format in the input
wrongFormatInput :: IO ()
wrongFormatInput = do
putStrLn ( "Formato incorrecto." )
putStrLn ( "Formato correcto 1: \nwilly <archivo> <tarea> -m | --manual" )
putStrLn ( "Formato correcto 2: \nwilly <archivo> <tarea> -a | --auto [<segundos>]" )
putStrLn ( "Formato correcto 3: \nwilly\nArchivo a Interpretar: <archivo>" )
putStrLn ( "Tarea a ejecutar (modo automatico): <tarea>")
-- Pass the string that represents the program to interpret to the scanner
-- and show the resuts
runProject :: String -> String -> String -> IO ()
runProject str taskName mode =
case scanner str of
Left s -> putStr s
Right toks -> do
let tk = reverse $ parse toks
let initTableState = MySymState Hash.empty [0] [] 0
runStateT (runTask taskName tk mode) initTableState
return()