#include #include using namespace std; #include "include/input.h" #include "include/errors.h" #include "include/colors.h" #include "include/parser.h" #include "include/tokenize.h" #include "include/interpreter.h" #include "include/memory.h" int main(int argc, char* argv[]) { bool print_ast = false; int i=1; while (i < argc) { if (!strcmp(argv[i], "--show-ast") || !strcmp(argv[i], "-s")) { print_ast = true; } else { cerr << "Unknow argument: " << argv[i] << endl; } i++; } vector input; vector tokens; Memory memory; while (true) { try { int initial_line = input.size(); input = get_input(input); tokens = tokenize(input, initial_line); Node ast = parse(tokens); if (print_ast) _debug_print_tree(ast, 0, ""); EvalResult res = eval(ast, memory); if (holds_alternative(res)) { cout << get(res) << endl; } else if (holds_alternative(res)) { cout << get(res) << endl; } } catch (const SyntaxError& e) { pretty_print_error(input, e.pos); cout << BOLD RED "Syntax Error: " RESET << e.what() << endl; } catch (const RuntimeError& e) { pretty_print_error(input, e.pos); cout << BOLD RED "Runtime Error: " RESET << e.what() << endl; } catch (const ParseException& e) { cout << RED "ParsingError" RESET << endl; } cout << endl; } }