-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypeExpressionTable.c
117 lines (105 loc) · 4.31 KB
/
typeExpressionTable.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
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
/**
SHUBHAM AGARWAL -- 2018A7PS0301P
YASH RAJ SINGH -- 2018A7PS0214P
SAHIL KATTNA -- 2018A7PS0154P
AGRAWAL RAJAT RAMESH -- 2018A7PS0182P
**/
#include "typeExpressionTable.h"
//********************8PRINTING TYPE EXPRESSION TABLE**************************//
void printTypeExpressionsTable(TypeExpressionTable T[], char *filename)
{
FILE *fp = fopen(filename, "w");
if (fp == NULL)
{
printf("ERROR OPENING FILE TO PRINT TYPE EXPRESSION TABLE");
return;
}
fprintf(fp, "%10.10s %15.15s %15.15s %15.15s \n", "Variable", "Type", "Bind_type", "Type_Expression");
for (int i = 0; i < curr_table_entry; i++)
{
char var_name[200], dec_name[200], bind_name[200];
strcpy(var_name, T[i].var_name); //field1
bind_info info = T[i].info;
strcpy(bind_name, string_bind[T[i].info]); //field2
NonTerminal tag = T[i].tag;
strcpy(dec_name, NonTerminalMap[T[i].tag]); //field3
fprintf(fp, "%10.10s %15.15s %15.15s ", var_name, dec_name, bind_name);
//field4 here on
if (tag == primitive)
{ //Primitive
fprintf(fp, " <basicType=%s>", TerminalMap[T[i].record.primitive_type]);
//print name, dec_type, bind_info, typeExpression
}
else if (tag == array)
{
//Array
int dim = T[i].record.arr_record.dim;
fprintf(fp, " <type=rectangularArray, dimensions=%d, ", dim);
for (int j = 0; j < dim; j++)
{
int a = T[i].record.arr_record.dim_bound[j][0];
int b = T[i].record.arr_record.dim_bound[j][1];
//case for var_name in d_bind
if (a != -1 && b != -1)
fprintf(fp, "range_R%d= (%d, %d), ", j + 1, a, b);
else if (a == -1 && b != -1)
fprintf(fp, "range_R%d= (%s, %d), ", j + 1, T[i].record.arr_record.l_indexes[j], b);
else if (a != -1 && b == -1)
fprintf(fp, "range_R%d= (%d, %s), ", j + 1, a, T[i].record.arr_record.u_indexes[j]);
else if (a == -1 && b == -1)
fprintf(fp, "range_R%d= (%s, %s), ", j + 1, T[i].record.arr_record.l_indexes[j], T[i].record.arr_record.u_indexes[j]);
}
fprintf(fp, "basicElementType = Integer>");
//basic=Integer by def
}
else if (tag == jagged_array)
{ //Jagged_ARRAY
int dim = T[i].record.j_arr_record.dim;
fprintf(fp, " <type =jaggedArray, dimensions=%d, ", dim);
if (dim == 2)
{
int high = T[i].record.j_arr_record.r1_high;
int low = T[i].record.j_arr_record.r1_low;
fprintf(fp, "range_R1=(%d, %d) range_R2 = (", low, high);
for (int j = 0; j < high - low + 1; j++)
{
fprintf(fp, " %d ", T[i].record.j_arr_record.dim_bound._line[j]);
if (j != high - low)
fprintf(fp, ",");
//from (low,high) gives size , 0 index
}
}
else
{ //dim==3
int high = T[i].record.j_arr_record.r1_high;
int low = T[i].record.j_arr_record.r1_low;
fprintf(fp, "range_R1=(%d, %d) range_R2 = ( ", low, high);
// <type =jaggedArray, dimensions=3, range_R1=(4, 7),
//3 [ 5, 3, 5] ,
//1 [ 5], 2 [ 4, 3] ,3 [ 5, 4, 4]
for (int j = 0; j < high - low + 1; j++)
{
int m = T[i].record.j_arr_record.dim_bound.jag_line[j][0];
fprintf(fp, "%d [", m);
for (int k = 0; k < m; k++)
{
fprintf(fp, " %d", T[i].record.j_arr_record.dim_bound.jag_line[j][k + 1]);
if (k != m - 1)
fprintf(fp, ",");
}
fprintf(fp, " ]");
if (j != high - low)
fprintf(fp, ", ");
}
}
fprintf(fp, "), basicElementType = integer>");
//basic=Integer by def
}
else
{
fprintf(fp, " NOT A VALID TYPE EXPRESSION");
}
fprintf(fp, "\n");
}
fclose(fp);
}