-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
45 lines (38 loc) · 1.1 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
/****************************************************/
/* File: main.c */
/* Main program for TINY compiler */
/* Compiler Construction: Principles and Practice */
/* Kenneth C. Louden */
/****************************************************/
#include "globals.h"
#include "util.h"
#include "lexer.h"
/* allocate global variables */
int lineno = 0;
FILE * source;
FILE * listing;
/* allocate and set tracing flags */
int EchoSource = TRUE;
int TraceLex = TRUE;
int Error = FALSE;
int main( int argc, char * argv[] )
{ TreeNode * syntaxTree;
char pgm[120]; /* source code file name */
if (argc != 2)
{ fprintf(stderr,"usage: %s <filename>\n",argv[0]);
exit(1);
}
strcpy(pgm,argv[1]) ;
if (strchr (pgm, '.') == NULL)
strcat(pgm,".tny");
source = fopen(pgm,"r");
if (source==NULL)
{ fprintf(stderr,"File %s not found\n",pgm);
exit(1);
}
listing = stdout; /* send listing to screen */
fprintf(listing,"\nCOMPILATION: %s\n",pgm);
while (getToken()!=ENDFILE);
fclose(source);
return 0;
}