-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
50 lines (37 loc) · 1.18 KB
/
main.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
#include "dependencies.h"
#include "header.h"
const char* out_file_path = "./tokens.txt";
const char* xml_file_path = "./syntax_tree.xml";
int main(int argc, char *argv[]){
if (argc != 2){
printf("Program file's path is missing\n");
exit(1);
}
const char* in_file_path = argv[1];
prog_file = fopen(in_file_path, "r");
if(prog_file == NULL){
perror("Error while opening program file");
exit(1);
}
out_file = fopen(out_file_path, "w");
if(out_file == NULL){
perror("Error while opening tokens output file");
exit(1);
}
lexicalAnalysis(); // Lexical Analysis : tokenization
fclose(prog_file);
fclose(out_file);
xml_file = fopen(xml_file_path, "w");
if(xml_file == NULL){
perror("Error while opening syntax tree file");
exit(1);
}
fprintf(xml_file,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(xml_file,"<note>\n");
Program(); //Syntax Analysis : parsing
fprintf(xml_file,"</note>\n");
fclose(xml_file);
semanticAnalysis(); //semantic analysis
printf("Program compiled\nOutput files: ./tokens.txt, ./syntax_tree.xml\n");
exit(0);
}