added ast generator
This commit is contained in:
parent
484418e884
commit
91340125ef
21
src/main/java/ASTGenerator.java
Normal file
21
src/main/java/ASTGenerator.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
4
src/main/java/abstractSyntaxTree/Node.java
Normal file
4
src/main/java/abstractSyntaxTree/Node.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package abstractSyntaxTree;
|
||||||
|
|
||||||
|
public interface Node {
|
||||||
|
}
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user