diff --git a/src/main/java/ASTGenerator.java b/src/main/java/ASTGenerator.java new file mode 100644 index 0000000..dc167ce --- /dev/null +++ b/src/main/java/ASTGenerator.java @@ -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 { + @Override + public Node visitProgram(DecafParser.ProgramContext ctx) { + List 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); + } +} diff --git a/src/main/java/Compiler.java b/src/main/java/Compiler.java index 4ec7a10..ff0aa5b 100644 --- a/src/main/java/Compiler.java +++ b/src/main/java/Compiler.java @@ -1,7 +1,6 @@ import abstractSyntaxTree.Class.FieldDecl; import abstractSyntaxTree.Class.MethodDecl; import abstractSyntaxTree.Class.RefType; -import abstractSyntaxTree.Node; import abstractSyntaxTree.Program; import abstractSyntaxTree.Statement.BlockStatement; import gen.DecafLexer; diff --git a/src/main/java/abstractSyntaxTree/Node.java b/src/main/java/abstractSyntaxTree/Node.java new file mode 100644 index 0000000..67475b0 --- /dev/null +++ b/src/main/java/abstractSyntaxTree/Node.java @@ -0,0 +1,4 @@ +package abstractSyntaxTree; + +public interface Node { +} diff --git a/src/main/java/abstractSyntaxTree/Program.java b/src/main/java/abstractSyntaxTree/Program.java index 6d7a733..e51d87a 100644 --- a/src/main/java/abstractSyntaxTree/Program.java +++ b/src/main/java/abstractSyntaxTree/Program.java @@ -3,7 +3,6 @@ package abstractSyntaxTree; import TypeCheck.TypeCheckResult; import abstractSyntaxTree.Class.FieldDecl; import abstractSyntaxTree.Class.MethodDecl; -import org.objectweb.asm.MethodVisitor; import abstractSyntaxTree.Class.RefType; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes;