forked from SarthakShah001/Compiler2K23
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseTree.h
More file actions
93 lines (82 loc) · 1.99 KB
/
parseTree.h
File metadata and controls
93 lines (82 loc) · 1.99 KB
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
/*
***** Group No. - 9 *****
Name : Sarthak Shah ID : 2020A7PS0092P
Name : Siddharth Khandelwal ID : 2020A7PS0098P
Name : Archaj Jain ID : 2020A7PS0072P
Name : BhanuPratap Singh Rathore ID : 2020A7PS1675P
Name : Rishi Rakesh Shrivastava ID : 2020A7PS0108P
*/
#ifndef _parseTree_
#define _parseTree_
#include "parserDef.h"
#include "doublyLinkedList.h"
#include "astdef.h"
typedef enum {
AST_PROGRAM,
AST_MODULEDECLARATIONS,
AST_MODULEDEFINITIONS,
AST_DRIVER,
AST_MODULE,
AST_INPUT_PARAMETER_LIST,
AST_OUTPUT_PARAMETER_LIST,
AST_INP_PARAMETER,
AST_OUT_PARAMETER,
AST_ARRAY,
AST_RANGE_ARRAYS,
AST_STATEMENTS,
AST_GET_VALUE,
AST_PRINT,
AST_ARRAY_ACCESS,
AST_ID_ASSIGN,
AST_ARRAY_ASSIGN,
AST_INDEX_ARR,
AST_MODULE_REUSE,
AST_PARAMETER_LIST1,
AST_PARAMETER_LIST2,
AST_ACTUAL_PARA,
AST_UNARYEXPR,
AST_RELATIONAL_OP,
AST_LOGICAL_OP,
AST_PLUS,
AST_MINUS,
AST_MUL,
AST_DIV,
AST_ARRAY_FACTOR,
AST_RANGE_FOR_LOOP,
AST_DECLARE_STMT,
AST_SWITCH,
AST_CASES,
AST_CASE,
AST_FORLOOP,
AST_WHILELOOP,
AST_INDEX_FOR_LOOP,
AST_DEFAULT,
}astToken;
typedef struct PARSETREENODE* parseTreeNode ;
struct PARSETREENODE{
parseTreeNode parent , sibling , prevSibling ;
TOK tok;
parseTreeNode child;
symbol s ;
parseTreeNode syn_node;
parseTreeNode inh_node;
astToken ast_name;
tkType type_inh;
tkType type_syn;
int scope[2];
bool is_visited;
};
// functions for the parse tree
// create tree
// add rule
parseTreeNode createTree() ;
// add rules from grammar
void addRuleInTree(parseTreeNode treeNode , dlinkedlist node) ;
void openparsetreefile(FILE *f);
// prints parse tree into the file open from previous function
void printParseTree(parseTreeNode treeNode) ;
// add tokens to terminals in parsetree (logic implemented in parse tree)
void addTokenTonode(parseTreeNode treeNode,Token currtoken);
void printAST(parseTreeNode treeNode) ;
void freeParseTree(parseTreeNode treeNode) ;
#endif