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

Slides:



Advertisements
Similar presentations
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
Advertisements

CPSC 388 – Compiler Design and Construction
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Programming Languages and Paradigms
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Java Review Interface, Casting, Generics, Iterator.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
1 Compiler Construction Intermediate Code Generation.
Chapter 2, Part 1: An interpreter architecture for C-like languages Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall 2010.
Slide 1 Vitaly Shmatikov CS 345 Functions. slide 2 Reading Assignment uMitchell, Chapter 7 uC Reference Manual, Chapters 4 and 9.
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
Prof. Fateman CS 164 Lecture 151 Language definition by interpreter, translator, continued Lecture 15.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there.
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
CS221 - Computer Science II Polymorphism 1 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Symbol Table (  ) Contents Map identifiers to the symbol with relevant information about the identifier All information is derived from syntax tree -
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
April 23, ICE 1341 – Programming Languages (Lecture #16) In-Young Ko Programming Languages (ICE 1341) Lecture #16 Programming Languages (ICE 1341)
COSC1030 DATA STRUCTURES IN JAVA. Important Notes Final drop date – July 13 Web site is our information center Check web site before raising questions.
Dr. Philip Cannata 1 Lexical and Syntactic Analysis Chomsky Grammar Hierarchy Lexical Analysis – Tokenizing Syntactic Analysis – Parsing Hmm Concrete Syntax.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
 Definition: Accessing child class methods through a parent object  Example: Child class overrides default parent class methods  Example: Child class.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
Programming in Java CSCI-2220 Object Oriented Programming.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Syntax (2).
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
CS212: Object Oriented Analysis and Design Lecture 11: Operator Overloading-I.
Introduction To Java Programming 1.0 Basic Concepts of Java Programming 2.0 Classes, Polymorphism and Inheritance 3.0 Exception handling 4.0.
Visitor-Based HMM Israel Perez, Fayz Rahman, Chinedu Egboh.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
1 Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Object-Oriented Design Chapter 7 1. Objectives You will be able to Use the this reference in a Java program. Use the static modifier for member variables.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Topic: Classes and Objects
Examples of Classes & Objects
AKA the birth, life, and death of variables.
CS 302 Week 11 Jim Williams, PhD.
Operator Overloading
CS345 Project Presentation
Interface.
Programming Languages 2nd edition Tucker and Noonan
Polymorphism.
Chapter 6 Intermediate-Code Generation
Classes & Objects: Examples
PZ09A - Activation records
AKA the birth, life, and death of variables.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
C++ Programming CLASS This pointer Static Class Friend Class
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Corresponds with Chapter 5
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

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

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

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 ] ] }

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

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 }

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

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

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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; }

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

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; }

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); }

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 =

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 =

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

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!

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

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

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

Questions