#ifndef STMT_HH #define STMT_HH #include "expr.hh" #include #include struct Stmt; struct _Expression; struct _Print; struct _Var; enum class StmtType { EXPRESSION, PRINT, VAR, }; using StmtVariant = std::variant< std::shared_ptr<_Expression>, std::shared_ptr<_Print>, std::shared_ptr<_Var> >; #define Expression(EXPR) (Stmt{StmtType::EXPRESSION, std::make_shared<_Expression>(EXPR)}) #define Print(EXPR) (Stmt{StmtType::PRINT, std::make_shared<_Print>(EXPR)}) #define Var(NAME, EXPR) (Stmt{StmtType::VAR, std::make_shared<_Var>(NAME, EXPR)}) struct Stmt { Stmt(StmtType type, StmtVariant value); // Copy constructor Stmt(const Stmt &other); // Move constructor Stmt(const Stmt &&other); // Copy assignment Stmt &operator=(const Stmt &other); // Move assignment Stmt &operator=(const Stmt &&other); StmtType type; StmtVariant value; }; struct _Expression { _Expression(const Expr &expr) : expr{expr} {} Expr expr; }; struct _Print { _Print(const Expr &expr) : expr{expr} {} Expr expr; }; struct _Var { _Var(const Token &name, const Expr &expr) : name{name}, expr{expr} {} Token name; Expr expr; }; #endif