Merge branch 'main' of gitlab.aliens-lyon.fr:alucas03/c-repl into main

This commit is contained in:
ala89 2023-11-15 16:10:39 +01:00
commit 1a37e67b2c
6 changed files with 10 additions and 9 deletions

View File

@ -11,6 +11,7 @@ void pretty_print_error(vector<string> history, CodePosition pos) {
if (pos.column == -1 || pos.line == -1) if (pos.column == -1 || pos.line == -1)
return; return;
cout << endl;
string line = history[pos.line]; string line = history[pos.line];
printf(BOLD "%4d " RESET , pos.line+1); printf(BOLD "%4d " RESET , pos.line+1);

View File

@ -8,6 +8,6 @@ using namespace std;
/* /*
Retrieves user input Retrieves user input
*/ */
vector<string> get_input(); vector<string> get_input(vector<string> history);
#endif #endif

View File

@ -34,7 +34,7 @@ public:
/* /*
Parses a string into a vector of tokens Parses a string into a vector of tokens
*/ */
vector<Token> tokenize(vector<string> str); vector<Token> tokenize(vector<string> str, int initial_line=0);
/* /*
Format and print a Token Format and print a Token

View File

@ -8,11 +8,10 @@ using namespace std;
vector<string> get_input() { vector<string> get_input(vector<string> input) {
string buffer; string buffer;
vector<string> input;
int line_num = 0; int line_num = input.size();
while (1) { while (1) {
line_num++; line_num++;
printf(BOLD "%4d " RESET , line_num); printf(BOLD "%4d " RESET , line_num);

View File

@ -25,8 +25,9 @@ int main(int argc, char* argv[]) {
vector<Token> tokens; vector<Token> tokens;
while (true) { while (true) {
try { try {
input = get_input(); int initial_line = input.size();
tokens = tokenize(input); input = get_input(input);
tokens = tokenize(input, initial_line);
Node ast = parse(tokens); Node ast = parse(tokens);

View File

@ -64,10 +64,10 @@ void _debug_print_tokens(vector<Token> tokens) {
cout << endl; cout << endl;
} }
vector<Token> tokenize(vector<string> input) { vector<Token> tokenize(vector<string> input, int initial_line) {
vector<Token> tokens; vector<Token> tokens;
for (int i = 0; i < int(input.size()); i++) { for (int i = initial_line; i < int(input.size()); i++) {
string line = input[i]; string line = input[i];
int j = 0; int j = 0;