added ast generator

This commit is contained in:
StefanZ3 2024-05-10 06:23:09 +02:00
parent 484418e884
commit 91340125ef
4 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,21 @@
import abstractSyntaxTree.Class.IClass;
import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Node;
import abstractSyntaxTree.Program;
import gen.DecafBaseVisitor;
import gen.DecafParser;
import java.util.ArrayList;
import java.util.List;
public class ASTGenerator extends DecafBaseVisitor<Node> {
@Override
public Node visitProgram(DecafParser.ProgramContext ctx) {
List<RefType> classes = new ArrayList<>();
for (DecafParser.ClassdeclContext classDecl : ctx.classdecl()) {
Node refType = new RefType(classDecl.Identifier().getText(), new ArrayList<>(), new ArrayList<>());
classes.add((RefType) refType);
}
return new Program(classes);
}
}

View File

@ -1,7 +1,6 @@
import abstractSyntaxTree.Class.FieldDecl; import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Class.MethodDecl; import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Class.RefType; import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Node;
import abstractSyntaxTree.Program; import abstractSyntaxTree.Program;
import abstractSyntaxTree.Statement.BlockStatement; import abstractSyntaxTree.Statement.BlockStatement;
import gen.DecafLexer; import gen.DecafLexer;

View File

@ -0,0 +1,4 @@
package abstractSyntaxTree;
public interface Node {
}

View File

@ -3,7 +3,6 @@ package abstractSyntaxTree;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.FieldDecl; import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Class.MethodDecl; import abstractSyntaxTree.Class.MethodDecl;
import org.objectweb.asm.MethodVisitor;
import abstractSyntaxTree.Class.RefType; import abstractSyntaxTree.Class.RefType;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;