From c2a3cecc1ab2d3f27dcea40a6f0f353b0306d66a Mon Sep 17 00:00:00 2001 From: ov-4 Date: Thu, 29 Jan 2026 10:20:58 +0000 Subject: Added INPUT, OUTPUT and DECLARE --- include/cps/AST.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 include/cps/AST.h (limited to 'include/cps/AST.h') diff --git a/include/cps/AST.h b/include/cps/AST.h new file mode 100644 index 0000000..5b28e8a --- /dev/null +++ b/include/cps/AST.h @@ -0,0 +1,63 @@ +#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(); } +}; + +} // namespace cps -- cgit v1.3.1-4-g156e