-
Notifications
You must be signed in to change notification settings - Fork 0
/
rascal.c
49 lines (38 loc) · 1.08 KB
/
rascal.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
#include <stdio.h>
#include <stdlib.h>
#include "semantico.h"
#include "bison.tab.h"
A_Programa absyn_root;
/* Compilar:
$ make
Executar:
$ ./compilador arquivo.ras
*/
int main(int argc, char** argv){
FILE* fp;
extern FILE* yyin;
/* nome do arquivo pra passar no fopen */
String nome_prog = argv[0];
// antes de dar make verificar os imports, ver se tem repetido
if(argc < 2 || argc > 2){
fprintf(stderr, "Erro: número inválido de parâmetros\n");
fprintf(stderr, "Uso: compilador <arquivo>\n");
return EXIT_FAILURE;
}
fp = fopen(argv[1], "r");
if(fp == NULL){
printf("Erro: não foi possível ler o arquivo '%s'\n", argv[1]);
return EXIT_FAILURE;
}
yyin = fp;
if(yyparse() == 0){
fprintf(stderr, "\nSucesso sintatico!\n\n");
/* etapa semântica e geração de código MEPA */
analisaPrograma(absyn_root, nome_prog);
}
else{
fprintf(stderr, "\nAnálise com erros sintaticos!");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}