aboutsummaryrefslogtreecommitdiffstats
path: root/main/core/runtime/Interpreter.java
blob: 0789822b704f67b07800b853f80310cb9c6499e0 (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
package com.jantuomi.interpreter.main.core.runtime;

import com.jantuomi.interpreter.main.core.parser.ast.ASTNode;
import com.jantuomi.interpreter.main.core.parser.datatype.DataContainer;
import com.sun.deploy.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jan on 14.6.2016.
 */
public class Interpreter {
    private static final Interpreter instance = new Interpreter();

    public static Interpreter getInstance() {
        return instance;
    }

    private Interpreter() {

    }
    public static String execute(List<ASTNode> sequence) {
        List<String> output = new ArrayList<>();
        for (ASTNode node : sequence) {
            DataContainer data = node.evaluate();

            if (data != null) {
                String out = data.toString();
                output.add(out);
            } else {
                break;
            }
        }
        return StringUtils.join(output, " ");
    }
}