⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errors.cc

📁 编译原理课程设计之pp2语法分析程序
💻 CC
字号:
/* * File: errors.cc * --------------- * Implementation for error-reporting class. */#include "errors.h"#include <iostream>#include <strstream>#include <stdarg.h>#include <stdio.h>#include "scanner.h" // for GetLineNumberedint ReportError::numErrors = 0;void ReportError::UnderlineErrorInLine(const char *line, yyltype *pos) {	using namespace std;    if (!line) return;    cerr << line << endl;    for (int i = 1; i <= pos->last_column; i++)        cerr << (i >= pos->first_column ? '^' : ' ');    cerr << endl;}  void ReportError::OutputError(yyltype *loc, const char *msg) {	using namespace std;    numErrors++;        fflush(stdout); // make sure any buffered text has been output    if (loc) {        cerr << endl << "*** Error line " << loc->first_line << "." << endl;        UnderlineErrorInLine(GetLineNumbered(loc->first_line), loc);    } else        cerr << endl << "*** Error." << endl;    cerr << "*** " << msg << endl << endl;}void ReportError::Formatted(yyltype *loc, const char *format, ...) {	using namespace std;    va_list args;    char errbuf[2048];        va_start(args, format);    vsprintf(errbuf,format, args);    va_end(args);    OutputError(loc, errbuf);}void ReportError::UntermComment() {	using namespace std;    OutputError(NULL, "Input ends with unterminated comment");}void ReportError::InvalidDirective(int linenum) {	using namespace std;    yyltype ll = {0, linenum, 0, 0};    OutputError(&ll, "Invalid # directive");}void ReportError::LongIdentifier(yyltype *loc, const char *ident) {	using namespace std;    ostrstream s;    s << "Identifier too long: \"" << ident << "\"" << '\0';    OutputError(loc, s.str());}void ReportError::UntermString(yyltype *loc, const char *str) {	using namespace std;    ostrstream s;    s << "Unterminated string constant: " << str << '\0';    OutputError(loc, s.str());}void ReportError::UnrecogChar(yyltype *loc, char ch) {	using namespace std;    ostrstream s;    s << "Unrecognized char: '" << ch << "'" << '\0';    OutputError(loc, s.str());}  /* Function: yyerror() * ------------------- * Standard error-reporting function expected by yacc. Our version merely * just calls into the error reporter above, passing the location of * the last token read. If you want to suppress the ordinary "parse error" * message from yacc, you can implement yyerror to do nothing and * then call ReportError::Formatted yourself with a more descriptive  * message. */void yyerror(char *msg) {    ReportError::Formatted(&yylloc, "%s", msg);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -