Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Names and Bindings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 5 Names, Bindings, and Scopes
Chapter 7:: Data Types Programming Language Pragmatics
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 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.
Compiler Construction
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Names, Bindings, Type Checking, and Scopes
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
The Concept of Variables
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Elementary Data Types Scalar Data Types Numerical Data Types Other
Chapter 9: Subprogram Control
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
CS 330 Programming Languages 10 / 21 / 2008 Instructor: Michael Eckmann.
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
1 CS Programming Languages Class 07 September 14, 2000.
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.
CSI 3125, Names etc., page 1 Names, binding, scope, type checking Names, variables Binding Scope Constants. Variable initialization Type checking Plan.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
Programming Languages and Paradigms Imperative Programming.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
PZ06C Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06C - Polymorphism Programming Language Design and.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
CS 330 Programming Languages 10 / 30 / 2007 Instructor: Michael Eckmann.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
ISBN Variables, Names, Scope and Lifetime ICOM 4036 Lecture 9.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Names, Scope, and Bindings Programming Languages and Paradigms.
Names, Bindings, Type Checking and Scopes. Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Object Lifetime and Pointers
Chapter 9: Value-Returning Functions
Data Types In Text: Chapter 6.
Chapter 4 Variables & Binding
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
Lecture 4: Type Systems.
Chapter 5 Names, Bindings, Type Checking, and Scopes.
Chapter 5 Names, Bindings, Type Checking, and Scopes.
Subprograms and Programmer Defined Data Type
Names and Binding In Text: Chapter 5.
Types and Related Issues
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment and initialization

Data Objects a run-time grouping of one or more pieces of data in a virtual computer. a location in memory with an assigned name in the actual computer. Programmer defined data objects System defined data objects

Concepts Data value: a bit pattern that is recognized by the computer. Elementary data object: contains a data value that is manipulated as a unit. Data structure: a combination of data objects. Attributes: determine how the location may be used. Most important attribute - the data type.

Attributes and Bindings Type: determines the set of data values that the object may take and the applicable operations. Name: the binding of a name to a data object. Component: the binding of a data object to one or more data objects. These attributes are bound at translation

Attributes and Bindings Location: the storage location in memory assigned by the system (bound at loading) Value: the assignment of a bit pattern to a name (bound at execution)

Variables and Constants In programs, data objects are represented as variables and constants Variables : Data objects defined and named by the programmer explicitly.

Variables and Constants Constants: Data objects with a name that is permanently bound to a value for its lifetime. Literals: constants whose name is the written representation of their value. A programmer-defined constant : the name is chosen by the programmer in a definition of data object. Persistence: existence of data beyond run time

Data Types A data type is a class of data objects with a set of operations for creating and manipulating them. Examples of elementary data types: integer, real, character, Boolean, enumeration, pointer.

Specification of a data type Attributes Values Operations

Attributes Distinguish data objects of a given type Data type and name - invariant during the lifetime of the object Approaches: stored in a descriptor and used during the program execution used only to determine the storage representation, not used explicitly during execution

Values The data type determines the values that a data object of that type may have Specification: Usually an ordered set, i.e. it has a least and a greatest value

Operations Operations define the possible manipulations of data objects of that type. Primitive - specified as part of the language definition Programmer-defined (as subprograms, or class methods)

Operations An operation is defined by: · Domain - set of possible input arguments · Range - set of possible results · Action - how the result is produced

Operation signature Specifies the domain and the range the number, order and data types of the arguments in the domain, the number, order and data type of the resulting range mathematical notation for the specification: op name: arg type x arg type x … x arg type  result type The action is specified in the operation implementation

Sources of ambiguity in operations Undefined operations for certain inputs. Implicit arguments, e.g. use of global variables Implicit results - the operation may modify its arguments Self-modification - usually through change of local data between calls, e.g. random number generators change the seed.

Implementation of a data type Storage representation Implementation of operations

Storage representation Influenced by the hardware Described in terms of: Size of the memory blocks required Layout of attributes and data values within the block

Methods to treat attributes a determined by the compiler and not stored in descriptors during execution - C b stored in a descriptor as part of the data object at run time - LISP Prolog

Implementation of operations Hardware operation: direct implementation. E.g. integer addition Subprogram/function, e.g. square root operation In-line code. Instead of using a subprogram, the code is copied into the program at the point where the subprogram would have been invoked.

Declarations Information about the name and type of data objects needed during program execution. Explicit – programmer defined Implicit – system defined

Examples FORTRAN - the first letter in the name of the variable determines the type Perl - the variable is declared by assigning a value $abc = 'a string' $abc is a string variable $abc = 7 $abc is an integer variable

Declarations of operations prototypes of the functions or subroutines that are programmer- defined. Examples: declaration: float Sub(int, float) signature: Sub: int x float --> float

Purpose of declaration Choice of storage representation Storage management Polymorphic operations Static type checking

Type Checking versus Type Conversion Type checking: checking that each operation executed by a program receives the proper number of arguments of the proper data types. Static type checking is done at compilation. Dynamic type checking is done at run-time.

Strong typing: all type errors can be statically checked Type inference: implicit data types, used if the interpretation is unambiguous. Type Conversion and Coercion Coercion: Implicit type conversion, performed by the system. Explicit conversion : routines to change from one data type to another.

Explicit conversion Pascal: the function round - converts a real type into integer C - cast, e.g. (int)X for float X converts the value of X to type integer

Coercion Two opposite approaches No coercions, any type mismatch is considered an error : Pascal, Ada Coercions are the rule. Only if no conversion is possible, error is reported.

Coercion: advantages and disadvantages Advantages: free the programmer from some low level concerns, as adding real numbers and integers. Disadvantages: may hide serious programming errors.

Assignments Assignment - the basic operation for changing the binding of a value to a data object. The assignment operation can be defined using the concepts L-value and R-value L-value: Location for an object. R-value: Contents of that location. Value, by itself, generally means R-value

Example A = A + B ; Pick up contents of location A: R-value of A Add contents of location B: R-value of B Store result into address A: L-value of A

Initialization Uninitialized data object - a data object has been created, but no value is assigned, i.e. only allocation of a block storage has been performed. Implicit and explicit initialization