-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionsSyntatic.c
264 lines (218 loc) · 5.12 KB
/
functionsSyntatic.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int step;
void print_variables(){
FILE *simbolsTable;
char contentType[50];
char contentName[300];
simbolsTable = fopen("SimbolsTable.txt", "r");
if(simbolsTable == NULL)
printf("Não abriu um arquivo de entrada de variaveis\n");
while(!feof(simbolsTable)){
//fscanf(simbolsTable,"%s",contentName);
//fgets(content, 300, TypeVariables);
fgets(contentName, 300, simbolsTable);
if(feof(simbolsTable))
break;
//Dont print structs
if (contentName[0] == 's' && contentName[1] == 't' && contentName[2] == 'r' && contentName[3] == 'u' && contentName[4] == 'c' && contentName[5] == 't')
{
while(strcmp(contentName, "} ;\n") != 0)
{
fgets(contentName, 300, simbolsTable);
}
fgets(contentName, 300, simbolsTable);
}
printf("\t%s",contentName);
}
fclose(simbolsTable);
}
char* getTillLineBreak(char* sentense)
{
char* new_sentense;
int count;
new_sentense =(char*) calloc(strlen(sentense), sizeof(char));
for(count = 0; count<strlen(sentense); count++)
{
if (sentense[count] == '\n')
{
sentense = new_sentense;
return sentense;
}
else
new_sentense[count] = sentense[count];
}
}
void saveNameVariables (char content[50])
{
if (step==1){
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
int qtdLetras = 0;
while(content[qtdLetras] != ' '){
fprintf(fp, "%c", content[qtdLetras]);
qtdLetras++;
}
fclose(fp);
}
}
void insertError(char error[100]){
FILE *fp;
fp = fopen("logOfErrors.txt","a+");
if(fp == NULL)
printf("Erro ao abrir o arquivo!\n");
fprintf(fp,"%s", error);
fclose(fp);
}
int verifyErrors(){
FILE *fp;
fp = fopen("logOfErrors.txt","r+");
if(fp == NULL){
printf("Erro ao abrir o arquivo!\n");
return 0;
}
char c;
do{
printf("%c", c);
c = fgetc(fp);
}while(c!=EOF);
fclose(fp);
return -1;
}
void defineDataType(char content[50])
{
FILE *fp;
fp = fopen("SimbolsTable.txt" , "r+");
int areFinal = 0;
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
char type[10] , name[50] , caracter;
int barraN_ascii = 10 , achou = 0;
while(!feof(fp)){
fscanf(fp , "%s %s" , type , name);
if (strcmp(content , name) == 0){
achou = 1;
if (strcmp(type,"int") == 0){
printf("%%d\"" );
printf(", &%s);\n" , name);
} else if (strcmp(type,"double") == 0){
printf("%%lf\"" );
printf(", &%s);\n" , name);
} else if (strcmp(type,"char") == 0){
printf("%%s\"");
printf(", &%s);\n" , name);
}
}
do{
if(feof(fp)){
areFinal = 1;
break;
}
caracter = fgetc(fp);
}while( caracter != barraN_ascii);
if(areFinal == 1 || achou == 1){
break;
}
}
if (achou == 0){
insertError("-> A variável ");
insertError(content);
insertError(" não foi declarada!\n");
}
fclose(fp);
}
void saveFloatDataVariables (double numero)
{
if (step == 1)
{
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
if(numero > 100){
insertError("-> Overflow da variavel float utilizada!\n");
}else if(numero < -100){
insertError("-> Underflow da variavel float utilizada!\n");
}
fprintf(fp, " = %lf", numero);
fprintf(fp, ";\n");
fclose(fp);
}
}
void saveIntDataVariables (int numero)
{
if (step == 1){
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
if(numero > 100){
insertError("-> Overflow da variavel int utilizada!\n");
}else if(numero < -100){
insertError("-> Underflow da variavel int utilizada!\n");
}
fprintf(fp, " = %d", numero);
fprintf(fp, ";\n");
fclose(fp);
}
}
void printPointComma(){
if (step == 1)
{
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
fprintf(fp, " ;\n");
fclose(fp);
}
}
void printOpenBrackets(){
if (step == 1)
{
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
fprintf(fp, " {\n");
fclose(fp);
}
}
void printCloseBrackets(){
if (step == 1)
{
FILE *fp;
fp = fopen("SimbolsTable.txt", "a+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
fprintf(fp, "\n}");
fclose(fp);
}
}
void printStruct()
{
FILE *fp;
char content[100];
fp = fopen("SimbolsTable.txt", "r+");
if(fp == NULL)
printf("\n\n\nNão abriu!\n\n\n");
printf("\n\n");
while(!feof(fp))
{
fgets(content, 100, fp);
// printf("%s\n", content);
if (content[0] == 's' && content[1] == 't' && content[2] == 'r' && content[3] == 'u' && content[4] == 'c' && content[5] == 't')
{
printf("%s\n", content);
while(strcmp(content, "} ;\n") != 0)
{
fgets(content, 100, fp);
printf("%s", content);
}
printf("\n\n");
}
}
}