-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.h
35 lines (29 loc) · 864 Bytes
/
ast.h
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
#ifndef AST_H
#define AST_H
#include <iostream>
using namespace std;
enum NodeType {
N_NULL,
N_Number, N_Variable,
N_Assign, N_UnaryOp,
N_Add, N_Subtract, N_Multipy, N_Divide,
N_dummyOpenParen, N_dummyCloseParen
};
class ASTNode {
public:
ASTNode* left;
ASTNode* right;
NodeType type;
string nodeValue;
ASTNode(NodeType initNodeType);
void init_NumberNode(string number);
void init_VariableNode(string var);
void init_AssignNode(ASTNode* var, ASTNode* expression);
void init_UnaryOperator(string sign, ASTNode* atom); //atom will always be left node
void init_AddNode(ASTNode* opLeft, ASTNode* opRight);
void init_SubtractNode(ASTNode* opLeft, ASTNode* opRight);
void init_MultiplyNode(ASTNode* opLeft, ASTNode* opRight);
void init_DivideNode(ASTNode* opLeft, ASTNode* opRight);
};
void deleteAST(ASTNode* &root);
#endif