aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorov-4 <hausemasterstream@gmail.com>2026-01-29 11:13:05 +0000
committerov-4 <hausemasterstream@gmail.com>2026-01-29 11:13:05 +0000
commit05c19789d5e1b5edd050ee97c19a8ab86ec9e0f6 (patch)
tree4fd26a6611084908c445c61a285ebf849d571e57 /include
parentf1fedc36ec54578be4983d2fc6abee999dbc51c2 (diff)
Added half way of IF statement
Diffstat (limited to 'include')
-rw-r--r--include/cps/AST.h29
-rw-r--r--include/cps/CodeGen.h3
-rw-r--r--include/cps/Parser.h3
3 files changed, 33 insertions, 2 deletions
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<ExprAST> LHS, RHS;
public:
- BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS, std::unique_ptr<ExprAST> RHS)
+ BinaryExprAST(int Op, std::unique_ptr<ExprAST> LHS, std::unique_ptr<ExprAST> 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<ExprAST> Cond;
+ std::vector<std::unique_ptr<StmtAST>> ThenStmts;
+ std::vector<std::unique_ptr<StmtAST>> ElseStmts;
+public:
+ IfStmtAST(std::unique_ptr<ExprAST> Cond,
+ std::vector<std::unique_ptr<StmtAST>> ThenStmts,
+ std::vector<std::unique_ptr<StmtAST>> ElseStmts)
+ : Cond(std::move(Cond)), ThenStmts(std::move(ThenStmts)), ElseStmts(std::move(ElseStmts)) {}
+
+ ExprAST *getCond() const { return Cond.get(); }
+ const std::vector<std::unique_ptr<StmtAST>> &getThenStmts() const { return ThenStmts; }
+ const std::vector<std::unique_ptr<StmtAST>> &getElseStmts() const { return ElseStmts; }
+};
+
+class BinaryExprAST : public ExprAST {
+ char Op;
+ std::unique_ptr<ExprAST> LHS, RHS;
+public:
+ BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS, std::unique_ptr<ExprAST> 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(); }
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index d6a6013..88e4755 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -21,6 +21,9 @@ class CodeGen {
llvm::Value *PrintfFormatStr;
llvm::Value *ScanfFormatStr;
llvm::Value *emitExpr(ExprAST *Expr);
+ void emitStmt(StmtAST *Stmt);
+ void emitIfStmt(IfStmtAST *Stmt);
+
void SetupExternalFunctions();
diff --git a/include/cps/Parser.h b/include/cps/Parser.h
index 1b27a22..c5d0c97 100644
--- a/include/cps/Parser.h
+++ b/include/cps/Parser.h
@@ -24,6 +24,9 @@ class Parser {
std::unique_ptr<ExprAST> ParseIdentifierExpr();
std::unique_ptr<ExprAST> ParseParenExpr();
+ std::unique_ptr<StmtAST> ParseStatement();
+ std::unique_ptr<StmtAST> ParseIfStmt();
+
public:
Parser(Lexer &L);
std::vector<std::unique_ptr<StmtAST>> Parse();