From 05c19789d5e1b5edd050ee97c19a8ab86ec9e0f6 Mon Sep 17 00:00:00 2001 From: ov-4 Date: Thu, 29 Jan 2026 11:13:05 +0000 Subject: Added half way of IF statement --- include/cps/AST.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'include/cps/AST.h') diff --git a/include/cps/AST.h b/include/cps/AST.h index 4d72040..7791580 100644 --- a/include/cps/AST.h +++ b/include/cps/AST.h @@ -61,12 +61,37 @@ public: }; class BinaryExprAST : public ExprAST { - char Op; // '+', '-', '*', '/' + int Op; std::unique_ptr LHS, RHS; public: - BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) + BinaryExprAST(int Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + int getOp() const { return Op; } + ExprAST *getLHS() const { return LHS.get(); } + ExprAST *getRHS() const { return RHS.get(); } +}; +class IfStmtAST : public StmtAST { + std::unique_ptr Cond; + std::vector> ThenStmts; + std::vector> ElseStmts; +public: + IfStmtAST(std::unique_ptr Cond, + std::vector> ThenStmts, + std::vector> ElseStmts) + : Cond(std::move(Cond)), ThenStmts(std::move(ThenStmts)), ElseStmts(std::move(ElseStmts)) {} + + ExprAST *getCond() const { return Cond.get(); } + const std::vector> &getThenStmts() const { return ThenStmts; } + const std::vector> &getElseStmts() const { return ElseStmts; } +}; + +class BinaryExprAST : public ExprAST { + char Op; + std::unique_ptr LHS, RHS; +public: + BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) + : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} char getOp() const { return Op; } ExprAST *getLHS() const { return LHS.get(); } ExprAST *getRHS() const { return RHS.get(); } -- cgit v1.3.1-4-g156e