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
|
module Symboltab where
import Data.FiniteMap
data Symboltable a b = ST ((FM String a),(FM String b))
(Maybe (Symboltable a b))
emptyTable :: Symboltable _ _
emptyTable = ST ((emptyFM (<)),(emptyFM (<))) Nothing
lookupFirstTable :: String -> Symboltable a b -> Maybe a
lookupFirstTable k (ST (m,_) Nothing ) = lookupFM m k
lookupFirstTable k (ST (m,_) (Just s)) = case lookupFM m k of
Just v -> Just v
Nothing -> lookupFirstTable k s
lookupCurrentScope :: String -> Symboltable a b -> Maybe a
lookupCurrentScope k (ST (m,_) _) = lookupFM m k
lookupSecondTable :: String -> Symboltable a b -> Maybe b
lookupSecondTable k (ST (_,n) _ ) = lookupFM n k
insertFirstTable :: String -> a -> Symboltable a b -> Symboltable a b
insertFirstTable k v (ST (m,n) ms) = ST ((addToFM m k v),n) ms
insertDefFirstTab :: String ->
a ->
(a -> a -> a) ->
Symboltable a b ->
Symboltable a b
insertDefFirstTab k v c (ST (m,n) ms) = ST ((addToFM_C c m k v),n) ms
insertSecondTable :: String -> b -> Symboltable a b -> Symboltable a b
insertSecondTable k v (ST (m,n) ms) = ST (m,(addToFM n k v)) ms
enterScope :: Symboltable a b -> Symboltable a b
enterScope s@(ST (_,n) _ ) = ST ((emptyFM (<)),n) (Just s)
exitScope :: Symboltable a b -> Symboltable a b
exitScope s@(ST _ Nothing ) = s
exitScope (ST _ (Just s)) = s
combineST :: Symboltable k v -> Symboltable k v -> Symboltable k v
combineST (ST (m1,n1) ms) (ST (m2,n2) _) =
ST ((plusFM m1 m2), (plusFM n1 n2)) ms
|