-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAST.h
More file actions
48 lines (34 loc) · 984 Bytes
/
AST.h
File metadata and controls
48 lines (34 loc) · 984 Bytes
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
#pragma once
#include <iostream>
#include <cmath>
#include <exception>
#include "SymbolTable.h"
class AST {
public:
AST() = default;
~AST();
AST(const AST& other) = default;
AST(Operation::BinaryOp op, const AST* left, const AST* right);
AST(Operation::UnaryOp op, const AST* left);
AST(int literal);
AST(float literal);
AST(const char* literal);
AST(char literal);
AST(bool literal);
AST(const SymbolData& symbol);
TypeNms::Type type() const;
std::string typeStr() const; // pt typeof
std::string valueStr() const; // pt eval
std::string trueValueStr() const; // pt eval
SymbolData symbol() const;
SymbolData evaluate() const;
private:
SymbolData evaluateUnary() const;
SymbolData evaluateBinary() const;
SymbolData _symbol;
TypeNms::Type _type;
bool _isOperation = false;
int _op;
Operation::Type _operationType;
const AST *_left = nullptr, *_right = nullptr;
};