Moved Enviroment and Expr types to a separate module

This commit is contained in:
Ivy 2021-02-03 20:52:01 +01:00
parent d74730afde
commit d786923335
5 changed files with 13 additions and 11 deletions

View File

@ -18,12 +18,12 @@ executable cherry
main-is: Main.hs main-is: Main.hs
default-language: Haskell2010 default-language: Haskell2010
other-modules: Expression, other-modules: Parser,
Parser,
Token, Token,
Lexer, Lexer,
Evaluator, Evaluator,
Enviroment Enviroment,
Types.Language
build-depends: base >= 4.7 && < 5, build-depends: base >= 4.7 && < 5,
containers, containers,

View File

@ -1,11 +1,9 @@
module Enviroment where module Enviroment where
import qualified Data.Map as M import qualified Data.Map as M
import Expression import Types.Language
import Data.Maybe import Data.Maybe
data Enviroment = Enviroment (M.Map String Expr) (Maybe Enviroment)
-- The base enviroment, that contains the main functions and variables -- The base enviroment, that contains the main functions and variables
base :: Enviroment base :: Enviroment
base = Enviroment (M.fromList [ base = Enviroment (M.fromList [

View File

@ -1,6 +1,6 @@
module Evaluator where module Evaluator where
import Expression import Types.Language
import Enviroment import Enviroment
import Data.Maybe import Data.Maybe
import Control.Monad.State import Control.Monad.State

View File

@ -4,7 +4,7 @@ import Text.Parsec hiding (tokens)
import Text.Parsec.String import Text.Parsec.String
import Lexer (tokens) import Lexer (tokens)
import Token import Token
import Expression import Types.Language
parseExpression :: String -> Either ParseError Expr parseExpression :: String -> Either ParseError Expr
parseExpression s = do parseExpression s = do

View File

@ -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 data Expr = IntE Integer
| VarE String | VarE String
@ -8,8 +12,6 @@ data Expr = IntE Integer
| QuotedE Expr | QuotedE Expr
| NilE | NilE
-- TODO: Make set! and lambda(?) parsed as cons, detect later set! and lambda as special procedures
instance Show Expr where instance Show Expr where
show (IntE x) = show x show (IntE x) = show x
show (VarE x) = x show (VarE x) = x
@ -20,3 +22,5 @@ instance Show Expr where
show (LambdaE s e) = "#[lambda " ++ s ++ " " ++ show e ++ "]" show (LambdaE s e) = "#[lambda " ++ s ++ " " ++ show e ++ "]"
show (QuotedE e) = show e show (QuotedE e) = show e
show NilE = "nil" show NilE = "nil"
-- TODO: Make set! and lambda(?) parsed as cons, detect later set! and lambda as special procedures