Slightly improved version of the parser
This commit is contained in:
@@ -5,6 +5,26 @@
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
template <>
|
||||
Expr make_expr<Binary>(Binary value) {
|
||||
return Expr(ExprType::BINARY, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
Expr make_expr<Grouping>(Grouping value) {
|
||||
return Expr(ExprType::GROUPING, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
Expr make_expr<Literal>(Literal value) {
|
||||
return Expr(ExprType::LITERAL, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
Expr make_expr<Unary>(Unary value) {
|
||||
return Expr(ExprType::UNARY, value);
|
||||
}
|
||||
|
||||
std::string AstPrinter::print(const Expr &expr) {
|
||||
switch (expr.type) {
|
||||
case ExprType::BINARY: {
|
||||
|
||||
@@ -52,6 +52,9 @@ struct Expr {
|
||||
Expression value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Expr make_expr(T value);
|
||||
|
||||
class AstPrinter {
|
||||
public:
|
||||
std::string print(const Expr &expr);
|
||||
|
||||
Reference in New Issue
Block a user