#ifndef EXPR_HH #define EXPR_HH #include "../tokenizer.hh" #include #include #include struct Expr; using ExprPtr = std::shared_ptr; struct Binary { Binary(ExprPtr left, Token op, ExprPtr right) : left{left}, op{op}, right{right} {}; ExprPtr left; Token op; ExprPtr right; }; struct Grouping { Grouping(ExprPtr expr) : expression{expr} {}; ExprPtr expression; }; struct Literal { Literal(Object value) : value{value} {}; Object value; }; struct Unary { Unary(Token op, ExprPtr right) : op{op}, right{right} {}; Token op; ExprPtr right; }; enum class ExprType { BINARY, GROUPING, LITERAL, UNARY, }; using Expression = std::variant; struct Expr { Expr(ExprType type, Expression value) : type{type}, value{value} {} ExprType type; Expression value; }; class AstPrinter { public: std::string print(const Expr &expr); private: std::string parenthesize(const std::string &name, std::vector exprs); }; #endif