#pragma once #include #include #include namespace cps { class ExprAST { public: virtual ~ExprAST() = default; }; class NumberExprAST : public ExprAST { int Val; public: NumberExprAST(int Val) : Val(Val) {} int getVal() const { return Val; } }; class VariableExprAST : public ExprAST { std::string Name; public: VariableExprAST(const std::string &Name) : Name(Name) {} const std::string &getName() const { return Name; } }; class StmtAST { public: virtual ~StmtAST() = default; }; class DeclareStmtAST : public StmtAST { std::string Name; public: DeclareStmtAST(const std::string &Name) : Name(Name) {} const std::string &getName() const { return Name; } }; class AssignStmtAST : public StmtAST { std::string Name; std::unique_ptr Expr; public: AssignStmtAST(const std::string &Name, std::unique_ptr Expr) : Name(Name), Expr(std::move(Expr)) {} const std::string &getName() const { return Name; } ExprAST *getExpr() const { return Expr.get(); } }; class InputStmtAST : public StmtAST { std::string Name; public: InputStmtAST(const std::string &Name) : Name(Name) {} const std::string &getName() const { return Name; } }; class OutputStmtAST : public StmtAST { std::unique_ptr Expr; public: OutputStmtAST(std::unique_ptr Expr) : Expr(std::move(Expr)) {} ExprAST *getExpr() const { return Expr.get(); } }; class BinaryExprAST : public ExprAST { int Op; std::unique_ptr LHS, RHS; public: 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(); } }; } // namespace cps