SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
PRINCIPLES OF Programming
Languages
UNIT 1
www.getmyuni.com
Presentation Outline
• Programming Language: Definition, History ,Feature
• Issues in Language Design
• Structure and Operation of Computer
• Programming Language Paradigms
• Efficiency, Regularity
• Issues in Language Translation
• Syntax and Semantics
www.getmyuni.com
Programming Languages
•Definition : A notation of a algorithm and data
structures are called a programming language.
www.getmyuni.com
Why study programming languages
• To improve your ability to develop effective algorithms
• To improve your use of existing programming languages
• To increase your vocabulary of useful programming constructs
• To allow a better choice of programming language
• To make it easier to learn a new language
• To make it easier to design a new language
www.getmyuni.com
History
• 1951- 55: Experimentaluse of expression compilers.
• 1956- 60: FORTRAN, COBOL, LISP, Algol 60.
• 1961- 65: APL notation, Algol 60 (revised), SNOBOL, CPL.
• 1966- 70: APL, SNOBOL 4, FORTRAN 66, BASIC, SIMULA, Algol 68,
Algol-W, BCPL.
• 1971- 75: Pascal, PL/1 (Standard), C, Scheme, Prolog.
• 1976- 80: Smalltalk, Ada, FORTRAN 77, ML.
www.getmyuni.com
History
• 1981- 85: Smalltalk-80, Prolog, Ada 83.
• 1986- 90: C++, SML, Haskell.
• 1991- 95: Ada 95, TCL, Perl.
• 1996- 2000: Java.
• 2000- 05: C#, Python, Ruby, Scala.
www.getmyuni.com
Language development
Numerically based languages
Computing mathematical expressions
FORTRAN, Algol, Pascal, PL/1, BASIC, C, C++
Business languages
COBOL (Common Business Oriented Language)
English-like notation
www.getmyuni.com
Language development
Artificial intelligence languages
Tree search; Rule-based paradigm
LISP (LISt Processing)
PROLOG (PROgramming in LOGic)
System languages
C, C++
Script languages: AWK, Perl, TCL/TK
Web programming: HTML, XML, Java,
Microsoft *.NET family
www.getmyuni.com
Software architectures
Mainframe era
Batch processing (batches of files)
Interactive processing (time sharing)
Effects on language design
File I/O in batch processing
Error handling in batch processing
Time constraints in interactive processing
www.getmyuni.com
Software architectures
Personal computers
Interactive processing
Embedded system environments
Effects on language design
No need for time sharing
Good interactive graphics
Non-standard I/O devices for embedded systems
www.getmyuni.com
Software architectures
Networking era
Client-server model of computing
Server: a program that provides information
Client - a program that requests information
Effects on language design
Interaction between the client and server programs
Active web pages, Security issues, Performance
www.getmyuni.com
Attributes of a good language
• Conceptual integrity
• Orthogonality
• Naturalness for the application
• Support for abstraction
• Ease of program verification
• Programming environment
• Portability of programs
• Cost of use
 Cost of execution.
 Cost of program translation.
 Cost of program creation, testing, and use.
 Cost of program maintenance.
www.getmyuni.com
Language Design Issues
• Design to
•Run efficiently : early languages
•Easy to write correctly : new languages
•Data typing features in ML
•Class of C++
•Package of Ada
www.getmyuni.com
The Structure And Operation Of A
Computer
• A computer is an integrated set of algorithms and data structures capable
of storing and executing programs.
•Hardware computer or
•virtual computer
www.getmyuni.com
Computer Architecture
•Well-known computer architecture: Von Neumann
• Imperative languages, most dominant, because of
von Neumann computers
– Data and programs stored in memory
– Memory is separate from CPU
– Instructions and data are piped from memory to
CPU
– Basis for imperative languages
• Variables model memory cells
• Assignment statements model piping
• Iteration is efficient
www.getmyuni.com
The von Neumann Architecture
www.getmyuni.com
Virtual Computers
• Hardware realization
•Physical devices
• Firmware realization
•microprogramming
• Software simulation
•Some other programming language
• Combination of these techniques
www.getmyuni.com
Major Components of a Computer
• Data
•Various kinds of elementary and structured data.
• Primitive operations
• Sequence control
•Controlling the sequence of primitive operations
execution.
www.getmyuni.com
Major Components of a Computer
• Data access
•Controlling the data supplied to each execution of
an operation.
• Storage management
•Controlling the allocation of storage for programs
and data.
• Operating environment
•Providing mechanisms for communication with
an external environment containing programs and
data.
www.getmyuni.com
Data
• Main memory
• High-speed register
• High-speed cache memory
• External files
Data and Program
www.getmyuni.com
Operations
• A set of build-in primitive operations
•Arithmetic operations on each built-in numeric
data (+,-,*,/)
•Testing various properties of data items (test for
zero, positive, and negative numbers)
•Accessing and modifying various parts of a data
item
•Controlling input-output devices
•Sequence control (jumps)
www.getmyuni.com
Sequence Control
• There is an interpreter :
•Fetch the instruction
•Decode instruction
•Fetch designated operands
•Branch to designated operation
•Execute primitive operations 1 to n
Using an address register
www.getmyuni.com
Data Access
• Access to operands of the operation
www.getmyuni.com
Storage Management
• Keeping all resources of the computer operating as much as possible
•Memory
•Central processor
•External data devices
Multiprogramming
Cache memory
www.getmyuni.com
Operating Environment
• The outside world of computer; a set of peripherals and
input-output devices
www.getmyuni.com
Language Paradigms
• Imperative / procedural languages
• Applicative / functional languages
• Rule-based / declarative languages
• Object-oriented languages
www.getmyuni.com
Imperative / procedural languages
Statement oriented languages that change machine
state
(C, Pascal, FORTRAN, COBOL)
Computation: a sequence of machine states (contents
of memory)
Syntax: S1, S2, S3, ... where S1, S2, … are statements
www.getmyuni.com
Applicative / functional languages
Programming consists of building the function that
computes the answer
Computation: Function composition is major
operation (ML, LISP)
Syntax: P1(P2(P3(X)))
www.getmyuni.com
Rule-based / declarative languages
Computation: Actions are specified by rules that
check for the presence of certain enabling conditions.
(Prolog)
The order of execution is determined by the enabling
conditions, not by the order of the statements.
Syntax: Condition  Action
www.getmyuni.com
Object-oriented languages
Imperative languages that merge applicative design
with imperative statements (Java, C++, Smalltalk)
Syntax: Set of objects (classes) containing data
(imperative concepts) and methods (applicative
concepts)
www.getmyuni.com
Language Translation issues
•Programming language Syntax
• Key criteria concerning syntax
• Basic syntactic concepts
• Overall Program-Subprogram structure
•Stages in Translation
• Analysis of the source program
• Synthesis of the object program
• Bootstrapping
www.getmyuni.com
Syntax
The syntax of a programming language describes the
structure of programs without any consideration of
their meaning.
www.getmyuni.com
Key criteria concerning syntax
Readability – a program is considered readable if the
algorithm and data are apparent by
inspection.
Write-ability – ease of writing the program.
Verifiability – ability to prove program
correctness (very difficult issue)
Translatability – ease of translating the program
into executable form.
Lack of ambiguity – the syntax should provide for
ease of avoiding ambiguous structures
www.getmyuni.com
Basic Syntactic Concepts
• Character set – The alphabet of the language. Several different character
sets are used: ASCII, EBCIDIC, Unicode
• Identifiers – strings of letters of digits usually beginning with a letter
• Operator Symbols – +-*/
• Keywords or Reserved Words – used as a fixed part of the syntax of a
statement
www.getmyuni.com
Basic Syntactic Concepts
• Noise words – optional words inserted into statements to improve
readability
• Comments – used to improve readability and for documentation purposes.
Comments are usually enclosed by special markers
• Blanks – rules vary from language to language. Usually only significant in
literal strings
www.getmyuni.com
Basic Syntactic Concepts
• Delimiters – used to denote the beginning and the end of syntactic
constructs
• Expressions – functions that access data objects in a program and return a
value
• Statements – these are the sentences of the language, they describe a task
to be performed
www.getmyuni.com
Overall Program-Subprogram
Structure
Separate subprogram definitions: Separate
compilation, linked at load time E.g. C/C++
Separate data definitions: General approach in
OOP.
Nested subprogram definitions: Subprogram
definitions appear as declarations within the main
program or other subprograms. E.g. Pascal
www.getmyuni.com
Overall Program-Subprogram
Structure
Separate interface definitions:
C/C++ header files
Data descriptions separated from executable
statements. A centralized data division contains all data
declarations. E.g. COBOL
Un-separated subprogram definitions: No syntactic
distinction between main program statements and
subprogram statements.
E.g. BASIC
www.getmyuni.com
Stages in Translation
• Analysis of the source program
• Synthesis of the object program
• Bootstrapping
www.getmyuni.com
Analysis of the source program
Lexical analysis (scanning) – identifying the tokens of the
programming language: keywords, identifiers, constants
and other symbols
In the program
void main()
{ printf("Hello Worldn"); }
the tokens are
void, main, (, ), {, printf, (, "Hello Worldn", ), ;, }
www.getmyuni.com
Syntactic and Semantic Analysis
Syntactic analysis (parsing) – determining the structure
of the program, as defined by the language grammar.
Semantic analysis - assigning meaning to the syntactic
structures
Example: int variable1;
meaning: 4 bytes for variable1 , a specific set of
operations to be used with variable1.
www.getmyuni.com
Basic Semantic Tasks
The semantic analysis builds the bridge between analysis and
synthesis.
Basic semantic tasks:
• Symbol–table maintenance
• Insertion of implicit information
• Error detection
• Macro processing
Result : an internal representation, suitable to be used for
code optimization and code generation.
www.getmyuni.com
Synthesis of the object program
Three main steps:
Optimization - Removing redundant statements
Code generation - generating assembler commands with
relative memory addresses for the separate program
modules - obtaining the object code of the program.
Linking and loading - resolving the addresses -
obtaining the executable code of the program.
www.getmyuni.com
Optimization example
Intermediate code:
Temp1 = B + C
Temp2 = Temp1 + D
A = Temp2
Assembler code not optimized:
LOAD_R B
ADD_R C
STORE_R Temp1
LOAD_R Temp1
ADD_R D
STORE_R Temp2
LOAD_R Temp2
STORE_R A
Statements in yellow
can be removed
www.getmyuni.com
Bootstrapping
The compiler for a given language can be written in
the same language.
• A program that translates some internal representation
into assembler code.
• The programmer manually re-writes the compiler into
the internal representation, using the algorithm that is
encoded into the compiler.
From there on the internal representation is translated into
assembler and then into machine language.
www.getmyuni.com
Syntax and Semantics
• Syntax: what the program looks like.
• Semantics: the meaning given to the various syntactic constructs.
Example:
V: array [0..9] of integer;
int V[10];
www.getmyuni.com

Contenu connexe

Similaire à computer-science_engineering_principles-of-programming-languages_introduction_notes.pdf

Similaire à computer-science_engineering_principles-of-programming-languages_introduction_notes.pdf (20)

Introduction
IntroductionIntroduction
Introduction
 
Intro to Programming Lang.pptx
Intro to Programming Lang.pptxIntro to Programming Lang.pptx
Intro to Programming Lang.pptx
 
Plc part 1
Plc part 1Plc part 1
Plc part 1
 
Pl9ch1
Pl9ch1Pl9ch1
Pl9ch1
 
Compiler design
Compiler designCompiler design
Compiler design
 
Ch1 language design issue
Ch1 language design issueCh1 language design issue
Ch1 language design issue
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Unit 1
Unit 1Unit 1
Unit 1
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
compiler construction tool in computer science .
compiler construction tool in computer science .compiler construction tool in computer science .
compiler construction tool in computer science .
 
Desired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptxDesired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptx
 
Programming language
Programming languageProgramming language
Programming language
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
CH # 1 preliminaries
CH # 1 preliminariesCH # 1 preliminaries
CH # 1 preliminaries
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
Bba i-introduction to computer-u-2- application and system software
Bba  i-introduction to computer-u-2- application and system softwareBba  i-introduction to computer-u-2- application and system software
Bba i-introduction to computer-u-2- application and system software
 
Bsc cs 1 fit u-2 application and system software
Bsc cs 1 fit u-2 application and system softwareBsc cs 1 fit u-2 application and system software
Bsc cs 1 fit u-2 application and system software
 
Bca i-fundamental of computer-u-2- application and system software
Bca  i-fundamental of  computer-u-2- application and system softwareBca  i-fundamental of  computer-u-2- application and system software
Bca i-fundamental of computer-u-2- application and system software
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Mca i-fundamental of computer-u-2- application and system software
Mca  i-fundamental of  computer-u-2- application and system softwareMca  i-fundamental of  computer-u-2- application and system software
Mca i-fundamental of computer-u-2- application and system software
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

computer-science_engineering_principles-of-programming-languages_introduction_notes.pdf

  • 2. Presentation Outline • Programming Language: Definition, History ,Feature • Issues in Language Design • Structure and Operation of Computer • Programming Language Paradigms • Efficiency, Regularity • Issues in Language Translation • Syntax and Semantics www.getmyuni.com
  • 3. Programming Languages •Definition : A notation of a algorithm and data structures are called a programming language. www.getmyuni.com
  • 4. Why study programming languages • To improve your ability to develop effective algorithms • To improve your use of existing programming languages • To increase your vocabulary of useful programming constructs • To allow a better choice of programming language • To make it easier to learn a new language • To make it easier to design a new language www.getmyuni.com
  • 5. History • 1951- 55: Experimentaluse of expression compilers. • 1956- 60: FORTRAN, COBOL, LISP, Algol 60. • 1961- 65: APL notation, Algol 60 (revised), SNOBOL, CPL. • 1966- 70: APL, SNOBOL 4, FORTRAN 66, BASIC, SIMULA, Algol 68, Algol-W, BCPL. • 1971- 75: Pascal, PL/1 (Standard), C, Scheme, Prolog. • 1976- 80: Smalltalk, Ada, FORTRAN 77, ML. www.getmyuni.com
  • 6. History • 1981- 85: Smalltalk-80, Prolog, Ada 83. • 1986- 90: C++, SML, Haskell. • 1991- 95: Ada 95, TCL, Perl. • 1996- 2000: Java. • 2000- 05: C#, Python, Ruby, Scala. www.getmyuni.com
  • 7. Language development Numerically based languages Computing mathematical expressions FORTRAN, Algol, Pascal, PL/1, BASIC, C, C++ Business languages COBOL (Common Business Oriented Language) English-like notation www.getmyuni.com
  • 8. Language development Artificial intelligence languages Tree search; Rule-based paradigm LISP (LISt Processing) PROLOG (PROgramming in LOGic) System languages C, C++ Script languages: AWK, Perl, TCL/TK Web programming: HTML, XML, Java, Microsoft *.NET family www.getmyuni.com
  • 9. Software architectures Mainframe era Batch processing (batches of files) Interactive processing (time sharing) Effects on language design File I/O in batch processing Error handling in batch processing Time constraints in interactive processing www.getmyuni.com
  • 10. Software architectures Personal computers Interactive processing Embedded system environments Effects on language design No need for time sharing Good interactive graphics Non-standard I/O devices for embedded systems www.getmyuni.com
  • 11. Software architectures Networking era Client-server model of computing Server: a program that provides information Client - a program that requests information Effects on language design Interaction between the client and server programs Active web pages, Security issues, Performance www.getmyuni.com
  • 12. Attributes of a good language • Conceptual integrity • Orthogonality • Naturalness for the application • Support for abstraction • Ease of program verification • Programming environment • Portability of programs • Cost of use  Cost of execution.  Cost of program translation.  Cost of program creation, testing, and use.  Cost of program maintenance. www.getmyuni.com
  • 13. Language Design Issues • Design to •Run efficiently : early languages •Easy to write correctly : new languages •Data typing features in ML •Class of C++ •Package of Ada www.getmyuni.com
  • 14. The Structure And Operation Of A Computer • A computer is an integrated set of algorithms and data structures capable of storing and executing programs. •Hardware computer or •virtual computer www.getmyuni.com
  • 15. Computer Architecture •Well-known computer architecture: Von Neumann • Imperative languages, most dominant, because of von Neumann computers – Data and programs stored in memory – Memory is separate from CPU – Instructions and data are piped from memory to CPU – Basis for imperative languages • Variables model memory cells • Assignment statements model piping • Iteration is efficient www.getmyuni.com
  • 16. The von Neumann Architecture www.getmyuni.com
  • 17. Virtual Computers • Hardware realization •Physical devices • Firmware realization •microprogramming • Software simulation •Some other programming language • Combination of these techniques www.getmyuni.com
  • 18. Major Components of a Computer • Data •Various kinds of elementary and structured data. • Primitive operations • Sequence control •Controlling the sequence of primitive operations execution. www.getmyuni.com
  • 19. Major Components of a Computer • Data access •Controlling the data supplied to each execution of an operation. • Storage management •Controlling the allocation of storage for programs and data. • Operating environment •Providing mechanisms for communication with an external environment containing programs and data. www.getmyuni.com
  • 20. Data • Main memory • High-speed register • High-speed cache memory • External files Data and Program www.getmyuni.com
  • 21. Operations • A set of build-in primitive operations •Arithmetic operations on each built-in numeric data (+,-,*,/) •Testing various properties of data items (test for zero, positive, and negative numbers) •Accessing and modifying various parts of a data item •Controlling input-output devices •Sequence control (jumps) www.getmyuni.com
  • 22. Sequence Control • There is an interpreter : •Fetch the instruction •Decode instruction •Fetch designated operands •Branch to designated operation •Execute primitive operations 1 to n Using an address register www.getmyuni.com
  • 23. Data Access • Access to operands of the operation www.getmyuni.com
  • 24. Storage Management • Keeping all resources of the computer operating as much as possible •Memory •Central processor •External data devices Multiprogramming Cache memory www.getmyuni.com
  • 25. Operating Environment • The outside world of computer; a set of peripherals and input-output devices www.getmyuni.com
  • 26. Language Paradigms • Imperative / procedural languages • Applicative / functional languages • Rule-based / declarative languages • Object-oriented languages www.getmyuni.com
  • 27. Imperative / procedural languages Statement oriented languages that change machine state (C, Pascal, FORTRAN, COBOL) Computation: a sequence of machine states (contents of memory) Syntax: S1, S2, S3, ... where S1, S2, … are statements www.getmyuni.com
  • 28. Applicative / functional languages Programming consists of building the function that computes the answer Computation: Function composition is major operation (ML, LISP) Syntax: P1(P2(P3(X))) www.getmyuni.com
  • 29. Rule-based / declarative languages Computation: Actions are specified by rules that check for the presence of certain enabling conditions. (Prolog) The order of execution is determined by the enabling conditions, not by the order of the statements. Syntax: Condition  Action www.getmyuni.com
  • 30. Object-oriented languages Imperative languages that merge applicative design with imperative statements (Java, C++, Smalltalk) Syntax: Set of objects (classes) containing data (imperative concepts) and methods (applicative concepts) www.getmyuni.com
  • 31. Language Translation issues •Programming language Syntax • Key criteria concerning syntax • Basic syntactic concepts • Overall Program-Subprogram structure •Stages in Translation • Analysis of the source program • Synthesis of the object program • Bootstrapping www.getmyuni.com
  • 32. Syntax The syntax of a programming language describes the structure of programs without any consideration of their meaning. www.getmyuni.com
  • 33. Key criteria concerning syntax Readability – a program is considered readable if the algorithm and data are apparent by inspection. Write-ability – ease of writing the program. Verifiability – ability to prove program correctness (very difficult issue) Translatability – ease of translating the program into executable form. Lack of ambiguity – the syntax should provide for ease of avoiding ambiguous structures www.getmyuni.com
  • 34. Basic Syntactic Concepts • Character set – The alphabet of the language. Several different character sets are used: ASCII, EBCIDIC, Unicode • Identifiers – strings of letters of digits usually beginning with a letter • Operator Symbols – +-*/ • Keywords or Reserved Words – used as a fixed part of the syntax of a statement www.getmyuni.com
  • 35. Basic Syntactic Concepts • Noise words – optional words inserted into statements to improve readability • Comments – used to improve readability and for documentation purposes. Comments are usually enclosed by special markers • Blanks – rules vary from language to language. Usually only significant in literal strings www.getmyuni.com
  • 36. Basic Syntactic Concepts • Delimiters – used to denote the beginning and the end of syntactic constructs • Expressions – functions that access data objects in a program and return a value • Statements – these are the sentences of the language, they describe a task to be performed www.getmyuni.com
  • 37. Overall Program-Subprogram Structure Separate subprogram definitions: Separate compilation, linked at load time E.g. C/C++ Separate data definitions: General approach in OOP. Nested subprogram definitions: Subprogram definitions appear as declarations within the main program or other subprograms. E.g. Pascal www.getmyuni.com
  • 38. Overall Program-Subprogram Structure Separate interface definitions: C/C++ header files Data descriptions separated from executable statements. A centralized data division contains all data declarations. E.g. COBOL Un-separated subprogram definitions: No syntactic distinction between main program statements and subprogram statements. E.g. BASIC www.getmyuni.com
  • 39. Stages in Translation • Analysis of the source program • Synthesis of the object program • Bootstrapping www.getmyuni.com
  • 40. Analysis of the source program Lexical analysis (scanning) – identifying the tokens of the programming language: keywords, identifiers, constants and other symbols In the program void main() { printf("Hello Worldn"); } the tokens are void, main, (, ), {, printf, (, "Hello Worldn", ), ;, } www.getmyuni.com
  • 41. Syntactic and Semantic Analysis Syntactic analysis (parsing) – determining the structure of the program, as defined by the language grammar. Semantic analysis - assigning meaning to the syntactic structures Example: int variable1; meaning: 4 bytes for variable1 , a specific set of operations to be used with variable1. www.getmyuni.com
  • 42. Basic Semantic Tasks The semantic analysis builds the bridge between analysis and synthesis. Basic semantic tasks: • Symbol–table maintenance • Insertion of implicit information • Error detection • Macro processing Result : an internal representation, suitable to be used for code optimization and code generation. www.getmyuni.com
  • 43. Synthesis of the object program Three main steps: Optimization - Removing redundant statements Code generation - generating assembler commands with relative memory addresses for the separate program modules - obtaining the object code of the program. Linking and loading - resolving the addresses - obtaining the executable code of the program. www.getmyuni.com
  • 44. Optimization example Intermediate code: Temp1 = B + C Temp2 = Temp1 + D A = Temp2 Assembler code not optimized: LOAD_R B ADD_R C STORE_R Temp1 LOAD_R Temp1 ADD_R D STORE_R Temp2 LOAD_R Temp2 STORE_R A Statements in yellow can be removed www.getmyuni.com
  • 45. Bootstrapping The compiler for a given language can be written in the same language. • A program that translates some internal representation into assembler code. • The programmer manually re-writes the compiler into the internal representation, using the algorithm that is encoded into the compiler. From there on the internal representation is translated into assembler and then into machine language. www.getmyuni.com
  • 46. Syntax and Semantics • Syntax: what the program looks like. • Semantics: the meaning given to the various syntactic constructs. Example: V: array [0..9] of integer; int V[10]; www.getmyuni.com