📄 main.c
字号:
/****************************************************/
/* File: main.c */
/* Main program for TINY compiler */
/* Compiler Construction: Principles and Practice */
/* Kenneth C. Louden */
/****************************************************/
#include "globals.h"
#include "util.h"
#include "scan.h"
#include "parse.h"
/* allocate global variables */
int lineno = 0;
FILE * source;
FILE * listing;
FILE * code;
/* allocate and set tracing flags */
int EchoSource = TRUE;
int TraceScan = TRUE;
main( int argc, char * argv[] )
{
int i=0;
char pgm[120]; /* source code file name */
fp=fopen("a.txt","wb+");
argv[1]="1t";
argc=2;
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,"\nTINY COMPILATION: %s\n",pgm);
// while (getToken()!=ENDFILE);
parse();//语法分析
initiate();
printf("print parse tree: in a.txt \n");
fputs("print parse tree:\r\n",fp);
rewind(source);//源文件指针重定位
//fseek(source,0L,0);
//source = fopen(pgm,"r");
TraceScan = FALSE;
EchoSource = FALSE;
fputs("program\r\n",fp);
sp=1;
flag=0;
parsetr(td);//分析树构造
printtree(td);//输出分析树
fclose(source);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -