|
一个简单的C语言编译器(23) errText="出现无法识别的符号."; break; case 2: errText="错误的标识符."; break; case 3: errText="运算符\'&&\'(\'\')写成\'&\'(\'\')了."; break; case 4: errText="语法错误,编译停止!"; break; case 5: errText="找不到main()函数."; break; case 6: errText="所使用的函数未定义"; break; case 7: errText="语句后缺少\';\'."; break; case 8: errText="else没有与之匹配的if."; break; case 9: errText="缺少语句."; break; case 10: errText="变量未定义."; break; case 11: errText="变量以定义过,不能重新定义."; break; default: errText="未知错误!"; } log<<"发生错误:文件"<<fileName<<".crr第"<<line<<"行:"<<errText<<endl; } int Compiler::lookup(string m) { list<string>::iterator i; for (i = symbolList.begin(); i != symbolList.end(); ++i) if(*i==m) return 1; return 0;
} Symbol::Symbol() { } Symbol::Symbol(const Symbol &b) { group=b.group; line=b.line; word=b.word; } Symbol::~Symbol() { } Symbol::operator =(const Symbol &b) { group=b.group; line=b.line; word=b.word; } Label::Label() { n=next(); char buffer[6]; text=_itoa(n,buffer,10); text="L"+text; }
Label::~Label() { } int Label::next() { return ++_label; } int Label::_label=0; Action::Action() { } Action::~Action() { } int Action::lookUp(char v,int s) { int n=vs.find_first_of(v,0);
|