Skip to content

Commit

Permalink
simple modification --> output filename on error --> parsing purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
S1810567023 committed Mar 17, 2020
1 parent b7e87c5 commit ed2e153
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ Parser::Parser(Scanner *scanner) {
minErrDist = 2;
errDist = minErrDist;
this->scanner = scanner;
errors = new Errors();
errors = new Errors(scanner->parseFileName);
}

bool Parser::StartOf(int s) {
Expand Down Expand Up @@ -830,8 +830,9 @@ Parser::~Parser() {
delete dummyToken;
}

Errors::Errors() {
Errors::Errors(char * FileName) {
count = 0;
file = FileName;
}

void Errors::SynErr(int line, int col, int n) {
Expand Down Expand Up @@ -898,18 +899,18 @@ void Errors::SynErr(int line, int col, int n) {
}
break;
}
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
coco_string_delete(s);
count++;
}

void Errors::Error(int line, int col, const wchar_t *s) {
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
count++;
}

void Errors::Warning(int line, int col, const wchar_t *s) {
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
}

void Errors::Warning(const wchar_t *s) {
Expand Down
14 changes: 8 additions & 6 deletions src/Parser.frame
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ Parser.h Specification
class Errors {
public:
int count; // number of errors detected
char * file;

Errors();
Errors(char * FileName);
void SynErr(int line, int col, int n);
void Error(int line, int col, const wchar_t *s);
void Warning(int line, int col, const wchar_t *s);
Expand Down Expand Up @@ -266,7 +267,7 @@ Parser::Parser(Scanner *scanner) {
minErrDist = 2;
errDist = minErrDist;
this->scanner = scanner;
errors = new Errors();
errors = new Errors(scanner->parseFileName);
}

bool Parser::StartOf(int s) {
Expand All @@ -284,8 +285,9 @@ Parser::~Parser() {
delete dummyToken;
}

Errors::Errors() {
Errors::Errors(char * FileName) {
count = 0;
file = FileName;
}

void Errors::SynErr(int line, int col, int n) {
Expand All @@ -300,18 +302,18 @@ void Errors::SynErr(int line, int col, int n) {
}
break;
}
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
coco_string_delete(s);
count++;
}

void Errors::Error(int line, int col, const wchar_t *s) {
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
count++;
}

void Errors::Warning(int line, int col, const wchar_t *s) {
wprintf(L"-- line %d col %d: %ls\n", line, col, s);
wprintf(L"%s -- line %d col %d: %ls\n", file, line, col, s);
}

void Errors::Warning(const wchar_t *s) {
Expand Down
3 changes: 2 additions & 1 deletion src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ namespace Coco {
class Errors {
public:
int count; // number of errors detected
char * file;

Errors();
Errors(char * FileName);
void SynErr(int line, int col, int n);
void Error(int line, int col, const wchar_t *s);
void Warning(int line, int col, const wchar_t *s);
Expand Down
2 changes: 2 additions & 0 deletions src/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ Scanner::Scanner(const unsigned char* buf, int len) {
Scanner::Scanner(const wchar_t* fileName) {
FILE* stream;
char *chFileName = coco_string_create_char(fileName);
parseFileName = coco_string_create_char(fileName);
if ((stream = fopen(chFileName, "rb")) == NULL) {
wprintf(L"--- Cannot open file %ls\n", fileName);
exit(1);
Expand All @@ -441,6 +442,7 @@ Scanner::~Scanner() {
free(firstHeap);
firstHeap = cur;
}
coco_string_delete(parseFileName);
delete [] tval;
delete buffer;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Scanner.frame
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public:
Token* Scan();
Token* Peek();
void ResetPeek();
char * parseFileName;

}; // end Scanner

Expand Down Expand Up @@ -689,6 +690,7 @@ Scanner::Scanner(const unsigned char* buf, int len) {
Scanner::Scanner(const wchar_t* fileName) {
FILE* stream;
char *chFileName = coco_string_create_char(fileName);
parseFileName = coco_string_create_char(fileName);
if ((stream = fopen(chFileName, "rb")) == NULL) {
wprintf(L"--- Cannot open file %ls\n", fileName);
exit(1);
Expand All @@ -711,6 +713,7 @@ Scanner::~Scanner() {
free(firstHeap);
firstHeap = cur;
}
coco_string_delete(parseFileName);
delete [] tval;
delete buffer;
}
Expand Down
1 change: 1 addition & 0 deletions src/Scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class Scanner {
Token* Scan();
Token* Peek();
void ResetPeek();
char * parseFileName;

}; // end Scanner

Expand Down

0 comments on commit ed2e153

Please sign in to comment.