From b01fe1e8e5541d6c11f905d7fbb949d747f29230 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Wed, 27 Mar 2024 22:53:08 -0600 Subject: SymbolTable to separate library, Class/Method Instances --- typecheck/library/PPrinter.java | 737 ---------------------------------------- 1 file changed, 737 deletions(-) delete mode 100644 typecheck/library/PPrinter.java (limited to 'typecheck/library/PPrinter.java') diff --git a/typecheck/library/PPrinter.java b/typecheck/library/PPrinter.java deleted file mode 100644 index e8e1b15..0000000 --- a/typecheck/library/PPrinter.java +++ /dev/null @@ -1,737 +0,0 @@ -package typecheck.library; - -import syntaxtree.*; -import visitor.*; -import java.util.*; - -/** - * Provides default methods which visit each node in the tree in depth-first - * order. Your visitors may extend this class. - */ -public class PPrinter extends GJDepthFirst { - - private int offset; - - private void printNode(Node n, A argu) { - for (int i=0; i < this.offset; ++i) - Utilities.print_filter(".", false); - Utilities.print_filter(n.getClass().getSimpleName(), true); - ++this.offset; - } - - // - // User-generated visitor methods below - // - - /** - * f0 -> MainClass() - * f1 -> ( TypeDeclaration() )* - * f2 -> - */ - public R visit(Goal n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "{" - * f3 -> "public" - * f4 -> "static" - * f5 -> "void" - * f6 -> "main" - * f7 -> "(" - * f8 -> "String" - * f9 -> "[" - * f10 -> "]" - * f11 -> Identifier() - * f12 -> ")" - * f13 -> "{" - * f14 -> ( VarDeclaration() )* - * f15 -> ( Statement() )* - * f16 -> "}" - * f17 -> "}" - */ - public R visit(MainClass n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.accept(this, argu); - n.f7.accept(this, argu); - n.f8.accept(this, argu); - n.f9.accept(this, argu); - n.f10.accept(this, argu); - n.f11.accept(this, argu); - n.f12.accept(this, argu); - n.f13.accept(this, argu); - n.f14.accept(this, argu); - n.f15.accept(this, argu); - n.f16.accept(this, argu); - n.f17.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> ClassDeclaration() - * | ClassExtendsDeclaration() - */ - public R visit(TypeDeclaration n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "{" - * f3 -> ( VarDeclaration() )* - * f4 -> ( MethodDeclaration() )* - * f5 -> "}" - */ - public R visit(ClassDeclaration n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "class" - * f1 -> Identifier() - * f2 -> "extends" - * f3 -> Identifier() - * f4 -> "{" - * f5 -> ( VarDeclaration() )* - * f6 -> ( MethodDeclaration() )* - * f7 -> "}" - */ - public R visit(ClassExtendsDeclaration n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.accept(this, argu); - n.f7.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Type() - * f1 -> Identifier() - * f2 -> ";" - */ - public R visit(VarDeclaration n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "public" - * f1 -> Type() - * f2 -> Identifier() - * f3 -> "(" - * f4 -> ( FormalParameterList() )? - * f5 -> ")" - * f6 -> "{" - * f7 -> ( VarDeclaration() )* - * f8 -> ( Statement() )* - * f9 -> "return" - * f10 -> Expression() - * f11 -> ";" - * f12 -> "}" - */ - public R visit(MethodDeclaration n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.accept(this, argu); - n.f7.accept(this, argu); - n.f8.accept(this, argu); - n.f9.accept(this, argu); - n.f10.accept(this, argu); - n.f11.accept(this, argu); - n.f12.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> FormalParameter() - * f1 -> ( FormalParameterRest() )* - */ - public R visit(FormalParameterList n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Type() - * f1 -> Identifier() - */ - public R visit(FormalParameter n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "," - * f1 -> FormalParameter() - */ - public R visit(FormalParameterRest n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> ArrayType() - * | BooleanType() - * | IntegerType() - * | Identifier() - */ - public R visit(Type n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "int" - * f1 -> "[" - * f2 -> "]" - */ - public R visit(ArrayType n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "boolean" - */ - public R visit(BooleanType n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "int" - */ - public R visit(IntegerType n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Block() - * | AssignmentStatement() - * | ArrayAssignmentStatement() - * | IfStatement() - * | WhileStatement() - * | PrintStatement() - */ - public R visit(Statement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "{" - * f1 -> ( Statement() )* - * f2 -> "}" - */ - public R visit(Block n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Identifier() - * f1 -> "=" - * f2 -> Expression() - * f3 -> ";" - */ - public R visit(AssignmentStatement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Identifier() - * f1 -> "[" - * f2 -> Expression() - * f3 -> "]" - * f4 -> "=" - * f5 -> Expression() - * f6 -> ";" - */ - public R visit(ArrayAssignmentStatement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "if" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> Statement() - * f5 -> "else" - * f6 -> Statement() - */ - public R visit(IfStatement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - n.f6.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "while" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> Statement() - */ - public R visit(WhileStatement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "System.out.println" - * f1 -> "(" - * f2 -> Expression() - * f3 -> ")" - * f4 -> ";" - */ - public R visit(PrintStatement n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> AndExpression() - * | CompareExpression() - * | PlusExpression() - * | MinusExpression() - * | TimesExpression() - * | ArrayLookup() - * | ArrayLength() - * | MessageSend() - * | PrimaryExpression() - */ - public R visit(Expression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "&&" - * f2 -> PrimaryExpression() - */ - public R visit(AndExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "<" - * f2 -> PrimaryExpression() - */ - public R visit(CompareExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "+" - * f2 -> PrimaryExpression() - */ - public R visit(PlusExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "-" - * f2 -> PrimaryExpression() - */ - public R visit(MinusExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "*" - * f2 -> PrimaryExpression() - */ - public R visit(TimesExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "[" - * f2 -> PrimaryExpression() - * f3 -> "]" - */ - public R visit(ArrayLookup n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "." - * f2 -> "length" - */ - public R visit(ArrayLength n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> PrimaryExpression() - * f1 -> "." - * f2 -> Identifier() - * f3 -> "(" - * f4 -> ( ExpressionList() )? - * f5 -> ")" - */ - public R visit(MessageSend n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - n.f5.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> Expression() - * f1 -> ( ExpressionRest() )* - */ - public R visit(ExpressionList n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "," - * f1 -> Expression() - */ - public R visit(ExpressionRest n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> IntegerLiteral() - * | TrueLiteral() - * | FalseLiteral() - * | Identifier() - * | ThisExpression() - * | ArrayAllocationExpression() - * | AllocationExpression() - * | NotExpression() - * | BracketExpression() - */ - public R visit(PrimaryExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> - */ - public R visit(IntegerLiteral n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "true" - */ - public R visit(TrueLiteral n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "false" - */ - public R visit(FalseLiteral n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> - */ - public R visit(Identifier n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "this" - */ - public R visit(ThisExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "new" - * f1 -> "int" - * f2 -> "[" - * f3 -> Expression() - * f4 -> "]" - */ - public R visit(ArrayAllocationExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - n.f4.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "new" - * f1 -> Identifier() - * f2 -> "(" - * f3 -> ")" - */ - public R visit(AllocationExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - n.f3.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "!" - * f1 -> Expression() - */ - public R visit(NotExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - --this.offset; - return _ret; - } - - /** - * f0 -> "(" - * f1 -> Expression() - * f2 -> ")" - */ - public R visit(BracketExpression n, A argu) { - this.printNode(n, argu); - R _ret=null; - n.f0.accept(this, argu); - n.f1.accept(this, argu); - n.f2.accept(this, argu); - --this.offset; - return _ret; - } - - public R visit(NodeToken n, A argu) { - for (int i=0; i < this.offset; ++i) - Utilities.print_filter(".", false); - Utilities.print_filter(n.getClass().getSimpleName() + - " => " + - n.toString(), true); - R _ret=null; - return _ret; - } - -} -- cgit v1.2.3