aboutsummaryrefslogtreecommitdiff
path: root/src/eval/eval.cc
blob: 1551d1ab2df4c29323f47a4d560edc5176274f85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include "eval.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <iostream>
#include <vector>
#include <string>

#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 "signal_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;
}

}