Now procedure applications are represented as lists

This commit is contained in:
Ivy 2021-01-30 17:15:26 +01:00
parent e96cddff9b
commit 16e6cd8419
3 changed files with 14 additions and 14 deletions

View File

@ -14,13 +14,13 @@ base = M.fromList [
]
eval :: Env -> Expr -> (Env, Expr)
eval env i@(IntE x) = (env, i)
eval env i@(IntE _) = (env, i)
eval env (VarE v) = (M.insert v nExpr nEnv, nExpr)
where (nEnv, nExpr) = eval env $ env M.! v
eval env (SetE v expr) = (M.insert v expr env, NilE)
eval env (QuotedE e) = (env, e)
eval env c@(ConsE _ _) = (env, c)
eval env (ConsE car cdr) = (env, apply car cdr)
eval env NilE = (env, NilE)
--apply :: Proc -> Args -> Expr
--apply p args
apply :: Expr -> Expr -> Expr
apply car cdr = undefined

View File

@ -2,7 +2,6 @@ module ExprType where
data Expr = IntE Integer
| VarE String
| ProcedureE String [Expr]
| SetE String Expr
| ConsE Expr Expr
| QuotedE Expr

View File

@ -20,9 +20,18 @@ expressionFromTokensEOF = do
expressionFromTokens :: GenParser Token st Expr
expressionFromTokens = do
expr <- intE <|> quotedE <|> try setE <|> try nilE <|> try consE <|> varE <|> procedureE
expr <- intE <|> quotedE <|> try setE <|> try nilE <|> try consE <|> varE <|> listE
return expr
listE :: GenParser Token st Expr
listE = do
_ <- parseLeftParenT
exprs <- many expressionFromTokens
_ <- parseRightParenT
return $ toCons exprs
where toCons [] = NilE
toCons (x:xs) = ConsE x (toCons xs)
intE :: GenParser Token st Expr
intE = do
(IntT num) <- parseIntT
@ -34,14 +43,6 @@ quotedE = do
expr <- expressionFromTokens
return $ QuotedE expr
procedureE :: GenParser Token st Expr
procedureE = do
_ <- parseLeftParenT
(SymbolT p) <- parseSymbolT
args <- many expressionFromTokens
_ <- parseRightParenT
return $ ProcedureE p args
consE :: GenParser Token st Expr
consE = do
_ <- parseLeftParenT