-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparserDef.h
132 lines (116 loc) · 2.18 KB
/
parserDef.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
124
125
126
127
128
129
130
131
132
// Batch Number - 38
// 2014A7PS102P - RISHABH JOSHI
// 2014A7PS248P - DEEP VYAS
#ifndef _PARSERDEF_
#define _PARSERDEF_
#include "lexerDef.h"
#include <stdbool.h>
#define GRAMMAR_LEN 98
#define noNonTerminals 53
#define noTerminals 57
#define maxFirstSet 20
#define maxFollowSet 20
typedef enum{
PROGRAMNT,
MODULEDECLARATIONS,
OTHERMODULES,
DRIVERMODULE,
MODULEDECLARATION,
MODULENT,
MODULEDEF,
INPUTPLIST,
RET,
OUTPUTPLIST,
N1,
N2,
DATATYPE,
RANGE,
TYPE,
STATEMENTS,
STATEMENT,
IOSTMT,
VAR,
WHICHID,
SIMPLESTMT,
ASSIGNMENTSTMT,
WHICHSTMT,
LVALUEIDSTMT,
LVALUEARRSTMT,
INDEX,
MODULEREUSESTMT,
OPTIONAL,
IDLIST,
N3,
EXPRESSION,
ARITHMETICORBOOLEANEXPR,
ANYTERM,
N7,
N8,
ARITHMETICEXPR,
N4,
TERM,
N5,
FACTOR,
LOGICALOP,
RELATIONALOP,
OP1,
OP2,
DECLARESTMT,
CONDITIONALSTMT,
CASESTMTS,
N9,
VALUE,
DEFAULTNT,
ITERATIVESTMT,
NEGVAR,
XXX
}NonTerminal;
typedef TokenType Terminal;
typedef union{
Terminal term;
NonTerminal non_term;
}GNodeType;
typedef enum{
TERMINAL,NONTERMINAL
}tag;
struct GrammarNode{
GNodeType ele;
tag t;
// struct GrammarNode *next;
int len;
};
typedef struct GrammarNode GrammarNode;
typedef struct {
int grammarindex;
Terminal t;
}FirstAndFollowNode;
typedef struct{
FirstAndFollowNode first[noNonTerminals][maxFirstSet];
FirstAndFollowNode follow[noNonTerminals][maxFollowSet];
}FirstAndFollow;
struct ParseTreeNode{
tokenInfo *tokenptr;
bool isLeaf;
GrammarNode nodeSymbol;
// FOR AST SIGN PROPAGATION
int parseTreeSign;
struct ParseTreeNode *parent, *sibling, *left;
};
typedef struct ParseTreeNode ParseTreeNode;
void populateFirstSet();
void populateFollowSet();
void populateGrammar();
void compute_first_rec(int i,int update);
void compute_first();
void compute_follow_rec(int i,int update);
void compute_follow();
void createParsingTable();
void printFollow();
void printFirst();
void printParsingTable();
ParseTreeNode* getGrammarRules(ParseTreeNode *root, int grammarIndex);
void populateParseTree(ParseTreeNode *root, FILE **fp, int flag);
ParseTreeNode* parseInputSourceCode(char *testcaseFile, int flag);
void __printParseTree(FILE *fp, ParseTreeNode *root);
void printParseTree(FILE *fp);
#endif