Created RunParser which is supposed the main class (still rather

experimental).
This commit is contained in:
Jakob Herrmann 2016-12-15 12:05:23 +01:00
parent 82a1e86186
commit 81e223334b

View File

@ -0,0 +1,31 @@
package de.dhbwstuttgart.parser;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import de.dhbwstuttgart.syntaxtree.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class RunParser{
public static void main(String[] args){
try{
String inputString = args[0];
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
ANTLRInputStream input = new ANTLRInputStream(stream);
Java8Lexer lexer = new Java8Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
ParserRuleContext tree = parser.compilationUnit();
ParseTreeWalker walker = new ParseTreeWalker();
CompilationUnitEvaluator eval = new CompilationUnitEvaluator();
walker.walk(eval, tree);
}
catch(Exception e){
System.out.println("An exception occured which is unknown and on our TODO list.");
e.printStackTrace();
}
}
}