-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackTree.h
86 lines (69 loc) · 1.65 KB
/
stackTree.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
/*
GROUP NUMBER: 45
GROUP MEMBERS:
1. SHAH NEEL KAUSHIK
2. MEHTA AASHAY PINKESH
3. RANADE SHUBHANKAR PRASAD
*/
#ifndef _STACK_
#define _STACK_
#include "lexerDef.h"
#include "lexer.h"
#include "parserDef.h"
//these two structures are used in ast
typedef enum {intType, realType, recordType, errType} varTypes;
typedef struct typeList{
struct typeList* next;
varTypes vtype;
char fieldName[MAX_LEXEME_SIZE + 1];
}* TypeList;
typedef struct astNode{
struct astNode *parent;
struct astNode *right;
struct astNode *child;
//struct astNode *last; //last node of linked list for a construct
//int offset;
grSymbol s;
char value[MAX_FLOAT_LEN+1];
tnt_tag t;
//varTypes vtype;
TypeList tlist;
int globalFlg; //global flag, 0 init 1 means global
int line_number;
} *AstNode;
typedef struct attNode{
tnt_tag t;
grSymbol s;
} *AttNode;
typedef struct stackNode{
AttNode grammar_node;
struct stackNode* next;
struct stackNode* parent;
struct stackNode* right;
struct stackNode* child;
char value[MAX_FLOAT_LEN+1];
int line;
//for ast construction
AstNode inh, syn, addr;
int rule_id; // default value is -2, follows 0 based indexing
} *StackNode;
typedef struct stack{
StackNode head;
int size;
} *Stack;
typedef StackNode TreeNode;
TreeNode createTree(TreeNode root);
Stack newStack();
Stack push(StackNode stNode, Stack st);
Stack pop(Stack st);
StackNode top(Stack st);
int isEmpty(Stack st);
StackNode createNode(AttNode grammar_node);
//ast helper function
AstNode createAstNode(TreeNode t);
//creat ast
void createAst(TreeNode root);
//print ast
void printAst(AstNode root);
TypeList createTypeList(varTypes vtype);
#endif