SlideShare a Scribd company logo
By-
Garima Jain
   Sequence control with expressions
   Conditional Statements, Loops
   Exception Handling
   Subprogram definition and activation
   Simple and Recursive Subprogram
   Subprogram Environment
Control of the order of execution of the operations
both primitive and user defined.
Implicit : determined by the order of the statements
in the source program or by the built-in execution
model
Explicit : the programmer uses statements to change
the order of execution (e.g. uses If statement)
Expressions: How data are           manipulated   using
precedence rules and parentheses.
Statements: conditional and iteration statements change
the sequential execution.
                Declarative programming: an execution
model that does not depend on the order of the
statements in the source program.
Subprograms: transfer control from one program to
another.
What is the sequence of performing the operations?
How is the sequence defined, and how is it represented?
Functional composition     :   Basic   sequence-control
mechanism:
Given an operation with its operands, the operands may
be:
·    Constants
·    Data objects
·    Other operations
Example 1: 3 * (var1 + 5)
operation - multiplication, operator: *, arity - 2
      operand 1: constant (3)
      operand 2: operation addition
                    operand1: data object (var1)
                    operand 2: constant (5)
Example 2: 3* var1 +5
Question: is the example equivalent to the above one?


Example 3: 3 + var1 +5
Question: is this equivalent to (3 + var1) + 5,
             or to 3 + (var1 + 5) ?
Precedence concerns the order of applying
operations
Associativity deals with the order of operations of
same precedence.
 
Precedence and associativity are defined when the
language is defined - within the semantic rules for
expressions.
Linear representation of the expression tree:
             Prefix notation
·            Postfix notation
·            Infix notation


Prefix and postfix notations are parentheses-free.
 Machine code sequence
 Tree structures - software simulation
 Prefix or postfix form - requires stack, executed by an
interpreter.
Eager evaluation - evaluate all operands before
applying operators.
Lazy evaluation
Side effects - some operations may change operands of
other operations.
Error conditions - may depend on the evaluation
strategy (eager or lazy evaluation)
Boolean expressions - results may differ depending on
the evaluation strategy.
if   expression   then   statement1   else
statement2
             if expression then statement1
 a choice among many alternatives
                   nested if statements
                   case statements
Implementation:  jump and branch machine
instructions, jump table implementation for case
statements
Simple  repetition (for loop)
     Specifies a count of the number
     of times to execute a loop:
            perform statement K times;
                  for loop -
Examples:
     for I=1 to 10 do statement;
     for(I=0;I<10; I++) statement;
while expression do statement;
Evaluate expression and if true execute statement, then
repeat process.
 repeat statement until expression;
 Execute statement and then evaluate expression.
Repeat if expression is not true.
C++ for loop functionally is equivalent to repetition
while condition holds
 Multiple exit loops
 Exceptional conditions
 Do-while-do structure


Solutions vary with languages, e.g. in C++ - break
statement, assert for exceptions.
Exception Handlers are subprograms that are not 
invoked by explicit calls

Special situations, called exceptions:

     Error conditions
     Unpredictable conditions
     Tracing and monitoring
Exception handlers typically contain only:

   • A set of declarations of local variables
   • A sequence of executable statements

Exception Handlers can be
  - predefined in the language
  - programmer defined
Languages provide methods for raising (throwing) and
   testing for exceptions.

  try {
       statement1;
       statement2;
       …
  if badCondition throw ExceptionName;
     }

  catch ExceptionName
{ ……….// do something for exception…….}
Operating system exceptions - raised directly
by hardware interrupts.

Programmer defined -
the translator inserts code to handle the
exceptions.
Subprogram Control :
interaction among subprograms
how subprograms pass data among themselves
Simple subprogram call return
     Copy rule view of subprograms:

     the effect of a call statement is the same as if the
     subprogram were copied and inserted into the
     main program.
• Subprograms cannot be recursive
• Explicit call statements are required
• Subprograms must execute completely at each call
• Immediate transfer of control at point of call
• Single execution sequence
CALL




       RETURN
Execution of subprograms

     Subprogram definition.

     Subprogram activation.
The definition is translated into a template, used
to create an activation each time a subprogram is
called.
a code segment (the invariant part) -
      executable code and constants,

an activation record (the dynamic part) -
       local data, parameters.

      created a new each time the subprogram is called,
      destroyed when the subprogram returns.
• Current-instruction pointer – CIP
address of the next statement to be executed


• Current-environment pointer – CEP
pointer to the activation record.
    An activation record is created
     Current CIP and CEP are saved in the created
    activation record as return point
      CEP is assigned the address of the activation
    record.
 CIP gets the address of the first instruction in the
    code segment
 The execution continues from the address in CIP
 The old values of CIP and CEP are retrieved.

     The execution continues from the address in
     CIP


Restrictions of the model:
      at most one activation of any subprogram
Allocate storage for a single activation record statically
as an extension of the code segment.
Used in FORTRAN and COBOL.

The activation record is not destroyed - only reinitialized
for each subprogram execution.

Hardware support - CIP is the program counter,
CEP is not used, simple jump executed on return.
The simplest run-time storage management technique
call statements : push CIP and CEP
return statements : pop CIP and CEP off of the stack.

Used in most C implementations
LISP: uses the stack as an environment.
Specification
      Syntactically - no difference
      Semantically - multiple activations of the
  same subprogram exist simultaneously at
  some point in the execution.

E.G. the first recursive call creates a second
activation within the lifetime of the first activation.
Stack-based -

CIP and CEP are stored in stack, forming a
dynamic chain of links.

A new activation record is created for each call
and destroyed on return.

The lifetimes of the activation records cannot
overlap - they are nested.
Data control features determine the accessibility of data at
different points during program execution.

Central problem:
the meaning of variable names, i.e. the correspondence
between names and memory locations.
Two ways to make a data object available as an operand
for an operation


Direct transmission
Referencing through a named data object
A data object computed at one point as the result of
an operation may be directly transmitted to another
operation as an operand

Example:                  x = y + 2*z;

The result of multiplication is transmitted directly as
an operand of the addition operation
A data object may be given a name when it is
created, the name may then be used to designate it
as an operand of an operation.
Variables
Formal parameters
Subprograms
Defined types
Defined constants
Labels
Exception names
Primitive operations
Literal constants
Association: binding identifiers to particular data
objects and subprograms

Referencing environment: the set of identifier
associations for a given subprogram.

Referencing operations during program execution:
determine the particular data object or subprogram
associated with an identifier
Subprogram Environment

     The set of associations created on entry to a subprogram formal
     parameters, local variables, and subprograms defined only within that
     subprogram.

Non-local referencing environment
     The set of associations for identifiers
     •        used within a subprogram
     •        not created on entry to it
Global referencing environment:
associations created at the start of execution of the main program, available
to be used in a subprogram.

Predefined referencing environments:
predefined associations in the language definition.
Unit 3 principles of programming language

More Related Content

What's hot

Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
SHREEHARI WADAWADAGI
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
Baskarkncet
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Analysis modeling & scenario based modeling
Analysis modeling &  scenario based modeling Analysis modeling &  scenario based modeling
Analysis modeling & scenario based modeling
Benazir Fathima
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
busyking03
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
Kumar
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
Jena Catherine Bel D
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
halstead software science measures
halstead software science measureshalstead software science measures
halstead software science measuresDeepti Pillai
 
software engineering
software engineeringsoftware engineering
software engineering
Azad public school
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
yndaravind
 

What's hot (20)

Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Analysis modeling & scenario based modeling
Analysis modeling &  scenario based modeling Analysis modeling &  scenario based modeling
Analysis modeling & scenario based modeling
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
halstead software science measures
halstead software science measureshalstead software science measures
halstead software science measures
 
software engineering
software engineeringsoftware engineering
software engineering
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 

Similar to Unit 3 principles of programming language

10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
Munawar Ahmed
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
Deepam Aggarwal
 
Unit 2
Unit 2Unit 2
theory of programming languages by shikra
theory of programming languages by shikratheory of programming languages by shikra
theory of programming languages by shikra
jateno3396
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
SHARDA SHARAN
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
janapriyanaidu
 
Parallel programming model
Parallel programming modelParallel programming model
Parallel programming model
Illuru Phani Kumar
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.ppt
ssuser0db64b
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
pinck2380
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
pinck200
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
Pramod Vishwakarma
 
Unit 1
Unit  1Unit  1
Unit 1
donny101
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
Taymoor Nazmy
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
AdenKheire
 
systemverilog-interview-questions.docx
systemverilog-interview-questions.docxsystemverilog-interview-questions.docx
systemverilog-interview-questions.docx
ssuser1c8ca21
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on lineMilind Patil
 

Similar to Unit 3 principles of programming language (20)

10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Unit 2
Unit 2Unit 2
Unit 2
 
theory of programming languages by shikra
theory of programming languages by shikratheory of programming languages by shikra
theory of programming languages by shikra
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
 
Parallel programming model
Parallel programming modelParallel programming model
Parallel programming model
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.ppt
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
Unit 1
Unit  1Unit  1
Unit 1
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 
systemverilog-interview-questions.docx
systemverilog-interview-questions.docxsystemverilog-interview-questions.docx
systemverilog-interview-questions.docx
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
 

Recently uploaded

Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 

Recently uploaded (20)

Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 

Unit 3 principles of programming language

  • 2. Sequence control with expressions  Conditional Statements, Loops  Exception Handling  Subprogram definition and activation  Simple and Recursive Subprogram  Subprogram Environment
  • 3. Control of the order of execution of the operations both primitive and user defined. Implicit : determined by the order of the statements in the source program or by the built-in execution model Explicit : the programmer uses statements to change the order of execution (e.g. uses If statement)
  • 4. Expressions: How data are manipulated using precedence rules and parentheses. Statements: conditional and iteration statements change the sequential execution. Declarative programming: an execution model that does not depend on the order of the statements in the source program. Subprograms: transfer control from one program to another.
  • 5. What is the sequence of performing the operations? How is the sequence defined, and how is it represented? Functional composition : Basic sequence-control mechanism: Given an operation with its operands, the operands may be: · Constants · Data objects · Other operations
  • 6. Example 1: 3 * (var1 + 5) operation - multiplication, operator: *, arity - 2 operand 1: constant (3) operand 2: operation addition operand1: data object (var1) operand 2: constant (5)
  • 7. Example 2: 3* var1 +5 Question: is the example equivalent to the above one? Example 3: 3 + var1 +5 Question: is this equivalent to (3 + var1) + 5, or to 3 + (var1 + 5) ?
  • 8. Precedence concerns the order of applying operations Associativity deals with the order of operations of same precedence.   Precedence and associativity are defined when the language is defined - within the semantic rules for expressions.
  • 9. Linear representation of the expression tree: Prefix notation · Postfix notation · Infix notation Prefix and postfix notations are parentheses-free.
  • 10.  Machine code sequence  Tree structures - software simulation  Prefix or postfix form - requires stack, executed by an interpreter.
  • 11. Eager evaluation - evaluate all operands before applying operators. Lazy evaluation
  • 12. Side effects - some operations may change operands of other operations. Error conditions - may depend on the evaluation strategy (eager or lazy evaluation) Boolean expressions - results may differ depending on the evaluation strategy.
  • 13. if expression then statement1 else statement2 if expression then statement1  a choice among many alternatives nested if statements case statements Implementation:  jump and branch machine instructions, jump table implementation for case statements
  • 14. Simple  repetition (for loop) Specifies a count of the number of times to execute a loop: perform statement K times; for loop - Examples: for I=1 to 10 do statement; for(I=0;I<10; I++) statement;
  • 15. while expression do statement; Evaluate expression and if true execute statement, then repeat process. repeat statement until expression; Execute statement and then evaluate expression. Repeat if expression is not true. C++ for loop functionally is equivalent to repetition while condition holds
  • 16.
  • 17.
  • 18.  Multiple exit loops  Exceptional conditions  Do-while-do structure Solutions vary with languages, e.g. in C++ - break statement, assert for exceptions.
  • 19. Exception Handlers are subprograms that are not  invoked by explicit calls Special situations, called exceptions:  Error conditions  Unpredictable conditions  Tracing and monitoring
  • 20. Exception handlers typically contain only: • A set of declarations of local variables • A sequence of executable statements Exception Handlers can be - predefined in the language - programmer defined
  • 21. Languages provide methods for raising (throwing) and testing for exceptions.   try { statement1; statement2; …   if badCondition throw ExceptionName; }   catch ExceptionName { ……….// do something for exception…….}
  • 22. Operating system exceptions - raised directly by hardware interrupts. Programmer defined - the translator inserts code to handle the exceptions.
  • 23. Subprogram Control : interaction among subprograms how subprograms pass data among themselves
  • 24. Simple subprogram call return Copy rule view of subprograms: the effect of a call statement is the same as if the subprogram were copied and inserted into the main program.
  • 25. • Subprograms cannot be recursive • Explicit call statements are required • Subprograms must execute completely at each call • Immediate transfer of control at point of call • Single execution sequence
  • 26. CALL RETURN
  • 27. Execution of subprograms Subprogram definition. Subprogram activation.
  • 28. The definition is translated into a template, used to create an activation each time a subprogram is called.
  • 29. a code segment (the invariant part) - executable code and constants, an activation record (the dynamic part) - local data, parameters. created a new each time the subprogram is called, destroyed when the subprogram returns.
  • 30. • Current-instruction pointer – CIP address of the next statement to be executed • Current-environment pointer – CEP pointer to the activation record.
  • 31.
  • 32. An activation record is created  Current CIP and CEP are saved in the created activation record as return point  CEP is assigned the address of the activation record.  CIP gets the address of the first instruction in the code segment  The execution continues from the address in CIP
  • 33.  The old values of CIP and CEP are retrieved.  The execution continues from the address in CIP Restrictions of the model: at most one activation of any subprogram
  • 34. Allocate storage for a single activation record statically as an extension of the code segment. Used in FORTRAN and COBOL. The activation record is not destroyed - only reinitialized for each subprogram execution. Hardware support - CIP is the program counter, CEP is not used, simple jump executed on return.
  • 35. The simplest run-time storage management technique call statements : push CIP and CEP return statements : pop CIP and CEP off of the stack. Used in most C implementations LISP: uses the stack as an environment.
  • 36. Specification Syntactically - no difference Semantically - multiple activations of the same subprogram exist simultaneously at some point in the execution. E.G. the first recursive call creates a second activation within the lifetime of the first activation.
  • 37. Stack-based - CIP and CEP are stored in stack, forming a dynamic chain of links. A new activation record is created for each call and destroyed on return. The lifetimes of the activation records cannot overlap - they are nested.
  • 38. Data control features determine the accessibility of data at different points during program execution. Central problem: the meaning of variable names, i.e. the correspondence between names and memory locations.
  • 39. Two ways to make a data object available as an operand for an operation Direct transmission Referencing through a named data object
  • 40. A data object computed at one point as the result of an operation may be directly transmitted to another operation as an operand Example: x = y + 2*z; The result of multiplication is transmitted directly as an operand of the addition operation
  • 41. A data object may be given a name when it is created, the name may then be used to designate it as an operand of an operation.
  • 42. Variables Formal parameters Subprograms Defined types Defined constants Labels Exception names Primitive operations Literal constants
  • 43. Association: binding identifiers to particular data objects and subprograms Referencing environment: the set of identifier associations for a given subprogram. Referencing operations during program execution: determine the particular data object or subprogram associated with an identifier
  • 44. Subprogram Environment The set of associations created on entry to a subprogram formal parameters, local variables, and subprograms defined only within that subprogram. Non-local referencing environment The set of associations for identifiers • used within a subprogram • not created on entry to it Global referencing environment: associations created at the start of execution of the main program, available to be used in a subprogram. Predefined referencing environments: predefined associations in the language definition.