chapter 1 introduction n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter 1. Introduction PowerPoint Presentation
Download Presentation
Chapter 1. Introduction

Loading in 2 Seconds...

play fullscreen
1 / 27

Chapter 1. Introduction - PowerPoint PPT Presentation


  • 82 Views
  • Uploaded on

Chapter 1. Introduction. Outline. Language Processors The Structure of a Compiler The Evolution of Programming Languages Why study principle of programming languages. Language Processors. A compiler. source program. Compiler. target program. Running the target program. Target Program.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chapter 1. Introduction' - drea


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
outline
Outline
  • Language Processors
  • The Structure of a Compiler
  • The Evolution of Programming Languages
  • Why study principle of programming languages
language processors
Language Processors
  • A compiler

source program

Compiler

target program

slide4
Running the target program

Target Program

input

output

slide5
An interpreter
    • Much slower program execution
    • Better error diagnostics

Interpreter

source program

output

input

slide6
A hybrid compiler, e.g. Java

source program

Translator

intermediate program

Virtual Machine

output

input

outline1
Outline
  • Language Processors
  • The Structure of a Compiler
  • The Evolution of Programming Languages
  • Why study principle of programming languages
a language processing system
A Language Processing System

source program

Preprocessor

modified source program

Compiler

target assembly program

Assembler

relocatable machine code

library filesrelocatable object files

Linker/Loader

target machine code

the structure of a compiler
The Structure of a Compiler
  • Analysis
    • Front end
    • Using a grammatical structure to create an intermediate representation
    • Collecting information about the source program in a symbol table
  • Synthesis
    • Back end
    • Constructing the target program from the intermediate representation and the symbol table
phases of a compiler
Phases of a Compiler

character stream

Lexical Analyzer

token stream

SymbolTable

Syntax Analyzer

syntax tree

(optional)

Semantic Analyzer

syntax tree

Machine-Independent Code Optimization

Intermediate Code Generator

intermediate representation

Code Generator

Machine-Dependent Code Optimization

(optional)

target machine code

lexical analysis scanning
Lexical Analysis (Scanning)
  • Grouping characters into lexemes
  • E.g.
    • position = initial + rate * 60
    • <id,1> <=> <id,2> <+> <id,3> <*> <60>
syntax analysis parsing
Syntax Analysis (Parsing)
  • Creating a tree-like (e.g. syntax tree) intermediate representation that depicts the grammatical structure of the token streams
    • E.g.
    • <id,1> <=> <id,2> <+> <id,3> <*> <60>

=

+

<id, 1>

*

<id, 2>

60

<id, 3>

semantic analysis
Semantic Analysis
  • Type checking
  • Type conversions or coercions
  • E.g.

=

+

<id, 1>

*

<id, 2>

<id, 3>

int2float

60

intermediate code generation
Intermediate Code Generation
  • Generating a low-level intermediate representation
    • It should be easy to produce
    • It should be easy to translate into the target machine
    • E.g. three-address code

t1 = int2float(60)t2 = id3 * t1t3 = id2 + t2id1 = t3

code optimization
Code Optimization
  • Attempts to improve the intermediate code
    • Better: faster, shorter code, or code that consumes less power (Chap. 8 -)
    • E.g.
      • t1 = id3 * 60.0id1 = id2 + t1
code generation
Code Generation
  • Mapping intermediate representation of the source program into the target language (Chap. 8)
    • Machine code: register/memory location assignments
    • E.g.
      • LDF R2, id3MULF R2, R2, #60.0LDF R1, id2ADDF R1, R1, R2STF id1, R1
symbol table management
Symbol Table Management
  • To record the variable names and collect information about various attributes of each name
    • Storage, type, scope
    • Number and types of arguments, method of argument passing, and the type returned
grouping of phases into passes
Grouping of Phases into Passes
  • Front-end pass
    • Lexical analysis, syntax analysis, semantic analysis, intermediate code generation
  • (Optional) Code optimization pass
  • Back-end pass
    • Code generation
outline2
Outline
  • Language Processors
  • The Structure of a Compiler
  • The Evolution of Programming Languages
  • Why study principle of programming languages
the evolution of programming languages
The Evolution of Programming Languages
  • Machine language: 1940’s
  • Assembly language: early 1950’s
  • Higher-level languages: late 1950’s
    • Fortran: scientific computation
    • Cobol: business data processing
    • Lisp: symbolic computation
  • Today: thousands of programming languages
classification of programming languages by generation
Classification of Programming Languages – by Generation
  • First generation: machine languages
  • Second generation: assembly languages
  • Third generation: high-level languages
    • Fortran, Cobol, Lisp, C, C++, C#, Java
  • Fourth generation: specific application
    • NOMAD, SQL, Postscript
  • Fifth generation: logic- and constraint-based
    • Prolog, OPS5
classification of programming languages by functions
Classification of Programming Languages - by Functions
  • Imperative: how
    • C, C++, C#, Java
  • Declarative: what
    • ML, Haskell, Prolog
  • von Neumann language
    • Fortran, C
  • Object-oriented language
    • Simula 67, Smalltalk, C++, C#, Java, Ruby
  • Scripting languages
    • Awk, JavaScript, Perl, PHP, Python, Ruby, Tcl
impacts on compilers
Impacts on Compilers
  • To translate and support new language features
  • To take advantage of new hardware capabilities
  • To promote the use of high-level languages by minimizing the execution overhead
  • To make high-performance computer architectures effective on users’ applications
  • To evaluate architectural concepts
outline3
Outline
  • Language Processors
  • The Structure of a Compiler
  • The Evolution of Programming Languages
  • Why study principle of programming languages
why study principle of programming languages
Why study principle of programming languages?
  • Become a better software engineer
    • Understand how to use language features
    • Appreciate implementation issues
  • Better background for language selection
    • Familiar with range of languages
    • Understand issues / advantages / disadvantages
  • Better able to learn languages
    • You might need to know a lot
why study programming languages
Why study programming languages?
  • Better understanding of implementation issues
    • How is “this feature” implemented?
    • Why does “this part” run so slowly?
  • Better able to design languages
    • Those who ignore history are bound to repeat it…