forked from JavaTX/JavaCompilerCore
Beispiel für ANTLR Parser
This commit is contained in:
parent
c34b3c4c14
commit
40ba5fb621
@ -22,9 +22,8 @@ public class RunParser{
|
||||
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);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(null);
|
||||
generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||
|
29
src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java
Normal file
29
src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java
Normal file
@ -0,0 +1,29 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SyntaxTreeGenerator {
|
||||
|
||||
public SyntaxTreeGenerator(JavaClassRegistry nameReg){
|
||||
//TODO: Implement
|
||||
}
|
||||
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||
List<Class> classes = new ArrayList<>();
|
||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
Class newClass = convert(typeDecl.classDeclaration());
|
||||
classes.add(newClass);
|
||||
}
|
||||
return new SourceFile(classes);
|
||||
}
|
||||
|
||||
private Class convert(Java8Parser.ClassDeclarationContext ctx) {
|
||||
//TODO: Implement
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user