-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparserDef.h
executable file
·191 lines (163 loc) · 3.07 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* Compilers Project Group 2
// Aditya Raisinghani 2011A7PS042P
// Utkarsh Verma 2011A7PS137P
// BITS Pilani, Pilani Campus
// Second semester 2014
*/
//Contains all definitions for data types such as grammar, table, parseTree etc. used in parser.c
#ifndef PARSERDEF
#define PARSERDEF
#include "tokens.h"
#define RULESIZE 150
#define NONTERMSIZE 25
#define TERMINALS 42 // Number of terminals that exist
#define NONTERMINALS 45 // Number of non terminals that exist
#define OFFSET 6 // defined by the format adopted in grammar_rules.txt
/*
// An enumeration of non Terminals.
*/
typedef enum nonTermValue
{
mainFunction,
stmtsAndFunctionDefs_type1,
stmtsAndFunctionDefs,
stmtOrFunctionDef,
stmt,
functionDef,
parameter_list,
type,
remainingList,
declarationStmt,
var_list,
more_ids,
assignmentStmt_type1,
assignmentStmt_type2,
leftHandSide_singleVar,
leftHandSide_listVar,
rightHandSide_type1,
rightHandSide_type2,
sizeExpression,
ifStmt,
elsePart,
otherStmts,
ioStmt,
funCallStmt,
inputParameterList,
listVar,
arithmeticExpression,
arithmeticExpression_type2,
arithmeticTerm,
arithmeticTerm_type2,
factor,
operator_lowPrecedence,
operator_highPrecedence,
booleanExpression,
constrainedVars,
var,
matrix,
rows,
rowsRemaining,
row,
remainingColElements,
matrixElement,
logicalOp,
relationalOp,
invalidNonTerm
} nonTerminal;
/*
typedef enum _leafName
{
FUNID,
ID,
NUM,
RNUM,
STR,
INT,
REAL,
STRING,
MATRIX,
PLUS,
MINUS,
MUL,
DIV,
AND,
OR,
LT,
LE,
EQ,
GT,
GE,
NE
} leafName;*/
typedef enum isNonTerm
{
FALSE, TRUE
} isNonTerminal;
typedef enum _choice
{
MAKENODE,LEAF,DIRECT
}choice;
typedef enum isNonTerm hasEmpty;
typedef enum isNonTerm flag;
typedef enum isNonTerm isNullable;
/*
// Structure for storing first and follow sets of different non Terminals.
*/
typedef struct _first **first;
typedef struct _follow **follow;
struct _first
{
token token_name;
int ruleNum;
};
struct _follow
{
token token_name;
int ruleNum;
};
typedef struct _nonterm **nonterm;
typedef struct _nonterm *NT;
struct _nonterm
{
nonTerminal nonterm_value;
first firstSet;
follow followSet;
isNullable nullable;
};
/*
// Structures for the RHS terms
// terminals: pointer to a structure for a term
// struct _termSet: a structure for the RHS terms used to form a linked list of such terms.
// terminal: a structure for a single RHS term, containing the token/nonTerminal value.
*/
typedef struct _terminal
{
isNonTerminal flag;
token tokValue;
nonTerminal nontermValue;
} terminal;
typedef struct _termSet *terminals;
struct _termSet
{
terminal term_value;
terminals nextTerm;
hasEmpty nullable;
};
//---------------------------
/*
// The structure for the grammar rule.
// nonTerminal: Enumeration of non terminals(LHS of the rule).
// terminals: linked list of the RHS of the rule(Name is misrepresenting- it could be a non terminal as well)
// rule: Points to the next grammar Rule.
*/
typedef struct _rule *rule;
typedef rule grammar;
struct _rule
{
int ruleNum;
nonTerminal nonterm_value;
terminals termSet;
hasEmpty nullable;
rule nextRule;
};
#endif