-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
47 lines (39 loc) · 876 Bytes
/
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "lexerf.h"
#include "parserf.h"
#include "codegeneratorf.h"
/**
* Main function that opens a file and calls the lexer function.
*/
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Error: correct syntax: %s <filename.unn>\n", argv[0]);
exit(1);
}
FILE *file;
file = fopen(argv[1], "r");
if (!file)
{
printf("ERROR: File not found\n");
exit(1);
}
Token *tokens = lexer(file);
for (size_t i = 0; tokens[i].type != END_OF_TOKENS; i++)
{
print_token(tokens[i]);
}
Node *test = parser(tokens);
generate_code(test);
FILE *assembly_file = fopen("generated.asm", "r");
if (!assembly_file)
{
printf("ERROR");
exit(1);
}
system("./buildasm.sh");
}