Cho, Joonmyun 18-10-7

Concepts of Programming Languages

Data Types

Primitive Data Types

Names, Bindings, Type Checking and Scope

Introduction

The Concepts of Binding

Type Checking

Scope

Subprograms

General Subprogram Characteristics

Basic Deginition

Design Issues for Subprograms

Support for Object-oriented Programming

Inheritance

Polymorphism and Dynamic Binding

Computing with an Object-oriented Language

Design Issues for Object_oriented Languages

Overview of Smalltalk

Data Types

It is convenient, both logically and concretely, to think of variables in terns of descriptors. A descriptor is the collections of the attributes of a variable.

In an implementation, a descriptor is a collection of memory cells that store variable attributes.

If the attributes are all static, descriptors are required only at compile time. They are built by the compiler, usually as a part of the symbol table, and are used during compilation.

For dynamic attributes, however, part or all of the descriptor must be maintained during execution. In this case, the descriptor is used by the run-time system

In all case, descriptors are used for type checking and by allocation and deallocation operation.

Primitive Data Types

Integer

Floatin-point

Decimal

boolean

character

Character String Type

User-defined Ordinal Type

enumeration

subrange

Array Types

Associative Arrays

Record Types

Union Types

Set Types

Pointer Types

Reference Types

Names, Bindings, Type Checking and Scope

Introduction

Imperative programming languages are, to varying degree, abstractions of the underlying von Neumann computer architecture. The architecture’s two primary components are its memory, which stores both instructions and data, and its processor, which provides operations for modifying the contests of the memory

The abstractions in a language for the memory cells of the machine are variables

The Concepts of Binding

A variables can be characterized as a sextuple of attributes:

(name, address, value, type, lifetime, scope, …)

Binding can take place at language design time, language implementation time, compile time, link time, load time, or run time.

A binding is static if it occurs before run time and remains unchanged throughout program execution. If it occurs during run time or can change in the course of program execution, it is called dynamic.

Type Binding

  • Static Type Binding
  • Dynamic Type Binding

Storage Binding and Lifetime

The fundamental character of a programming language is in large part determined by the design of the storage bindings for its variables.

Allocation and Deallocation

The lifetime of a variable is the time during which the variable is bound to a specific memory location.

It is convenient to separate scalar(unstructured) variables into four categories, according to their lifetimes;

static, stack-dynamic, explicit heap-dynamic, implicit heap-dynamic

Static Variables

Static variables are those that are bound to memory cells before program execution begins and remain bound to those same memory cell until program execution terminates

Stack-dynamic Variables

Stack-dynamic variables are those whose storage bindings are created when their declaration statements are elaborated, but whose types are statically bound.

Explicit Heap-dynamic Variables

Explicit heap-dynamic variables are nameless(abstract) memory cells that are allocated and deallocated by explicit run-time instructions specified by the programmer. These variables can only be referenced through pointer or reference variables.

Implicit Heap-dynamic Variables

Implicit heap-dynamic variables are bound to heap storage only when they are assigned values. In fact all their attributes are bound everytime they are assigned.

Type Checking

Type checking is the activity of ensuring that the operands of an operator are of compatible type. A compatible type is one that is either legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type.

Strong Typing

A strong typed language is one in which each name in a program in a language has single type associated with it, and that type is known at compile time. The essence of this definition is that all types are statically bound.

Type Compatibility

Perhaps the most important result of two variables being compatible type is that either one can have its value assigned to the other

There are two different type compatibility methods: name compatibility and structure compatibility

Scope

The scope of a program variable is the range of statements in which the variable is visible. A variable is visible in a statement if it can be referenced in that statement.

Static Scope

Static scoping is named because the scope of a variable can be statically determined, that is, prior to execution

Most individual static scopes in imperative languages are associated with program unit definitions

Dynamic Scope

Dynamic scoping is based on the calling sequence of subprograms, not on their spatial relationship to each other. Thus the scope can be determined only at run time.

Referencing Environments

The referencing environment of a statement is the collection of all names that are visible in the statement.

In a static-scoped language, the referencing environment of a statement is needed while that statement is being compiled, so code and data structures can be created to allow references to variables from other scope during run time.

Subprograms

Two fundamental abstraction facilities can be included in a programming language:

process abstraction and data abstraction

General Subprogram Characteristics

All subprograms, except the coroutines, have the following characteristics:

  • Each subprogram has a single entry point
  • The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time.
  • Control always returns to the caller when the subprogram execution terminates.

Basic Deginition

Subprogram Definition

Subprogram Call

Subprogram Header

Design Issues for Subprograms

  • What parameter-passing method or methods are used?
  • Are the types of the actual parameters checked against the types of the formal parameters?
  • Are local variables statically or dynamically allocated?
  • If subprograms can be passed as parameters, what is the referencing environment of such a subprogram?
  • If subprograms can be passed as parameters, are the types of parameters checked in calls to the passed subprograms?
  • Can subprogram definitions appear in other subprogram definitions?
  • Can subprograms be overloaded?
  • Can subprograms be generic?
  • Is either separate or independent compilation possible?

Support for Object-oriented Programming

A language that is object-oriented must provide support for three key language features:

abstract data types, inheritance, dynamic binding

Inheritance

The problem with the reuse of abstract data types in that, in nearly all cases, the features and capabilities of the existing type are not quite right for the new use.

A second problem with data oriented programming is that all abstract data type definitions are independent and are not at the same level.

Polymorphism and Dynamic Binding

The third characteristic of object-oriented programming languages is a kind of polymorphism provided by the dynamic binding of messages to method definitions. This is supported by allowing one to define polymorphic variables of the type of the parent class that are also able to reference objects of any of the subclasses of that class.

Computing with an Object-oriented Language

all computing in a pure object-oriented language is done by the same uniform technique:

sending a message to an object to invoke one of its methods

Design Issues for Object_oriented Languages

  • the exclusivity of objects
  • Are subclasses subtypes?
  • Implementation and interface inheritance
  • Type checking and polymorphism
  • Single and multiple inheritance
  • allocation and deallocation of objects
  • dynamic and static binding

Overview of Smalltalk

1/6