Elementary Data Types Scalar Data Types Numerical Data Types Other

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Advertisements

Names and Bindings.
Types and Arithmetic Operators
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
ISBN Chapter 6 Data Types: Structured types.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Primitive Data Types: Numbers Strings Ordinal Types Pointers
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
2 Systems Architecture, Fifth Edition Chapter Goals Describe numbering systems and their use in data representation Compare and contrast various data.
JavaScript, Third Edition
Structured Data Types. Date Types We have seen various data types –Integer, Real, Character, Logical All these types define data values of different kinds.
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.
Imperative Programming Part One. 2 Overview Outline the characteristics of imperative languages Discuss other features of imperative languages that are.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
1 Programming Languages Implementation of Data Structures Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
SCSC 311 Information Systems: hardware and software
ISBN 0-321— Chapter 6 sections 1-4, 9 Primitive Data Types Numbers Strings Ordinal Types Pointers.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Cis303a_chapt03-2a.ppt Range Overflow Fixed length of bits to hold numeric data Can hold a maximum positive number (unsigned) X X X X X X X X X X X X X.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Elsa Gunter who’s.
Compiler Construction
Introduction to Computer Systems and the Java Programming Language.
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.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Other data types. Standard type sizes b Most machines store integers and reals in 4 bytes (32 bits) b Integers run from -2,147,483,648 to 2,147,483,647.
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.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Copyright Curt Hill Variables What are they? Why do we need them?
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
1 CS Programming Languages Class 08 September 19, 2000.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved. 6-2 Chapter 6 Topics Introduction Primitive Data Types.
1 Data Types Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer Types.
The Instruction Set Architecture. Hardware – Software boundary Java Program C Program Ada Program Compiler Instruction Set Architecture Microcode Hardware.
CS 330 Programming Languages 11 / 01 / 2007 Instructor: Michael Eckmann.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.2 Primitive Data Types Almost all programming languages.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
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
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Chapter 3 Data Representation
Data Types In Text: Chapter 6.
Chapter 6 – Data Types CSCE 343.
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
Chapter 6: Data Types Lectures # 10.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CS 326 Programming Languages, Concepts and Implementation
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.
PZ06C - Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3 PZ06C.
Introduction to Abstract Data Types
High Level Programming Languages
Low Level Programming Languages
The Data Element.
The Data Element.
Types and Related Issues
Presentation transcript:

Elementary Data Types Scalar Data Types Numerical Data Types Other Composite Data Types Character Strings Pointers and Programmer-Constructed Objects Files

Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general, scalar objects follow the hardware architecture of a computer.

Scalar Data Types Numeric Data Types Integers Subranges Floating-point real numbers Fixed-point real numbers Other Data Types Complex numbers Rational numbers Enumerations Booleans Characters

Integers Specification Maximal and minimal values Operations: Arithmetic Relational Assignment Bit operations Implementation - hardware defined

Subranges Specification: subtype of integer Implementation Example: a sequence of integer values within some restricted range Example: Pascal declaration A: 1..10 means that the variable A may be assigned integer values from 1 through 10. Implementation smaller storage requirements, better type checking

Floating-point real numbers Specification: Minimum and maximal value Roundoff issues - the check for equality may fail due to roundoff Implementation Mantissa - exponent model. Example: 10.5 = 0.105 x 102, Mantissa: 105, Exponent: 2

Fixed-point real numbers Specification: real numbers with predefined decimal places Implementation directly supported by hardware or simulated by software

Other Scalar Data Types Complex numbers: software simulated with two storage locations one the real portion and one for the imaginary portion. Rational numbers: the quotient of two integers. Enumerations: Ordered list of different values Booleans Characters

Enumerations enum StudentClass {Fresh, Soph, Junior, Senior} Example: enum StudentClass {Fresh, Soph, Junior, Senior} the variable StudentClass may accept only one of the four listed values. Implementation: represented during run time as integers, corresponding to the listed values.

Booleans Specification: Two values: true and false. Can be given explicitly as enumeration Basic operations: and, or, not. Implementation A single addressable unit such as byte or word. Use a particular bit for the value, e.g. the last bit; 1 - true, 0 -false. Use the entire storage; a zero value would then be false, otherwise - true.

Characters Specification: Single character as a value of a data object. Collating sequence - the ordering of the characters, used for lexicographic sorting. Operations: Relational Assignment Testing the type of the character - e.g. digit, letter, special symbol. Implementation supported by the underlying hardware

Composite Data Types Characterized by a complex data structure organization, processed by the compiler Character Strings Pointers and Programmer- Constructed Objects Files

Character Strings Specification: Fixed declared length : storage allocation at translation time. Strings longer than the declared length are truncated. Variable length to a declared bound: storage allocation at translation time. An upper bound for length is set and any string over that length is truncated Unbounded length: storage allocation at run time. String can be any length

Character Strings - operations o  Concatenation – appending two strings o  Relational operations – equal, less than, greater than o  Substring selection using positioning subscripts o  Substring selection using pattern matching o  Input / output formatting o  Dynamic strings - the string is evaluated at run time.

Character Strings - implementation Fixed declared length: A packed vector of characters Variable length to a declared bound: a descriptor that contains the maximum length and the current length Unbounded length: Either a linked storage of fixed-length data objects or a contiguous array of characters with dynamic run-time storage allocation

Pointers and Programmer-Constructed Objects Specification: Reference data objects only of a single type – C, Pascal, Ada. Reference data objects of any type – Smalltalk C, C++: pointers are data objects and can be manipulated by the program Java: pointers are hidden data structures, managed by the language implementation

Pointers - implementation Absolute addresses stored in the pointer. Allows for storing the new object anywhere in the memory Relative addresses: offset with respect to some base address. Advantages: the entire block can be moved to another location without invalidating the addresses in the pointers, since they are relative, not absolute.

Pointers – implementation problems Management of a general heap storage area: to create objects of different size Garbage - the contents of pointer is destroyed, and the object still exists Dangling references: the object is destroyed however the pointer still contains the address of the used location, and can be wrongly used by the program.

Files Characteristics: Usually reside on secondary storage devices as disks, tapes. Lifetime is greater than the lifetime of the program that has created the files. Implementation – as part of the operating system

Types of files Sequential file: a data structure composed of a linear sequence of components of the same type. Interactive Input-Output: sequential files used in interactive mode.

Types of Files Direct Access Files: Any single component can be accessed at random just as in an array. Key: the subscript to access a component. Implementation: a key table is kept in main memory Indexed Sequential Files: Similar to direct access files using a key combined with being able to sequentially process the file. The file must be ordered by the key