From fda4936771831605db13a3f7b5d85bb49db3998c Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 4 Oct 2026 18:09:43 +0000 Subject: refactor eval --- src/eval/eval.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/eval/eval.cc (limited to 'src/eval/eval.cc') diff --git a/src/eval/eval.cc b/src/eval/eval.cc new file mode 100644 index 0000000..83eccd7 --- /dev/null +++ b/src/eval/eval.cc @@ -0,0 +1,61 @@ +#include "eval.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "magic_enum/magic_enum.hpp" + +#include "error.h" +#include "lang_analysis/lexer_class.h" +#include "lang_analysis/ast.h" +#include "lang_analysis/token.h" +#include "handler.h" + +using namespace std; + +namespace ov4 +{ + +/* + * eval - Evaluate the command line that the user has just typed in + * + * If the user has requested a built-in command (quit, jobs, bg or fg) + * then execute it immediately. Otherwise, fork a child process and + * run the job in the context of the child. If the job is running in + * the foreground, wait for it to terminate and then return. Note: + * each child process must have a unique process group ID so that our + * background children don't receive SIGINT (SIGTSTP) from the kernel + * when we type ctrl-c (ctrl-z) at the keyboard. +*/ +void eval(char *raw_input) +{ + string s = raw_input; + T_lexer lexer_instance; + + try + { + lexer_instance.tokenizer(s); + lexer_instance.parse(0, lexer_instance.token.size(), lexer_instance.alloc_ast()); + } + catch(const T_error &e) + { + cerr << "Error: " << magic_enum::enum_name(e.code) << endl; + cerr << "what: " << e.what() << endl; + return; + } + + eval_tree_cd(0, lexer_instance, false); + return; +} + +} -- cgit v1.3.1-4-g156e