-
Notifications
You must be signed in to change notification settings - Fork 0
/
traverse.c
53 lines (45 loc) · 1.1 KB
/
traverse.c
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
/*
* Group No. - 48
* Members:
* 2018A7PS0181P, Bikash Jena
* 2018A7PS0276P, Jatin Jain
* 2018A7PS0131P, Utkarsh Dwivedi
*/
#include "structures.h"
#define INTEGER 0
#define REAL 1
#define BOOLEAN 2
#define RARRAY 3
#define JARRAY 4
void traverseParseTree(Parse_Tree *statements)
{
int num_of_statements = statements->num_of_children;
for (int i = 0; i < num_of_statements; i++)
{
if (isDeclaration(statements->children[i]))
{
Parse_Tree *declaration_statement = statements->children[i]->children[0];
int type = findDeclaredType(declaration_statement);
Parse_Tree *identifier_list = findIdentifierList(declaration_statement);
switch (type)
{
case INTEGER:
case REAL:
case BOOLEAN:
insertPrimitiveInTable(identifier_list, type);
break;
case RARRAY:
case JARRAY:
insertArrayInTable(identifier_list, type, i, statements);
break;
default:
break;
}
}
else if (isAssignment(statements->children[i]))
{
// printf("assignment\n");
checkAssignment(statements->children[i]->children[0]);
}
}
}