SlideShare a Scribd company logo
By-
Garima Jain
   Specification and Implementation of Elementary Data
    Types
   Specification and Implementation of Structured Data
    Types
   Type Equivalence, Checking and Conversion
   Vectors and Arrays
   Lists ,Structures
   Sets ,Files
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
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.
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
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)
In programs, data objects are represented as
variables and constants
Variables : Data objects defined and named by the
programmer explicitly.
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
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.
•Attributes
•Values
•Operations
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
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 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)
An operation is defined by:
·    Domain - set of possible input arguments
·    Range - set of possible results
·    Action - how the result is produced
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.
 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.
   Storage representation
   Implementation of operations
Influenced by the hardware Described in terms of:
        Size of the memory blocks required
        Layout of attributes and data values within the
block
    determined by the compiler and not stored in
descriptors during execution - C


 stored in a descriptor as part of the data object at
run time - LISP Prolog
• 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.
   Scalar Data Types
     Numerical Data Types
     Other


   Composite Data Types
     Character Strings
     Pointers and Programmer-Constructed
      Objects
     Files
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.
Numeric Data Types
      Integers
      Sub -ranges
      Floating-point real numbers
      Fixed-point real numbers
Other Data Types -
      Complex numbers
      Rational numbers
      Enumerations
      Booleans
      Characters
Specification
      Maximal and minimal values
      Operations:
            Arithmetic
            Relational
            Assignment
            Bit operations
Implementation - hardware defined
Specification: subtype of integer
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
Specification: Minimum and maximal value
      Round-off issues - the check for equality may fail
due to round -off


Implementation
      Mantissa - exponent model.
      Example: 10.5 = 0.105 x 102,
            Mantissa: 105, Exponent: 2
Specification:
      real numbers with predefined decimal places
Implementation :
      directly supported by hardware or simulated by
software
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
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.
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.
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
Characterized by a complex data structure organization,
processed by the compiler.

   Character Strings
   Pointers and Programmer-       Constructed
  Objects
   Files
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
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.
   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
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
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.
o Management of a general heap storage area: to
create objects of different size
o Garbage - the contents of pointer is destroyed, and the
object still exists
o 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.
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
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.
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
A data structure is a data object that contains other data
  objects as its elements or components.
Mechanisms to create new data types:
      Structured data
        Homogeneous: arrays, lists, sets,
        Non-homogeneous: records
      Subprograms
      Type declarations – to define new types and operations
       (Abstract data types)
      Inheritance
•Number of components and size

•Type of each component

•Selection mechanism

•Maximum number of components

•Organization of the components
•Number of components and size
  Fixed size - Arrays
  Variable size – stacks, lists. Pointer is used to
  link components.

•Type of each component
     Homogeneous – all components are the
     same type
     Heterogeneous – components are of
     different types
Selection mechanism to identify components –
index, pointer

Two-step process:
 referencing the structure
 selection of a particular component
•   Simple linear sequence - arrays, stacks, lists
• Multidimensional structures:
  • separate types (Fortran)
  • a vector of vectors (C++)
Component selection operations
            Sequential
            Random
Insertion/deletion of components

Whole-data structure operations
Creation/destruction of data structures
   Storage representations
   Implementation of operations on data structures
   Storage management
   storage for the components
   optional descriptor, contains some or all of the
    attributes

   Sequential representation
   Linked representation
The data structure is stored in a single contiguous
block of storage, that includes both descriptor and
components.

Used for fixed-size structures,         homogeneous
structures (arrays, character strings)
The data structure is stored in several noncontiguous
blocks of storage, linked together through pointers.

Used for variable-size structured (trees, lists)

Flexible, ensures true variable size, however it has to
be software simulated
Component selection in sequential representation
    Base address plus offset calculation. Add
    component size to current location to move to next
    component.

Component selection in linked representation
    Move from address location to address location
    following the chain of pointers.
Access paths to a structured data object - to
endure access to the object for its processing.
Created using a name or a pointer.

Two central problems:
     Garbage – data object is bound but access
     path is destroyed. Memory cannot be
     unbound.

     Dangling references: the data object is
     destroyed, but the access path still exists.
What is to be checked:

  • Existence of a selected component

  • Type of a selected component
Two questions to be answered:

•When are two types the same?

•When do 2 objects have the same value?
Two data types are considered equivalent only if
they have the same name.



Issues
Every object must have an assigned type, there can
be no anonymous types.

A singe type definition must serve all or large parts
of a program.
Two data types are considered equivalent if they define
data objects that have the same internal components.

Issues
• Do components need to be exact duplicates?
• Can field order be different in records?
• Can field sizes vary?
Two objects are equal if each member in one object
is identical to the corresponding member of the
other object.



The compiler has no way to know how to compare data
values of user-defined type. It is the task of the
programmer that has defined that particular data type to
define also the operations with the objects of that type.
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.
Vector - one dimensional array

Matrix - two dimensional array

Multidimensional arrays

Slice - a substructure in an array that is also an array,
e.g. a column in a matrix

Associative Arrays - elements are selected by a key
value
Access - can be implemented efficiently if the length
of the components of the array is known at
compilation time.

The address of each selected element can be computed
using an arithmetic expression.

Whole array operations, e.g. copying an array - may
require much memory.
A record is data structure composed of a fixed
number of components of different types.

The components may be heterogeneous, and they
are named with symbolic names.
Records and arrays with structured components

Lists and sets

Executable data objects
Data structures are considered to be a special type of
program statements and all are treated in the same
way (Prolog).
THANK YOU.. !!

More Related Content

What's hot (20)

Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Unit 4
Unit 4Unit 4
Unit 4
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Function in C
Function in CFunction in C
Function in C
 
Enums in c
Enums in cEnums in c
Enums in c
 
Python set
Python setPython set
Python set
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithm
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
String functions and operations
String functions and operations String functions and operations
String functions and operations
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Character attributes
Character attributesCharacter attributes
Character attributes
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 

Similar to Unit 2 Principles of Programming Languages

Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & StringsAbhinav Porwal
 
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its ModuleMuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its ModuleJitendra Bafna
 
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...Spark Summit
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netwww.myassignmenthelp.net
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS Adams Sidibe
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Typesk v
 
Java platform
Java platformJava platform
Java platformVisithan
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptxsalutiontechnology
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance Anaya Zafar
 
STAT Requirement Analysis
STAT Requirement AnalysisSTAT Requirement Analysis
STAT Requirement Analysisstat
 
[2015/2016] AADL (Architecture Analysis and Design Language)
[2015/2016] AADL (Architecture Analysis and Design Language)[2015/2016] AADL (Architecture Analysis and Design Language)
[2015/2016] AADL (Architecture Analysis and Design Language)Ivano Malavolta
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha Keim
 

Similar to Unit 2 Principles of Programming Languages (20)

Unit 5
Unit 5Unit 5
Unit 5
 
Data types.pdf
Data types.pdfData types.pdf
Data types.pdf
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & Strings
 
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its ModuleMuleSoft Nashik Virtual  Meetup#3 - Deep Dive Into DataWeave and its Module
MuleSoft Nashik Virtual Meetup#3 - Deep Dive Into DataWeave and its Module
 
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...
Large-Scale Text Processing Pipeline with Spark ML and GraphFrames: Spark Sum...
 
Unit 1
Unit  1Unit  1
Unit 1
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.net
 
VB.net
VB.netVB.net
VB.net
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Ordbms
OrdbmsOrdbms
Ordbms
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Java platform
Java platformJava platform
Java platform
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptx
 
Data types
Data typesData types
Data types
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
STAT Requirement Analysis
STAT Requirement AnalysisSTAT Requirement Analysis
STAT Requirement Analysis
 
[2015/2016] AADL (Architecture Analysis and Design Language)
[2015/2016] AADL (Architecture Analysis and Design Language)[2015/2016] AADL (Architecture Analysis and Design Language)
[2015/2016] AADL (Architecture Analysis and Design Language)
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 

Recently uploaded

2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 

Recently uploaded (20)

2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 

Unit 2 Principles of Programming Languages

  • 2. Specification and Implementation of Elementary Data Types  Specification and Implementation of Structured Data Types  Type Equivalence, Checking and Conversion  Vectors and Arrays  Lists ,Structures  Sets ,Files
  • 3. 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
  • 4. 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.
  • 5. 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
  • 6. 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)
  • 7. In programs, data objects are represented as variables and constants Variables : Data objects defined and named by the programmer explicitly.
  • 8. 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
  • 9. 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.
  • 11. 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
  • 12. 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
  • 13. 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)
  • 14. An operation is defined by: · Domain - set of possible input arguments · Range - set of possible results · Action - how the result is produced
  • 15. 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.
  • 16.  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.
  • 17. Storage representation  Implementation of operations
  • 18. Influenced by the hardware Described in terms of: Size of the memory blocks required Layout of attributes and data values within the block
  • 19.     determined by the compiler and not stored in descriptors during execution - C  stored in a descriptor as part of the data object at run time - LISP Prolog
  • 20. • 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.
  • 21. Scalar Data Types  Numerical Data Types  Other  Composite Data Types  Character Strings  Pointers and Programmer-Constructed Objects  Files
  • 22. 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.
  • 23. Numeric Data Types Integers Sub -ranges Floating-point real numbers Fixed-point real numbers Other Data Types - Complex numbers Rational numbers Enumerations Booleans Characters
  • 24. Specification Maximal and minimal values Operations: Arithmetic Relational Assignment Bit operations Implementation - hardware defined
  • 25. Specification: subtype of integer 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
  • 26. Specification: Minimum and maximal value Round-off issues - the check for equality may fail due to round -off Implementation Mantissa - exponent model. Example: 10.5 = 0.105 x 102, Mantissa: 105, Exponent: 2
  • 27. Specification: real numbers with predefined decimal places Implementation : directly supported by hardware or simulated by software
  • 28. 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
  • 29. 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.
  • 30. 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.
  • 31. 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
  • 32. Characterized by a complex data structure organization, processed by the compiler.  Character Strings  Pointers and Programmer- Constructed Objects  Files
  • 33. 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
  • 34. 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.
  • 35. 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
  • 36. 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
  • 37. 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.
  • 38. o Management of a general heap storage area: to create objects of different size o Garbage - the contents of pointer is destroyed, and the object still exists o 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.
  • 39. 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
  • 40. 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.
  • 41. 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
  • 42. A data structure is a data object that contains other data objects as its elements or components. Mechanisms to create new data types:  Structured data  Homogeneous: arrays, lists, sets,  Non-homogeneous: records  Subprograms  Type declarations – to define new types and operations (Abstract data types)  Inheritance
  • 43. •Number of components and size •Type of each component •Selection mechanism •Maximum number of components •Organization of the components
  • 44. •Number of components and size Fixed size - Arrays Variable size – stacks, lists. Pointer is used to link components. •Type of each component Homogeneous – all components are the same type Heterogeneous – components are of different types
  • 45. Selection mechanism to identify components – index, pointer Two-step process:  referencing the structure  selection of a particular component
  • 46. Simple linear sequence - arrays, stacks, lists • Multidimensional structures: • separate types (Fortran) • a vector of vectors (C++)
  • 47. Component selection operations Sequential Random Insertion/deletion of components Whole-data structure operations Creation/destruction of data structures
  • 48. Storage representations  Implementation of operations on data structures  Storage management
  • 49. storage for the components  optional descriptor, contains some or all of the attributes  Sequential representation  Linked representation
  • 50. The data structure is stored in a single contiguous block of storage, that includes both descriptor and components. Used for fixed-size structures, homogeneous structures (arrays, character strings)
  • 51. The data structure is stored in several noncontiguous blocks of storage, linked together through pointers. Used for variable-size structured (trees, lists) Flexible, ensures true variable size, however it has to be software simulated
  • 52. Component selection in sequential representation Base address plus offset calculation. Add component size to current location to move to next component. Component selection in linked representation Move from address location to address location following the chain of pointers.
  • 53. Access paths to a structured data object - to endure access to the object for its processing. Created using a name or a pointer. Two central problems: Garbage – data object is bound but access path is destroyed. Memory cannot be unbound. Dangling references: the data object is destroyed, but the access path still exists.
  • 54. What is to be checked: • Existence of a selected component • Type of a selected component
  • 55. Two questions to be answered: •When are two types the same? •When do 2 objects have the same value?
  • 56. Two data types are considered equivalent only if they have the same name. Issues Every object must have an assigned type, there can be no anonymous types. A singe type definition must serve all or large parts of a program.
  • 57. Two data types are considered equivalent if they define data objects that have the same internal components. Issues • Do components need to be exact duplicates? • Can field order be different in records? • Can field sizes vary?
  • 58. Two objects are equal if each member in one object is identical to the corresponding member of the other object. The compiler has no way to know how to compare data values of user-defined type. It is the task of the programmer that has defined that particular data type to define also the operations with the objects of that type.
  • 59. 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.
  • 60. Type Conversion and Coercion Coercion: Implicit type conversion, performed by the system. Explicit conversion : routines to change from one data type to another.
  • 61. Vector - one dimensional array Matrix - two dimensional array Multidimensional arrays Slice - a substructure in an array that is also an array, e.g. a column in a matrix Associative Arrays - elements are selected by a key value
  • 62. Access - can be implemented efficiently if the length of the components of the array is known at compilation time. The address of each selected element can be computed using an arithmetic expression. Whole array operations, e.g. copying an array - may require much memory.
  • 63. A record is data structure composed of a fixed number of components of different types. The components may be heterogeneous, and they are named with symbolic names.
  • 64. Records and arrays with structured components Lists and sets Executable data objects Data structures are considered to be a special type of program statements and all are treated in the same way (Prolog).