?? main.c
字號:
#include "globals.h"
#define NO_PARSE FALSE
#define NO_ANALYZE FALSE
#define NO_CODE FALSE
#include "util.h"
#if NO_PARSE
#include "scan.h"
#else
#include "parse.h"
#if !NO_ANALYZE
#include "analyze.h"
#if !NO_CODE
#include "cgen.h"
#endif
#endif
#endif
int lineno = 0;
FILE * source;
FILE * listing;
FILE * code;
int EchoSource = TRUE; //源代碼
int TraceScan =TRUE; //詞法分析
int TraceParse = TRUE; ///語法樹
int TraceAnalyze =TRUE;//語義分析
int TraceCode = 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);
printf("Input File name:\n"); //控制臺輸入
scanf("%s",pgm);
}
else
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);
#if NO_PARSE
while (getToken()!=ENDFILE);
#else
syntaxTree = parse();
if (TraceParse) {
fprintf(listing,"\nSyntax tree:\n");
printTree(syntaxTree);
}
#if !NO_ANALYZE
if (! Error)
{ if (TraceAnalyze) fprintf(listing,"\nBuilding Symbol Table...\n");
buildSymtab(syntaxTree);
if (TraceAnalyze) fprintf(listing,"\nChecking Types...\n");
typeCheck(syntaxTree);
if (TraceAnalyze) fprintf(listing,"\nType Checking Finished\n");
}
#if !NO_CODE
if (! Error)
{ char * codefile;
int fnlen = strcspn(pgm,".");
codefile = (char *) calloc(fnlen+4, sizeof(char));
strncpy(codefile,pgm,fnlen);
strcat(codefile,".tm");
code = fopen(codefile,"w");
if (code == NULL)
{ printf("Unable to open %s\n",codefile);
exit(1);
}
codeGen(syntaxTree,codefile);
fclose(code);
}
#endif
#endif
#endif
fclose(source);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -