From 416e88a071c9d091c3d868171cecb4bdd093b6b6 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Thu, 25 Apr 2024 23:35:21 -0600 Subject: Files I forgot to add --- boil/tests/ex49.java | 26 ++++++++++++++++++++++++++ boil/tests/ex50.java | 35 +++++++++++++++++++++++++++++++++++ st/SymTableExtend.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 boil/tests/ex49.java create mode 100644 boil/tests/ex50.java create mode 100644 st/SymTableExtend.java diff --git a/boil/tests/ex49.java b/boil/tests/ex49.java new file mode 100644 index 0000000..d28a887 --- /dev/null +++ b/boil/tests/ex49.java @@ -0,0 +1,26 @@ +class ex49 { + public static void main(String[] z) { + int result ; + A a ; + a = new A() ; + System.out.println(a.set()) ; + } +} + +class A { + + int b ; + + public int set() { + b = 3 ; + return 1 ; + } +} + +class B extends A { + + public int get() { + b = 12 ; + return b ; + } +} diff --git a/boil/tests/ex50.java b/boil/tests/ex50.java new file mode 100644 index 0000000..576af0e --- /dev/null +++ b/boil/tests/ex50.java @@ -0,0 +1,35 @@ +class ex50 { + public static void main(String[] z) { + int result ; + A a ; + a = new A() ; + System.out.println(a.set_get()) ; + } +} + +class A { + + B b ; + + public int set_get() { + int r ; + b = new B() ; + r = b.set() ; + r = b.get() ; + return r ; + } +} + +class B { + + int x ; + + public int get() { + return x ; + } + + public int set() { + x = 12 ; + return 1 ; + } +} diff --git a/st/SymTableExtend.java b/st/SymTableExtend.java new file mode 100644 index 0000000..2e634d8 --- /dev/null +++ b/st/SymTableExtend.java @@ -0,0 +1,44 @@ +package st; + +import syntaxtree.*; +import visitor.*; +import java.util.*; +import misc.*; + +/** + * Performs a bottom-up preliminary visit through the AST + * initializing all ClassInstances and placing them in the passed ST + */ +public class SymTableExtend extends GJDepthFirst { + + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public R visit(ClassExtendsDeclaration n, SymbolTable symt) { + String act = n.f1.f0.tokenImage; + symt.setActive(TypeEnum.classname, symt.getClass(act)); + n.f0.accept(this, symt); + n.f1.accept(this, symt); + n.f2.accept(this, symt); + n.f3.accept(this, symt); + n.f4.accept(this, symt); + n.f5.accept(this, symt); + n.f6.accept(this, symt); + n.f7.accept(this, symt); + + + symt.setExtend(n.f3.f0.tokenImage); + + + return null; + } + +} -- cgit v1.2.3