From ed2e153982bcaa4b673aa2930581a4270db2ea05 Mon Sep 17 00:00:00 2001 From: S1810567023 Date: Tue, 17 Mar 2020 15:45:39 +0100 Subject: [PATCH] simple modification --> output filename on error --> parsing purpose --- src/Parser.cpp | 11 ++++++----- src/Parser.frame | 14 ++++++++------ src/Parser.h | 3 ++- src/Scanner.cpp | 2 ++ src/Scanner.frame | 3 +++ src/Scanner.h | 1 + 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index ce0f16e..da7b397 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -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) { @@ -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) { @@ -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) { diff --git a/src/Parser.frame b/src/Parser.frame index 85bd8b5..b40b866 100644 --- a/src/Parser.frame +++ b/src/Parser.frame @@ -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); @@ -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) { @@ -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) { @@ -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) { diff --git a/src/Parser.h b/src/Parser.h index c02102d..5c0d202 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -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); diff --git a/src/Scanner.cpp b/src/Scanner.cpp index d58d8f7..0ef14db 100644 --- a/src/Scanner.cpp +++ b/src/Scanner.cpp @@ -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); @@ -441,6 +442,7 @@ Scanner::~Scanner() { free(firstHeap); firstHeap = cur; } + coco_string_delete(parseFileName); delete [] tval; delete buffer; } diff --git a/src/Scanner.frame b/src/Scanner.frame index 0c36f7b..489739d 100644 --- a/src/Scanner.frame +++ b/src/Scanner.frame @@ -283,6 +283,7 @@ public: Token* Scan(); Token* Peek(); void ResetPeek(); + char * parseFileName; }; // end Scanner @@ -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); @@ -711,6 +713,7 @@ Scanner::~Scanner() { free(firstHeap); firstHeap = cur; } + coco_string_delete(parseFileName); delete [] tval; delete buffer; } diff --git a/src/Scanner.h b/src/Scanner.h index b183771..a5d55be 100644 --- a/src/Scanner.h +++ b/src/Scanner.h @@ -281,6 +281,7 @@ class Scanner { Token* Scan(); Token* Peek(); void ResetPeek(); + char * parseFileName; }; // end Scanner