diff --git a/ast.hs b/ast.hs index 1f4bfac..7476849 100644 --- a/ast.hs +++ b/ast.hs @@ -17,6 +17,7 @@ data AST = Add AST AST | Call String AST | UnitConst | Cons AST AST + | IfExpr AST AST AST | TupleConst [AST] | ListConst [AST] | StrConst String diff --git a/parser.hs b/parser.hs index 9866915..d2613f1 100644 --- a/parser.hs +++ b/parser.hs @@ -128,6 +128,15 @@ consExpr = do y <- exprparser return $ Cons x y +ifExpr = do + symbol "if" + cond <- exprparser + symbol "then" + t <- exprparser + symbol "else" + e <- exprparser + return $ IfExpr cond t e + expr' = try block <|> try funDef <|> try call @@ -135,6 +144,7 @@ expr' = try block <|> try (tupleSeq exprparser TupleConst) <|> parens exprparser <|> listSeq exprparser ListConst + <|> try ifExpr <|> fmap Var identifier <|> fmap StrConst stringLiteral <|> fmap IntConst integer