-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymTable.hs
72 lines (56 loc) · 2.5 KB
/
SymTable.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
{-
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
-}
module SymTable where
import AST
import Lexer
import Control.Monad.State
import Control.Monad.Trans
import qualified Data.Map as Hash
type Pos = (Int,Int)
-- Data type to save the elements of the world, walls or objects
type WorldDesc = Hash.Map Pos WorldElements
-- Data type to save the objects in a cell, because you can have more than
-- one type of object
type ObjectsInCell = Hash.Map String Int
-- Data type to represent the elements of the world, can be a wall or objects
data WorldElements = Wall | Objects{ map :: ObjectsInCell} deriving(Show)
-- Data type to represent the final goal of the world
data FinalGoal = None | FinalG{ goal :: FINALGOAL } deriving(Show)
-- Data type to represent the values that the table can contain
data SymValue = World{ startPos :: Pos , id :: String
, defBlock :: Int , numBlock :: Int
, desc :: WorldDesc , willyIsAt :: Pos
, basketSize :: Int , objectsInB :: [String]
, size :: Pos , willyDirection :: String
, finalG :: FinalGoal
}
| ObjectType{ startPos :: Pos , id :: String
, defBlock :: Int , color :: String
}
| WBoolean{startPos :: Pos , id :: String
, defBlock :: Int , value :: Bool
}
| Goal{ startPos :: Pos , id :: String
, defBlock :: Int , test :: GOALTEST
}
| Instruction{ startPos :: Pos , id :: String
, defBlock :: Int , numBlock :: Int , inst :: TASKINSTR
}
| Task{ startPos :: Pos , id :: String
, defBlock :: Int , numBlock :: Int, onWorld :: String
}
deriving(Show)
-- Data type of the table, a hash from String to a list of SymValues
type SymTable = Hash.Map String [SymValue]
-- Data type to create the symbols table, using a LeBlanc-Cook implementation
data MySymState = MySymState{ symTable :: SymTable , stack :: [Int] , error :: [String]
, nBlock :: Int }
type MyStateM a = StateT MySymState IO a
-- para hacer cosas de IO en StateT
io :: IO a -> MyStateM a
io = liftIO