Slightly improved version of the parser

This commit is contained in:
2025-06-18 22:57:52 +01:00
parent ae87a3b4a3
commit 56e259d7ed
3 changed files with 36 additions and 4 deletions

View File

@@ -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: {

View File

@@ -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);