|
一个简单的C语言编译器(20) err(4,ip->line); goto label1; }//switch r=ss.top(); iq=sos.top(); r=Goto::lookUp(iq->group,r); if(r) ss.push(r); else err(4,iq->line); }//else else if(t==0&&!hasError){ log<<endl; log<<"代码通过语法检查,未发现语法错误."<<endl; } }//while label1: in.close(); log<<"词法分析完毕..."<<endl; log<<"*******************************************"<<endl; }
Compiler::preProcess() { string tmpstr; ifstream ins((fileName+".crr").c_str(),ios::in); log<<"*******************************************"<<endl; log<<"程序预处理开始"<<endl; if(ins.is_open()){ hasFile=1; log<<"打开文件 \'"<<fileName<<".crr\' 成功!"<<endl; } else{ hasFile=0; log<<"打开文件失改!"<<endl; } while(getline(ins,tmpstr)){ if(tmpstr.substr(0,18)=="#import system.out"){ needOutSuppose=1; break; } } if(needOutSuppose) log<<"需要引入系统函数\'System.out\'."<<endl; else log<<"不需要引入系统函数\'System.out\'."<<endl; log<<"程序预处理完成!"<<endl; log<<"*******************************************"<<endl; ins.close(); } char Compiler::nextChar() { char ch; if(in.get(ch)){ currentChar=ch; return ch; } else{ currentChar=ch; return '$'; } } void Compiler::emitter()
|