|
一个简单的C语言编译器(2) list<string> symbolList;//符号表 }; Compiler::Compiler(string CmdLine) { line=1; hasError=0; needOutSuppose=0; hasFile=0; fileName=CmdLine; log.open((fileName + "_Log.txt").c_str(),ios::out); //char c; //测试nextChar() //do{c=nextChar();log<<c;}while(c!='#');log<<endl; }
Compiler::Compiler() { } Compiler::~Compiler() { log.close(); } Symbol *Compiler::lexer() { char c; int s=1; Symbol *r; r=new Symbol(); c=currentChar; while(s){ switch(s){ case 1: if(c=='\x0A')line++; else if(isspace(c)) s=1; else if(isalpha(c)c=='_'){ s=2; r->word=c; } else if(isdigit(c)){ s=3; r->word=c; } else{ switch(c){ case '+': case '-': s=0; r->word=c; r->group='+'; r->line=line; break; case '*': case '%': s=0; r->word=c; r->group='*'; r->line=line; break; case '&': case '': r->word=c; s=4; break; case '>': case '<':
|