G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.

Slides:



Advertisements
Similar presentations
Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Advertisements

Arrays and records Programming Language Design and Implementation
Programming Languages and Paradigms
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Elementary Data Types Prof. Alamdeep Singh. Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general,
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Chapter Four Data Types Pratt 2 Data Objects A run-time grouping of one or more pieces of data in a virtual machine a container for data it can be –system.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Names, Bindings, Type Checking, and Scopes
ISBN Chapter 10 Implementing Subprograms.
ISBN Chapter 6 Data Types: Structured types.
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Elementary Data Types Scalar Data Types Numerical Data Types Other
Chapter 9: Subprogram Control
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
College of Computer Science and Engineering
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Basic Semantics Associating meaning with language entities.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
Programming Languages and Paradigms Imperative Programming.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
CS 330 Programming Languages 10 / 30 / 2007 Instructor: Michael Eckmann.
1 CS Programming Languages Class 08 September 19, 2000.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union Types.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
ISBN Chapter 10 Implementing Subprograms.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Implementing Subprograms
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
CS 326 Programming Languages, Concepts and Implementation
Chapter 6 – Data Types CSCE 343.
Chapter 6 Data Types.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
FORTRAN 04 February 1999; CS655.
Implementing Subprograms
Complex Data Types One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables Design.
Chapter 6 Data Types.
Arrays and records Programming Language Design and Implementation
Arrays and records Programming Language Design and Implementation
Abstract data types Programming Language Design and Implementation
Arrays and records Programming Language Design and Implementation
Arrays and records Programming Language Design and Implementation
Types and Related Issues
Implementing Subprograms
Presentation transcript:

G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier to read, write, modify Security – programmer cannot corrupt data –Primitive data types are encapsulated (Not entirely –Pascal variant record, C union, FORTRAN equivalence) # of bits or digits that implement numeric type perhaps needs to be known

G. Levine Chapter 6 User defined types Ability to define new type (Pascal, typedef) Orthogonality- same syntax and semantics for user defined types and primitive types –Ex: User defined and system defined integer should use infix operators Structured data types with complex relationships between potentially heterogeneous fields –Ex: Records of records, ptrs as components for recursive data structures Subprograms for defining functionality of new type Inheritance (chapt 7)

G. Levine Chapter 6 Attributes of structured types Number of components Type of each component Organization of components Names (i.e., index) for selecting components Is there a limit on the number of components (such as max stack size); is this limit a function of the compiler or hardware? Can the structure be changed dynamically? –Insertion/deletion of components

G. Levine Chapter 6 Operations on user defined types Are primitive operations available (i.e, succ, ++, WRITE); can they be defined to be used by same name (overloading), same form Primitive aggregate operations –APL – array aggregate operations –SNOBOL – string operations –LISP – list operations –Assignment of values of one to another (strcpy is library function) Component selection –Restrictions? Creation/ destruction of objects

G. Levine Chapter 6 Implementation- Storage Allocation –Allocate storage for components –Allocate storage (perhaps) for descriptor –Static or dynamic allocation of storage –Efficiency- use of hardware as possible –Sequential or linked storage allocation Sequential : Base address + offset –This is why C arrays begin with 0 Linked: follow chain of ptrs –How much can be done at compile time?

G. Levine Chapter 6 Implementation – Storage Mgt Issues Lifetime of a data object spans from allocation of storage (and value initialization) to deallocation of storage (binding) and the creation of an ACCESS PATH to it Data object may have several access paths –ptr1 := ptr2 (ptr assignment) –void copy (int &objects); (reference parameter) –array and array (0) (Array names) Storage management problems –Garbage - when all external access paths have been lost – Dangling references (ptrs) – when storage has been deallocated (data object is dead), but an access path to it still exists; storage may have been reassigned to another data object

G. Levine Chapter 6 Type checking for composite objects Composite type Number of dimensions (arrays) Number of components Type of each component Range of selection operator –Out-of-range run time hander? Operations on aggregate type –Ex: C’s string op if not terminated Operations between components

G. Levine Chapter 6 Implementation of vectors/arrays Homogeneity assumed Fixed size assumed (Pascal) –If size is not known at compile time, then array descriptor (dope vector) is allocated storage by compiler » (a) Base address of vector » LB » UB » component type » (E) component size (extend above for multiple dimensions) A(I) is stored at » a + (I-LB)*E – LB is always 0 in C –Where is the array stored?

G. Levine Chapter 6 Type equivalence How are two objects equivalent, say for assignment or parameter passing –Name equivalence Same type names –Cannot be any anonymous types »var W: array [1..10] of real; –Type must be declared globally Supports strong typing –Structural equivalence Assignment based on component(s) structure Does not support dimensional analysis Compare to coercion, casting

G. Levine Chapter 6 Semi-dynamic arrays Needed to create general purpose module for all sizes of arrays of that type –For example, vector addition –Need not give a maximum size nor allocate some maximum storage block –Programmer need not be concerned with keeping track of array size Values in dope vector can be assigned on module entry Storage for vector allocated on top of the stack

G. Levine Chapter 6 Packed and unpacked representations Packed structures save storage Since typically packed unit is not addressable, there is efficiency cost is unpacking Ex: Cobol packed decimals Ex: Pascal characters Ex: arrays of booleans

G. Levine Chapter 6 Associative arrays Subscripts are names Ex: Perl Declaration –%ClassList = (“Michelle”, ‘A’, “Doris”, ‘B’); Dereferencing –$ClassList {“Michelle”} // ‘A’ Stored in key alphabetic order for search

G. Levine Chapter 6 Implementation of records Attributes –Number of components –Type of each component –Selector (name) for each component Aggregate operations –Assignment Sequential storage allocation –Information available at compile time Records of composite types

G. Levine Chapter 6 Variant records Use as general purpose procedure Type checking (tag field present) discriminated union Free Union/ representation viewing Storage allocation –Maximum size –Size allocated by type Compare to inheritance with objects

G. Levine Chapter 6 Sets and Lists (LISP) Pascal sets are limited to bit representation for set membership –Operations of union, intersection, delection, insertion, deletion –Typically limited in size to machine word size SET-L has heterogeneous sets LISP has primitive List type –Program is also a list –(define myfunction (cons (a b c) (d e f ))) –Primitive list operations

G. Levine Chapter 6 Control Abstraction and encapsulation Functions and procedures –Information hiding Programmer defined abstraction mechanism –Need only inform user of function and interface –User cannot manipulate body of function Ignore FORTRAN’s multiple entries Ignore multiple exits –Ease of replacement of unit –Problems with global data and reference parameters –History sensitive (static) data

G. Levine Chapter 6 Data Abstraction and encapsulation All operations are defined for type User cannot access objects except through provided operations Selection operators must be provided Initialization must be provided Different method of breaking down complex system Solves global data problem Simplifies interface May simplify replacement of parts