Compare commits

..

No commits in common. "c15a736236b76a8fc58a223bf50c61fb682ae0c6" and "7218e4b4fb8949bf9218d0cc9127bd5097688460" have entirely different histories.

6 changed files with 16 additions and 14 deletions

View File

@ -19,11 +19,12 @@ executable cherry
default-language: Haskell2010 default-language: Haskell2010
other-modules: ExprType, other-modules: ExprType,
Parser, ExprParser,
TokenType, TokenType,
Lexer, TokenParser,
Evaluator, Evaluator,
ParserUtils ParserUtils,
TokenParser
build-depends: base >= 4.7 && < 5, build-depends: base >= 4.7 && < 5,
containers, containers,

View File

@ -4,9 +4,11 @@ import qualified Data.Map as M
import ExprType import ExprType
type Env = M.Map String Expr type Env = M.Map String Expr
type Proc = String
-- TODO: create a separated file for builtinProcs -- TODO: create a separated file for builtinProcs
-- TODO: create a BuiltinProc or something like that in data Expr, and make + a builtin proc -- TODO: create a BuiltinProc or something like that in data Expr, and make + a builtin proc
-- TODO: create enviroments
base :: Env base :: Env
base = M.fromList [ base = M.fromList [
@ -15,8 +17,7 @@ base = M.fromList [
eval :: Env -> Expr -> (Env, Expr) eval :: Env -> Expr -> (Env, Expr)
eval env (IntE x) = (env, IntE x) eval env (IntE x) = (env, IntE x)
eval env (VarE v) = (M.insert v nExpr nEnv, nExpr) eval env (VarE v) = (env, env M.! v)
where (nEnv, nExpr) = eval env $ env M.! v
eval env (SetE v expr) = (M.insert v expr env, NilE) eval env (SetE v expr) = (M.insert v expr env, NilE)
eval env NilE = (env, NilE) eval env NilE = (env, NilE)

View File

@ -1,8 +1,8 @@
module Parser where module ExprParser where
import Text.Parsec import Text.Parsec
import Text.Parsec.String import Text.Parsec.String
import Lexer import TokenParser
import TokenType import TokenType
import ExprType import ExprType

View File

@ -4,9 +4,9 @@ data Expr = IntE Integer
| VarE String | VarE String
| ProcedureE String [Expr] | ProcedureE String [Expr]
| SetE String Expr | SetE String Expr
| NilE deriving (Show) | NilE
-- instance Show Expr where instance Show Expr where
-- show (IntE x) = show x show (IntE x) = show x
-- show (VarE x) = x ++ " ; var" show (VarE x) = x ++ " ; var"
-- show NilE = "nil" show NilE = "nil"

View File

@ -1,7 +1,7 @@
module Main where module Main where
import Evaluator import Evaluator
import Parser import ExprParser
import Control.Monad import Control.Monad
import Data.Maybe import Data.Maybe
import System.Console.Haskeline import System.Console.Haskeline

View File

@ -1,4 +1,4 @@
module Lexer where module TokenParser where
import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec
import ParserUtils import ParserUtils