-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
58 lines (46 loc) · 1.17 KB
/
main.c
File metadata and controls
58 lines (46 loc) · 1.17 KB
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
#include "globals.h"
#include "util.h"
#include "scan.h"
#include "analyze.h"
/*allocate global variables*/
int lineno = 0;
FILE *source;
FILE *listing;
int Error = FALSE;
int main(int argc, char *argv[]){
char pgm[20]; //source code file name
TreeNode * syntaxTree;
if (argc != 2){
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
exit(1);
}
strcpy(pgm, argv[1]);
if (strchr(pgm, '.') == NULL)
strcat(pgm, ".c");
source = fopen(pgm, "r");
if (source == NULL){
fprintf(stderr, "File %s not found\n", pgm);
exit(1);
}
listing = stdout;
if (NO_PARSE){
fprintf(listing, " line number\t\t token\t lexeme\n");
fprintf(listing, "--------------------------------------------------------\n");
while (getToken() != ENDFILE);
}
syntaxTree = parse();
if (Error) return -1;
if (NO_ANALYZE){
fprintf(listing, "\nSyntax tree:\n");
printTree(syntaxTree);
}
fprintf(listing, "\nBuilding Symbol Table...\n");
buildSymtab(syntaxTree);
if (Error) return -1;
fprintf(listing, "\nChecking Types...\n");
typeCheck(syntaxTree);
if (Error) return -1;
fprintf(listing, "\nType Checking Finished\n");
fclose(source);
return 0;
}