-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
123 lines (113 loc) · 2.17 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef ast_h
#define ast_h
#include "symbol.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
enum stmt_type {
TSKIP,
TPC,
TIF,
TFDEF,
TFDECL,
TEXIT,
TRET,
TFCALL,
TCONTM,
TCONT,
TBREAKM,
TBREAK,
TDECL,
TASSIGN,
TLOOP
};
class ASTlval;
class ASTstmt;
class ASTif;
class ASTExpr;
class ASTparam;
class ASTfcall;
class ASTNode {
public:
int he;
// ASTNode(int a) { he = a ;}
// virtual void run() = 0;
};
class ASTExpr : ASTNode {
public:
char op;
ASTlval *operand;
int constant_val;
ASTExpr *left;
ASTExpr *right;
ASTfcall *f = NULL;
ASTExpr(char, ASTlval *, int, ASTExpr *, ASTExpr *);
};
class ASTheader : ASTNode {
public:
ASTheader(Type, ASTparam *, string);
ASTparam *paramlist;
string identifier;
Type type;
};
class ASTfdef : ASTNode {
public:
ASTfdef(ASTheader *, ASTstmt *);
ASTheader *header;
ASTstmt *body;
};
class ASTstmt : ASTNode {
public:
ASTstmt(stmt_type, ASTstmt *, ASTstmt *, string);
stmt_type type;
string label;
ASTlval *lvalue;
ASTExpr *expr;
ASTif *ifnode;
vector<string> *identifiers;
ASTstmt *body;
ASTstmt *tail;
ASTfdef *def;
Type t;
};
class ASTlval : ASTNode {
public:
int byRef = 0;
ASTlval(bool, string);
string identifier;
bool constant;
int nesting_diff = 0; // these are the starting values and may change
int offset = 0;
std::vector<ASTExpr *> *indices;
void print() {
cout << "Printing bracket lists" << endl;
for (auto i : *indices) {
cout << i->constant_val << " ";
}
cout << endl;
}
};
class ASTparam : ASTNode {
public:
ASTparam(vector<string> *, Type, ASTparam *);
vector<string> *identifiers;
Type p;
bool byref;
ASTparam *next;
};
class ASTfcall : ASTNode {
public:
ASTfcall(string);
string identifier;
vector<ASTExpr *> *parameters;
int nesting_diff; // these are the starting values and may change
};
class ASTif {
public:
ASTif(ASTExpr *, ASTstmt *);
ASTExpr *condition;
ASTstmt *body;
ASTif *tail;
};
#endif