-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriver.c
43 lines (36 loc) · 1.39 KB
/
driver.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compiler.h"
extern FILE* yyin;
extern int yyparse();
// A global variable that holds a pointer to the AST root
ASTNode* gASTRoot;
int main(int argc, char**argv)
{
if (argc != 2){
printf("ERROR: Invalid number of command-line arguments. Usage: bcc File_Name.bc\n");
exit(1);
}
yyin = fopen(argv[1], "r" );
if (yyin == NULL){
printf("ERROR: Failed to open the input file\n");
exit(1);
}
// Call the parser.
// Add embedded actions to the parser (in BabyC.y) to construct the AST and store its root in gASTRoot.
yyparse();
fclose(yyin);
// Now that the AST has been constructed, pass its root to the function that traverses it and generates the ILOC code.
char * test = strtok(argv[1], ".");
char * outputfile = (char *) calloc(strlen(test) + 8, sizeof(char));
strcat(outputfile, test);
strcat(outputfile, ".iloc");
FILE * output = fopen(outputfile, "w+");
fputs("", output);
fclose(output);
output = fopen(outputfile, "a+");
// FILE * outputFile = fopen(, "a+");
GenerateILOC(gASTRoot, output);
// Code generation is commented out in this assignment. You will implement it in the next assignment.
}