Persistent line number

This commit is contained in:
augustin64 2023-11-15 16:07:50 +01:00
parent a57b759af9
commit 84e344a970
5 changed files with 9 additions and 9 deletions

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;