diff --git a/src/Parser.cpp b/src/Parser.cpp index b8530e0..4f86319 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -35,6 +35,7 @@ void Parser::parse() { std::string currentValue; uint8_t c; currentValue.reserve(16); + uint32_t lineNumber = 1; std::vector>> states = { /* 0 */ {{Token::Type::Label, 1}, {Token::Type::Directive, 4}}, @@ -180,7 +181,7 @@ void Parser::parse() { if (!foundToken) { //TODO: ERROR - throw std::runtime_error("Could not find new Token state"); + throw std::runtime_error("Could not find new Token state, unexpected value = " + currentValue); } } @@ -212,6 +213,8 @@ void Parser::parse() { if (c == '\0') { functions.emplace_back(std::move(currentFunction)); break; + }else{ + lineNumber++; } } if (c == ';') { @@ -221,7 +224,7 @@ void Parser::parse() { currentValue += c; } }catch (const std::exception& e){ - std::cerr << "Exception: " << e.what() << " on " << currentFunction.label << "\n"; + std::cerr << "Exception: " << e.what() << " on " << currentFunction.label << " (line# " << std::dec << lineNumber << ")\n"; throw e; } } diff --git a/src/rrcas.cpp b/src/rrcas.cpp index 1909cc9..a34ee11 100644 --- a/src/rrcas.cpp +++ b/src/rrcas.cpp @@ -40,18 +40,23 @@ int main(int argc, char *argv[]) { } for (int inputIndex = 1; inputIndex < (argc - 1); ++inputIndex) { - std::ifstream image(argv[inputIndex]); - if (image.is_open()) { - std::vector bytes; - int c; - while (!image.eof() && (c = image.get()) != EOF) { - bytes.push_back(c); + try { + std::ifstream image(argv[inputIndex]); + if (image.is_open()) { + std::vector bytes; + int c; + while (!image.eof() && (c = image.get()) != EOF) { + bytes.push_back(c); + } + Parser parser(bytes, linker.getVariables()); + parser.parse(); + linker.addFromParser(parser); + } else { + throw std::runtime_error("Could not open " + std::string(argv[inputIndex])); } - Parser parser(bytes, linker.getVariables()); - parser.parse(); - linker.addFromParser(parser); - } else { - throw std::runtime_error("Could not open " + std::string(argv[inputIndex])); + }catch (const std::exception& e){ + std::cerr << "Exception: " << e.what() << " on input file " << argv[inputIndex] << "\n"; + return 1; } }