36 lines
1.3 KiB
Java
36 lines
1.3 KiB
Java
import java.util.*;
|
|
|
|
import org.antlr.v4.runtime.*;
|
|
import org.antlr.v4.runtime.tree.*;
|
|
|
|
import de.hsrm.compiler.Klang.*;
|
|
import de.hsrm.compiler.Klang.helper.*;
|
|
import de.hsrm.compiler.Klang.nodes.*;
|
|
|
|
public class Helper {
|
|
public static ParseTree prepareParser(String input) {
|
|
CharStream inStream = CharStreams.fromString(input);
|
|
KlangLexer lexer = new KlangLexer(inStream);
|
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
KlangParser parser = new KlangParser(tokens);
|
|
return parser.parse();
|
|
}
|
|
|
|
public static Map<String, FunctionInformation> getFuncs(ParseTree tree) {
|
|
var functionDefinitions = new HashMap<String, FunctionInformation>();
|
|
new GetDefinitions(functionDefinitions, new HashMap<>(), new HashMap<>()).visit(tree);
|
|
return functionDefinitions;
|
|
}
|
|
|
|
public static Map<String, StructDefinition> getStructs(ParseTree tree) {
|
|
var structs = new HashMap<String, StructDefinition>();
|
|
new GetDefinitions(new HashMap<>(), structs, new HashMap<>()).visit(tree);
|
|
return structs;
|
|
}
|
|
|
|
public static Map<String, EnumDefinition> getEnums(ParseTree tree) {
|
|
var enums = new HashMap<String, EnumDefinition>();
|
|
new GetDefinitions(new HashMap<>(), new HashMap<>(), enums).visit(tree);
|
|
return enums;
|
|
}
|
|
} |