Moved Enviroment and Expr types to a separate module
This commit is contained in:
parent
d74730afde
commit
d786923335
|
@ -18,12 +18,12 @@ executable cherry
|
|||
main-is: Main.hs
|
||||
default-language: Haskell2010
|
||||
|
||||
other-modules: Expression,
|
||||
Parser,
|
||||
other-modules: Parser,
|
||||
Token,
|
||||
Lexer,
|
||||
Evaluator,
|
||||
Enviroment
|
||||
Enviroment,
|
||||
Types.Language
|
||||
|
||||
build-depends: base >= 4.7 && < 5,
|
||||
containers,
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
module Enviroment where
|
||||
|
||||
import qualified Data.Map as M
|
||||
import Expression
|
||||
import Types.Language
|
||||
import Data.Maybe
|
||||
|
||||
data Enviroment = Enviroment (M.Map String Expr) (Maybe Enviroment)
|
||||
|
||||
-- The base enviroment, that contains the main functions and variables
|
||||
base :: Enviroment
|
||||
base = Enviroment (M.fromList [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Evaluator where
|
||||
|
||||
import Expression
|
||||
import Types.Language
|
||||
import Enviroment
|
||||
import Data.Maybe
|
||||
import Control.Monad.State
|
||||
|
|
|
@ -4,7 +4,7 @@ import Text.Parsec hiding (tokens)
|
|||
import Text.Parsec.String
|
||||
import Lexer (tokens)
|
||||
import Token
|
||||
import Expression
|
||||
import Types.Language
|
||||
|
||||
parseExpression :: String -> Either ParseError Expr
|
||||
parseExpression s = do
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
module Expression where
|
||||
module Types.Language where
|
||||
|
||||
import Data.Map (Map)
|
||||
|
||||
data Enviroment = Enviroment (Map String Expr) (Maybe Enviroment)
|
||||
|
||||
data Expr = IntE Integer
|
||||
| VarE String
|
||||
|
@ -8,8 +12,6 @@ data Expr = IntE Integer
|
|||
| QuotedE Expr
|
||||
| NilE
|
||||
|
||||
-- TODO: Make set! and lambda(?) parsed as cons, detect later set! and lambda as special procedures
|
||||
|
||||
instance Show Expr where
|
||||
show (IntE x) = show x
|
||||
show (VarE x) = x
|
||||
|
@ -20,3 +22,5 @@ instance Show Expr where
|
|||
show (LambdaE s e) = "#[lambda " ++ s ++ " " ++ show e ++ "]"
|
||||
show (QuotedE e) = show e
|
||||
show NilE = "nil"
|
||||
|
||||
-- TODO: Make set! and lambda(?) parsed as cons, detect later set! and lambda as special procedures
|
Loading…
Reference in New Issue