From 57439de0f7762367f5abf98fa766210bed241b91 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 15 Nov 2023 13:48:40 +0100 Subject: [PATCH] Change input type: string -> vector --- src/include/input.h | 3 ++- src/input.cpp | 15 +++++++++------ src/main.cpp | 7 ++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/include/input.h b/src/include/input.h index 1964eda..ebb5574 100644 --- a/src/include/input.h +++ b/src/include/input.h @@ -2,11 +2,12 @@ #define DEF_INPUT_H #include +#include using namespace std; /* Retrieves user input */ -string get_input(); +vector get_input(); #endif \ No newline at end of file diff --git a/src/input.cpp b/src/input.cpp index 00ace80..3eee323 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1,3 +1,5 @@ +#include +#include #include using namespace std; @@ -6,9 +8,9 @@ using namespace std; -string get_input() { +vector get_input() { string buffer; - string input = ""; + vector input; int line_num = 0; while (1) { @@ -18,13 +20,14 @@ string get_input() { cout << "\rReceived EOF" << endl; exit(0); } - input += "\n" + buffer; - int n = input.length(); - if (n >= 2 && input[n-1] == ';' && input[n-2] == ';') { - input[n-1] = '\0'; + int n = buffer.length(); + if (n >= 2 && buffer[n-1] == ';' && buffer[n-2] == ';') { + buffer[n-1] = '\0'; break; } + + input.push_back(buffer); } return input; diff --git a/src/main.cpp b/src/main.cpp index b6bd8c2..b9906fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,8 +22,9 @@ int main(int argc, char* argv[]) { while (true) { try { - string input = get_input(); + vector input = get_input(); vector tokens = tokenize(input); + Node ast = parse(tokens); if (print_ast) @@ -33,8 +34,8 @@ int main(int argc, char* argv[]) { cout << get(res) << endl; } catch (const SyntaxError& e) { cout << RED "SyntaxError: " RESET << e.what() << endl; - } catch (const std::exception& e) { // temp - cout << RED "err: " RESET << e.what() << endl; + } catch (const ParseException& e) { + cout << RED "ParsingError" RESET << endl; } cout << endl; }