-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpr.h
More file actions
55 lines (45 loc) · 1.36 KB
/
Expr.h
File metadata and controls
55 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by ryousuke kaga on 2023/11/08.
//
#ifndef INTERPRETER_IN_CPP_EXPR_H
#define INTERPRETER_IN_CPP_EXPR_H
#include "Token.h"
class Expr {
public:
virtual std::string toString();
virtual std::shared_ptr<Literal> evaluate();
void checkNumberOperand(Token* op, std::shared_ptr<Literal> right);
void checkNumberOperands(Token* op, std::shared_ptr<Literal> left, std::shared_ptr<Literal> right);
};
class BinaryExpr : public Expr {
public:
BinaryExpr(Expr* left, Token* op, Expr* right): left(left), op(op), right(right) {}
std::string toString() override;
std::shared_ptr<Literal> evaluate() override;
Expr* left;
Token* op;
Expr* right;
};
class UnaryExpr : public Expr {
public:
UnaryExpr(Token* op, Expr* expr): op(op), expr(expr) {}
std::string toString() override;
std::shared_ptr<Literal> evaluate() override;
Token* op;
Expr* expr;
};
class GroupingExpr : public Expr {
public:
GroupingExpr(Expr* expr): expr(expr) {}
std::string toString() override;
std::shared_ptr<Literal> evaluate() override;
Expr* expr;
};
class LiteralExpr : public Expr {
public:
LiteralExpr(std::shared_ptr<Literal> literal): literal(literal) {}
std::string toString() override;
std::shared_ptr<Literal> evaluate() override;
std::shared_ptr<Literal> literal;
};
#endif //INTERPRETER_IN_CPP_EXPR_H