-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.c
62 lines (47 loc) · 1.49 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
51
52
53
54
55
56
57
58
59
60
/***************************
C-minus Compiler -
Compiler Design Course Project
***************************/
#include "globals.h"
#include "parse.h"
#include "symtab.h"
#include "codegen.h"
#define FILE_NAME_LEN 100
FILE* source; /* source code text file */
FILE* listing; /* listing output text file */
FILE* code; /* code text file for TM simulator */
int main(int argc, char *argv[])
{
char sourcefile[FILE_NAME_LEN]; /* source code file name */
if (argc != 2){
fprintf(stderr,"usage: %s <filename>\n",argv[0]);
strcpy(sourcefile,"./test/test0.cm") ;
}
else{
strcpy(sourcefile,argv[1]) ;
}
source = fopen(sourcefile,"r");
ASSERT(source != NULL){
fprintf(stderr,"File %s not found.\n",sourcefile);
}
listing = stdout; /* send listing to screen */
fprintf(listing,"\nC-minus Compiler\ntarget: %s\n",sourcefile);
initTable();
yyrestart(source);
yyparse();
fclose(source);
fprintf(listing,"\nParsing Finished...\n");
fprintf(listing,"\nSemantic Analysis Finished...\n");
char * codefile = (char *) calloc(strlen(sourcefile), sizeof(char));
strcpy(codefile,sourcefile);
strcat(codefile,".tm");
code = fopen(codefile,"w");
ASSERT(code != NULL){
fprintf(stderr, "Unable to open %s for output.\n",codefile);
}
codeGen();
fclose(code);
fprintf(listing,"\nCode Generation Finished...\n");
fprintf(listing, "\nSee %s for result codes.\n", codefile);
return 0;
}