-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsetree.h
111 lines (87 loc) · 2.14 KB
/
parsetree.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
/*
Group Number: 56
Chirag Singhal 2018A7PS0219P
Harshan Baskar 2018A7PS0166P
Nitya Mangal 2018A7PS0216P
*/
#ifndef PARSETREE_H
#define PARSETREE_H
#include <stdio.h>
#include "grammar.h"
#include "token.h"
// TYPEEXPRESSIONROW
typedef enum _basicElementTypeEnum {
INTEGER_TYPE,
REAL_TYPE,
BOOLEAN_TYPE
} basicElementTypeEnum;
union rectArrayIndexUnion {
int intIndex;
char* varIdIndex;
};
typedef struct _rectArrayIndex {
int isVarId;
union rectArrayIndexUnion value;
} rectArrayIndex;
struct rectArray {
int dimensions;
rectArrayIndex** ranges;
basicElementTypeEnum basicElementType;
};
union jaggedArrayR2Dims {
int* range_2d;
int** range_3d; //first element of each row has its size
};
struct jaggedArray {
int dimensions;
int R1_range[2];
union jaggedArrayR2Dims R2_ranges;
basicElementTypeEnum basicElementType;
};
union typeExpression {
basicElementTypeEnum primitive;
struct rectArray rectArray;
struct jaggedArray jaggedArray;
};
typedef enum _typeVariableEnum {
PRIMITIVE,
RECTARRAY,
JAGGEDARRAY,
ERROR
} typeVariableEnum;
typedef enum _typeRectArrayEnum {
STATIC,
DYNAMIC,
NOT_APPLICABLE
} typeRectArrayEnum;
typedef struct _typeExpressionRow {
typeVariableEnum typeVariable;
typeRectArrayEnum rectArrayType;
union typeExpression expression;
} typeExpressionRow;
// PARSETREE
typedef struct tokenNode* parserStackNode;
typedef struct _parseNode {
struct tokenNode* token;
int terminal;
char* sourceToken;
typeExpressionRow* typeExpression;
int grammar_rule_idx; // 1-based index
int depth;
int num_child;
struct _parseNode** children;
} parseNode;
typedef parseNode parseTree;
struct parserStack {
parserStackNode token;
int terminal;
struct _parseNode* parseTreeNode;
//struct parserStack* prev;
struct parserStack* next;
};
typedef struct parserStack* stack;
extern void createParseTree(parseTree *t, tokenStream *s, grammar G);
extern stack pop(stack head);
extern stack push(stack s, stack head);
extern void freeStackNode(stack node);
#endif // PARSETREE_H