int main() { system("mode con cols=100 lines=30"); system("COLOR 0A"); while(1){ dat.init(); lexer.init(); buf.clear(); deb.init(); ending=0; cout << "请将要运行的程序放在与本程序相同的目录下" << endl; cout << "输入1运行程序,输入2调试程序,输入3退出程序" << endl; int type; while(cin >> type){ if (type == 1) { cout << "输入要运行的程序文件名:" << endl; break; } else if (type == 2) { cout << "输入要调试的程序文件名:" << endl; break; } else if(type==3) exit(0); else { cout << "输入不合法!请重新输入:" << endl; } } string filename; //cin >> filename; ifstream file; string s; while(cin >> filename){ file.open(filename); if(!file) cout << "输入文件名错误!重新输入:" << endl; else break; } while (!file.eof()) { getline(file, s); buf.push_back(s); } if(type==2){ cout << "进入调试模式\n以下为调试器的命令,输入h即可再次查看" << endl; cout << "列出所有代码:l\n查看变量的值:p 变量名\n设置断点:b 行号\n取消断点:nb 行号\n查看当前所有的断点的行号:wb\n下一步:n\n运行程序:r\n" << endl; deb.wait(); } /*buf.push_back("begin"); buf.push_back("out 123;"); buf.push_back("end");*/ int x = 0, y = 0; bool flag=0; while (1) { if (x == buf.size()) break; if (buf[x].size() == 0) { x++; y = 0; continue; } if(buf[x][y]=='/' && y+1<buf[x].size() && buf[x][y]=='/'){ x++; y=0; } if (y + 4<buf[x].size()) { if (buf[x].substr(y, 5) == "begin") { lexer.curx = x + 1; lexer.cury = 0; if(deb.next) { cout << lexer.curx << " -> " << buf[lexer.curx] << endl; deb.wait(); } if(deb.is_bp(lexer.curx)){ cout << lexer.curx << " -> " << buf[lexer.curx] << endl; deb.wait(); } flag=1; lexer.domain(); break; } } y++; if (y == buf[x].size()) { x++; y = 0; } } if(!flag){ cout << "没有检测到begin" <<endl; system("pause"); exit(0); } } return 0; }