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