-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.h
163 lines (137 loc) · 2.85 KB
/
common.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
/********************************************
2017B4A70696P Abdul Kadir Khimani
********************************************/
/*Header Guard*/
#ifndef COMMON_H
#define COMMON_H
/*Color codes for printing to terminal*/
#define RED "\033[0;31m"
#define GREEN "\033[0;32m"
#define YELLOW "\033[0;33m"
#define BLUE "\033[0;34m"
#define PURPLE "\033[0;35m"
#define CYAN "\033[0;36m"
#define RESET "\033[0m"
/*General Constructs*/
#define NO_OF_GRAMMAR_RULES 59
#define NO_OF_TERMINALS 32
#define NO_OF_NONTERMINALS 31
#define MAX_ALLOWED_DECLARATIONS 21
#define MAX_ALLOWED_DIMENSION 21
#define sc startChild
#define rs rightSibling
#define HASH_DIM 35
/*Standard headers*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
/*Important Definitions for all files*/
/*Self-Explanatory*/
typedef enum NonTerminal {
programStart,
declaration,
declarations,
assignment,
assignments,
primDatatype,
IDList,
arrDatatype,
jarrDatatype,
extendIDList,
IDNum,
jaggedInit,
jaggedValues,
numList,
leftHandSide,
lvalueID,
lvalueArr,
expression,
indices,
arithmeticExpr,
opPlusMinus,
term,
factor,
opMuLDiv,
option3D,
booleanExpr,
extendArithmeticExpr,
extendTerm,
logicalOp,
commonList,
arrayDims
}NonTerminal;
typedef enum Terminal{
AND,
ARRAY,
ASSIGNOP,
BOOLEAN,
COLON,
CYBC,
CYBO,
DECLARE,
DIV,
EPSILON,
ELLIPSIS,
ID,
INTEGER,
JAGGED,
LIST,
MINUS,
MUL,
NUM,
OF,
OR,
RBO,
RBC,
PLUS,
PROGRAM,
R1,
REAL,
SEMICOLON,
SIZE,
SQBC,
SQBO,
VALUES,
VARIABLES
}Terminal;
/*Common variables*/
extern char* terminalMap[]; //defined in common.c
extern char* nonTerminalMap[];
extern int num_of_nodes;
/*Common function declarations*/
int findNonTerminal(char *str);
int findTerminal(char *str);
// typedef enum PrimitiveType{
// integer,
// real,
// boolean,
// }PrimitiveType;
// typedef struct rectangularArrayType{
// PrimitiveType basicElementType;
// int dimensions;
// char** range1;
// char** range2;
// }rectangularArrayType;
// typedef struct jaggedArrayType{
// int dimensions;
// int range1[2];
// int *range2_2D;
// int **range2_3D;
// PrimitiveType basicElementType;
// }jaggedArrayType;
// typedef union typeExpression{
// PrimitiveType primitive;
// rectangularArrayType rectArray;
// jaggedArrayType jaggedArray;
// }typeExpression;
// typedef struct tableEntry{
// int type; //0 -- primitive; 1 -- rectangular; 2 -- jagged
// char name[21];
// char arrayType[17]; // -- Static ; -- Dynamic ; -- Not Applicable
// typeExpression typeExpr;
// struct tableEntry *next;
// }tableEntry;
#endif