📄 main.cpp
字号:
#include "globals.h"
#define NO_PARSE FALSE
#define NO_ANALYZE FALSE
#define NO_CODE FALSE
#include "util.h"
#if NO_PARSE
#include "scaner.h"
#else
#include "parser.h"
#include "parse.h"
#endif
#if !NO_ANALYZE
#include "analyze.h"
#include "symtab.h"
#endif
#if !NO_CODE
#include "gencode.h"
#endif
int lineno=0;
FILE* source;
FILE* listing;
FILE* code;
tableRec* globalTable;
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;
globalTable=new tableRec;
globalTable->child=NULL;
globalTable->parent=NULL;
globalTable->sibling=NULL;
for(int q=0;q<BUCKETSIZE;q++)
globalTable->table[q]=NULL;
char pgm[20];
if(argc!=2)
{
fprintf(stderr,"usage: %s<filename>\n",argv[0]);
return 0;
}
strcpy(pgm,argv[1]);
source=fopen(pgm,"r+");
// listing=fopen("listing.txt","w+");
listing=stdout;
if(source==NULL||listing==NULL)
printf("can't open files!");
#if NO_PARSE
while(getToken()!=0);
#else
syntaxTree=parse();
if(TraceParse)
{
fprintf(listing,"\nSyntax tree:\n");
printTree(syntaxTree);
}
#if !NO_ANALYZE
if(!Error)
{
fprintf(listing,"\nBuilding Symbol Table ...\n");
buildSymtab(syntaxTree,globalTable);
printSymTab(listing,globalTable);
fprintf(listing,"\nChecking Types ...\n");
typeCheck(syntaxTree);
fprintf(listing,"\nType Checking Finished\n");
}
#if !NO_CODE
code=fopen("code.txt","w+");
if(code==NULL)
{
printf("Unable to open file!");
return 0;
}
genCode(syntaxTree);
#endif
#endif
#endif
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -