Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 345 Project Presentation OOH A More Object-Oriented Hmm++ Alysha Behn Jesse Vera.

Similar presentations


Presentation on theme: "CS 345 Project Presentation OOH A More Object-Oriented Hmm++ Alysha Behn Jesse Vera."— Presentation transcript:

1 CS 345 Project Presentation OOH A More Object-Oriented Hmm++ Alysha Behn Jesse Vera

2 Project Overview: Hmm++ Revise existing BNF to facilitate inheritance and instanceof syntax Near-complete revision of runtime stack usage Add an object-oriented feature: inheritance

3 BNF: what existed previously Program : {[ Declaration ]|retType Identifier Function | MyClass | MyObject} Function : ( ) Block MyClass: Class Idenitifier { {retType Identifier Function}Constructor {retType Identifier Function } } MyObject: Identifier Identifier = create Identifier callArgs Constructor: Identifier ([{ Parameter } ]) block Declaration : Type Identifier [ [Literal] ]{, Identifier [ [ Literal ] ] }

4 BNF: what existed previously Type : int|bool| float | list |tuple| object | string | void Statements : { Statement } Statement : ; | Declaration| Block |ForEach| Assignment |IfStatement|WhileStatement|CallStatement|ReturnStat ement Block : { Statements } ForEach: for( Expression <- Expression ) Block Assignment : Identifier [ [ Expression ] ]= Expression ; Parameter : Type Identifier

5 BNF: what existed previously IfStatement: if ( Expression ) Block Expression : Conjunction {|| Conjunction } Conjunction : Equality {&&Equality } Equality : Relation [EquOp Relation ] EquOp: == | != Relation : Addition [RelOp Addition ] RelOp: |>= Addition : Term {AddOp Term }

6 BNF: what existed previously AddOp: + | - Term : Factor {MulOp Factor } MulOp: * | / | % Factor : [UnaryOp]Primary UnaryOp: - | !

7 Changes to BNF RelOp: |>= → RelOp: |>= instanceof MyClass: Class Identifier { {retType Identifier Function} Constructor {retType Identifier Function } } → MyClass: Class Identifier {extends Identifier} { {retType Identifier Function} Constructor {retType Identifier Function } } ObjFunc : Class Dot MyObject Dot Function ( ) Block → ObjFunc : MyObject Dot Function ( ) Block

8 Revising stack Old Stack //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

9 Revising stack Old Stack //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

10 Revising stack Old Stack param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

11 Revising stack Old Stack myY myX param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

12 Revising stack Old Stack Y = 4 myY X = 20 myX param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

13 Revising stack Old Stack var result myY myX param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; thing.fun(num); return result; }

14 Revising stack Old Stack var value var result arg num myY fun::ret myX param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

15 Revising stack Old Stack var value var result arg num myY fun::ret myX param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

16 Revising stack New Stack //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

17 Revising stack New Stack //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

18 Revising stack New Stack param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

19 Revising stack New Stack myY myX thing param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

20 Revising stack New Stack y = 4 x = 20 myY myX thing param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

21 Revising stack New Stack var result myY myX thing param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

22 Revising stack New Stack arg num fun::ret var result myY myX thing param num foo::ret //Main calls foo int foo(int num) { Obj thing = create Obj(20, 4); int result = 0; result = thing.fun(num); return result; }

23 Changes for inheritance MyClasses ”point” to their parent classes MyClass copy parent data in constructor MyObjects keep track of runtime type and compileTime type MyObjects treated like a variable, placed on the stack Instance Variables referenced by an offset of their object

24 Demo continued int main() { int x = foo(); println( "It worked!" ); } int foo() int temp = 0; Test objOne = create Test(20, 4); temp = objOne.fun(2); Test_2 objTwo = create Test_2(15); temp = objTwo.fun_2(); temp = objOne.fun(7); return temp; }

25 Inheritance : Demo Class Test{ int myX; int myY; Test(int x, int y){ myX = x; myY = y; } int fun (int match){ println("The result from method fun is: "); println(myX); println(myY); int value = myX + myY; return value; } Class Test_2 extends Test{ Test(int x){ myY = 5; myX = x; } int fun_2(){ println("the result from method fun_2 is: "); println(myX); println(myY); return (myX + myY); }

26 Demo abstract syntax tree Program (abstract syntax): Function = main; Return type = int params = Block: int x = Call: foo, stackOffset=2 args = Call: println, stackOffset=0 args = StringValue: It worked! Function = foo; Return type = int params = Block: int temp = IntValue: 0 Object = objOne; Object type = Test args = IntValue: 20 IntValue: 4 Assignment: Variable: temp, LOCAL addr=1 Object Function = objOne; Function Name = fun args = IntValue: 2 Object = objTwo; Object type = Test_2 args = IntValue: 15 Assignment: Variable: temp, LOCAL addr=1 Object Function = objTwo; Function Name = fun_2 args =

27 Abstract syntax Tree cont. Assignment: Variable: temp, LOCAL addr=1 Object Function = objOne; Function Name = fun args = IntValue: 7 Return: Variable: return#foo, LOCAL addr=0 Variable: temp, LOCAL addr=1 Class: Test int myX int myY Function = fun; Return type = int params = int match Block: Call: println, stackOffset=0 args = StringValue: The result from method fun is: Call: println, stackOffset=0 args = Variable: myX, INSTANCE addr=1 Call: println, stackOffset=0 args = Variable: myY, INSTANCE addr=2 int value =

28 Abstract syntax Tree cont. args = Variable: myX, INSTANCE addr=1 Call: println, stackOffset=0 args = Variable: myY, INSTANCE addr=2 Return: Variable: return#fun_2, LOCAL addr=8 Binary: Operator: INT+ Variable: myX, INSTANCE addr=1 Variable: myY, INSTANCE addr=2 Constructor = Test params = int x Block: Assignment: Variable: myY, INSTANCE addr=2 IntValue: 5 Assignment: Variable: myX, INSTANCE addr=1 Variable: x, LOCAL addr=8

29 Demo output The result from method fun is: 20 4 the result from method fun_2 is: 15 5 The result from method fun is: 20 4 It worked!

30 Changes to AbstractSyntax.java Modified the class MyObject to extend Value instead of Statement to help treat MyObjects like variable Each object gets individual copies of class data MyClass extends Value and implements Type to compute instanceof Instanceof is added to the enum of Operators

31 StaticTypeChecker/SymbolTable Beyond checking types of assignments, these classes set the static offsets for referencing data within a scope Calling a constructor now creates a new scope Instance variables no longer remain in the scope indefinitely Calls to functions now account for local variables when moving the stack pointer

32 Interpreter Interface with the stack is brand new Global map of objects and their instances Special interpretation of variables used for instanceof

33 Questions


Download ppt "CS 345 Project Presentation OOH A More Object-Oriented Hmm++ Alysha Behn Jesse Vera."

Similar presentations


Ads by Google