blob: 3d19a8ccb601e38391962745f598baf813238ecd (
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
|
package com.jantuomi.interpreter.main.core.parser;
import com.jantuomi.interpreter.main.core.parser.ast.ASTNode;
import com.jantuomi.interpreter.main.core.tokenizer.token.Token;
import com.jantuomi.interpreter.main.exception.InterpreterException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jan on 16.6.2016.
*/
public class ASTGenerator {
private static final ASTGenerator instance = new ASTGenerator();
private ASTGenerator() {}
public static ASTGenerator getInstance() {
return instance;
}
public List<ASTNode> generate(List<Token> trees) throws InterpreterException {
List<ASTNode> list = new ArrayList<>();
for (Token root : trees) {
list.add(root.generateNode());
}
return list;
}
public void printTree(ASTNode root) {
System.out.println("### AST Tree begin ###");
root.print(0);
System.out.println("### AST Tree end ###");
}
public void printAllTrees(List<ASTNode> trees) {
for (ASTNode tree : trees) {
printTree(tree);
}
}
}
|