A simple scripting language in C++
Ferenc Szontágh
2025-04-18 e398a47fc9ef8ded356c56b5739808ce1192e3d2
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
62
63
64
65
66
67
68
69
#ifndef INTERPRETER_HPP
#define INTERPRETER_HPP
#include <iostream>
#include <memory>
#include <stdexcept>
 
#include "Interpreter/Operation.hpp"
#include "Interpreter/OperationContainer.hpp"
 
namespace Interpreter {
 
class Interpreter {
  private:
    void runOperation(const Operations::Operation & op) {
        std::cout << "Operation: " << op.toString() << "\n";
 
        switch (op.type) {
            case Operations::Type::Declaration:
                if (op.statement) {
                    op.statement->interpret(*this);
                }
                break;
            case Operations::Type::FuncDeclaration:
                {
                    op.statement->interpret(*this);
                }
                break;
 
            case Operations::Type::Assignment:
                {
                    op.statement->interpret(*this);
                    break;
                }
 
            case Operations::Type::Expression:
                {
                    op.statement->interpret(*this);  // csak side effect miatt
                    break;
                }
 
            case Operations::Type::FunctionCall:
            case Operations::Type::Return:
            case Operations::Type::Loop:
            case Operations::Type::Break:
            case Operations::Type::Continue:
            case Operations::Type::Block:
            case Operations::Type::Import:
            case Operations::Type::Error:
            case Operations::Type::Conditional:
                // TODO: implementálható később
                break;
            default:
                throw std::runtime_error("Not implemented operation type");
        }
    }
 
  public:
    Interpreter() {}
 
    void run() {
        for (const auto & operation : Operations::Container::instance()->getAll()) {
            runOperation(*operation);
        }
    }
 
};  // class Interpreter
 
}  // namespace Interpreter
#endif  // INTERPRETER_HPP