Change input type: string -> vector<string>
This commit is contained in:
parent
e9723fef07
commit
57439de0f7
@ -2,11 +2,12 @@
|
|||||||
#define DEF_INPUT_H
|
#define DEF_INPUT_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Retrieves user input
|
Retrieves user input
|
||||||
*/
|
*/
|
||||||
string get_input();
|
vector<string> get_input();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -6,9 +8,9 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
string get_input() {
|
vector<string> get_input() {
|
||||||
string buffer;
|
string buffer;
|
||||||
string input = "";
|
vector<string> input;
|
||||||
|
|
||||||
int line_num = 0;
|
int line_num = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -18,13 +20,14 @@ string get_input() {
|
|||||||
cout << "\rReceived EOF" << endl;
|
cout << "\rReceived EOF" << endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
input += "\n" + buffer;
|
|
||||||
|
|
||||||
int n = input.length();
|
int n = buffer.length();
|
||||||
if (n >= 2 && input[n-1] == ';' && input[n-2] == ';') {
|
if (n >= 2 && buffer[n-1] == ';' && buffer[n-2] == ';') {
|
||||||
input[n-1] = '\0';
|
buffer[n-1] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
|
@ -22,8 +22,9 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
string input = get_input();
|
vector<string> input = get_input();
|
||||||
vector<Token> tokens = tokenize(input);
|
vector<Token> tokens = tokenize(input);
|
||||||
|
|
||||||
Node ast = parse(tokens);
|
Node ast = parse(tokens);
|
||||||
|
|
||||||
if (print_ast)
|
if (print_ast)
|
||||||
@ -33,8 +34,8 @@ int main(int argc, char* argv[]) {
|
|||||||
cout << get<int>(res) << endl;
|
cout << get<int>(res) << endl;
|
||||||
} catch (const SyntaxError& e) {
|
} catch (const SyntaxError& e) {
|
||||||
cout << RED "SyntaxError: " RESET << e.what() << endl;
|
cout << RED "SyntaxError: " RESET << e.what() << endl;
|
||||||
} catch (const std::exception& e) { // temp
|
} catch (const ParseException& e) {
|
||||||
cout << RED "err: " RESET << e.what() << endl;
|
cout << RED "ParsingError" RESET << endl;
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user