-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodetype.h
89 lines (74 loc) · 2.44 KB
/
nodetype.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
#include "globalsymboltable.h"
extern struct Lsymbol * currLocalTable;
extern struct Gsymbol * currFunction;
typedef enum { CONSTANT, ID, OPERATION , FUNC} nodeEnum;
/* constants */
typedef struct {
int value; /* value of constant */
int type;
} conNodeType;
struct innerVariable{
char * name;
struct innerVariable * next;
};
/* identifiers */
typedef struct {
union {
int * intPointer;
char * charPointer;
char * booleanPointer;
};
struct Gsymbol * GsymbolPointer;
struct Lsymbol * LsymbolPointer;
struct typeTable * typeTableTuple;
char * type;
char * name;
struct nodeTypeTag * expressionNode;
struct innerVariable * innerId;
int isRef;
} idNodeType;
/* operators */
typedef struct {
int oper; /* operator */
int nops; /* number of operands */
struct nodeTypeTag *op; /* operands */
} oprNodeType;
typedef struct {
char * funcName;
struct fArgExpression * fArgExps;
}funcNodeType;
//For each function call Arguments
struct fArgExpression{
struct nodeTypeTag * exprNode;
struct fArgExpression * next;
} ;
struct nodeTypeTag {
nodeEnum nodeClass; /* type of node */
char * dataType;
int lineNumber;
union {
conNodeType con; /* constants */
idNodeType id; /* identifiers */
oprNodeType opr; /* operators */
funcNodeType func; /* Functions */
};
};
typedef struct nodeTypeTag NodeType;
//Expression Tree Related Functions//
struct nodeTypeTag * makeOperationNode(int oper, int nops, ...);
struct nodeTypeTag * makeIdNode(char * varName, struct nodeTypeTag * expressionNode);
struct nodeTypeTag * makeConstantNode(int value,int type);
void freeNode(struct nodeTypeTag *p);
int evaluate(struct nodeTypeTag *p);
int hasReturnState(struct nodeTypeTag *p);
void pushForLocalVariables(struct Lsymbol *lsymbols);
int analyse(struct nodeTypeTag *p);
//For function Call
struct fArgExpression * makeFargNode(struct nodeTypeTag * exprNode);
struct nodeTypeTag * makeFunctionNode(char * funcName, struct fArgExpression * fArgs);
//Basic Functions
char * copyString(char * source);
struct nodeTypeTag * makeInnerVar(struct nodeTypeTag * Id,char * name);
struct typeTable * getFieldType(char * name,struct typeTable * type);
extern int lineNumber;
FILE *fp;