Change input type: string -> vector<string>
This commit is contained in:
parent
e9723fef07
commit
57439de0f7
@ -2,11 +2,12 @@
|
||||
#define DEF_INPUT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Retrieves user input
|
||||
*/
|
||||
string get_input();
|
||||
vector<string> get_input();
|
||||
|
||||
#endif
|
@ -1,3 +1,5 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
@ -6,9 +8,9 @@ using namespace std;
|
||||
|
||||
|
||||
|
||||
string get_input() {
|
||||
vector<string> get_input() {
|
||||
string buffer;
|
||||
string input = "";
|
||||
vector<string> 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;
|
||||
|
@ -22,8 +22,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
string input = get_input();
|
||||
vector<string> input = get_input();
|
||||
vector<Token> tokens = tokenize(input);
|
||||
|
||||
Node ast = parse(tokens);
|
||||
|
||||
if (print_ast)
|
||||
@ -33,8 +34,8 @@ int main(int argc, char* argv[]) {
|
||||
cout << get<int>(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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user