diff --git a/src/Evaluator.hs b/src/Evaluator.hs index 2f34498..d5d50b7 100644 --- a/src/Evaluator.hs +++ b/src/Evaluator.hs @@ -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 diff --git a/src/ExprType.hs b/src/ExprType.hs index c8418af..f4aaa21 100644 --- a/src/ExprType.hs +++ b/src/ExprType.hs @@ -2,7 +2,6 @@ module ExprType where data Expr = IntE Integer | VarE String - | ProcedureE String [Expr] | SetE String Expr | ConsE Expr Expr | QuotedE Expr diff --git a/src/Parser.hs b/src/Parser.hs index 1a36f93..9e86403 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -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