Compiler Chap'1 Introduction to Compiler - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Compiler Chap'1 Introduction to Compiler

Description:

Directed by a simple understanding of the phrase structure ... Parser and part of code generator performing semantic analysis is called constrainer by pittman ... – PowerPoint PPT presentation

Number of Views:119
Avg rating:3.0/5.0
Slides: 13
Provided by: suno
Category:

less

Transcript and Presenter's Notes

Title: Compiler Chap'1 Introduction to Compiler


1
CompilerChap.1 Introduction to Compiler
  • Internet Management Technology Lab.

2
Contents
  • Introduction
  • Conceptual view of the compilation process
  • The phases of a compiler

3
Introduction
  • Definition of compiler
  • A program which accepts phrases written in an
    input language (source language) and produces
    equivalent phrases in the desired output language
    (target language)
  • e.g. assembler assembly ? machine language
  • Characteristics of compiler
  • Directed by a simple understanding of the phrase
    structure (grammar) of an input language
  • Usually contains complex mapping algorithms
  • Generates a target code for efficiency while an
    interpreter does not generate a target code for
    flexibility

4
Conceptual View of Compilation Process
ltA language-processing systemgt
5
The phases of a compiler Architecture
ltAnalysis of the source programgt
6
The phases of a compiler Lexical Analysis
  • Lexical Analysis Phase
  • Reads in the characters from the source program
  • Groups the characters into grammatically
    significant chunks called lexemes or tokens
  • A token is a logically cohesive sequence of
    characters - keyword, constant, operator,
    identifier, etc.
  • Outputs the tokens to the syntax analysis phase
  • Performed by a lexer (or scanner) and the
    efficiency is one of the important issues
  • Example Find tokens from the following example

if( a lt 3.5 )        bottom a else
       bottom
7
The phases of a compiler Syntax Anaysis
  • Syntax Analysis phase
  • Imposes a hierarchical structure on the token
    stream by the language syntax
  • Optionally builds an Abstract Syntax Tree (AST)
  • AST represents the structure of the source
    program
  • AST is one of the Intermediate representation
    form
  • Performed by a parser

8
The phases of a compiler Intermediate Rep.
  • AST from the example 1

9
The phases of a compiler Semantic Analysis
  • Semantic Analysis Phase
  • Checks the meaning of the constructs
  • Most of the semantic analysis is done by a parser
  • Some could be done by lexer or code generator
  • Parser and part of code generator performing
    semantic analysis is called constrainer by
    pittman
  • Type checking, uniqueness
  • Int a, real b
  • a b

10
The phases of a compiler Optimization
  • Code optimization Phase
  • Optional phase for performance enhancement such
    as
  • Reducing execution time
  • Saving memory space
  • Reducing communication bandwidth
  • Performed by a code optimizer

for(j 0 j lt MAX j)    m 24   
sum sum xj m could be rewritten as
m 24 for(j 0 j lt MAX j)    sum
xj m
11
The phases of a compiler Code Generation
  • Code Generation Phase
  • Translates intermediate representation (or output
    from the parser) into a target code
  • Performed by a code generator
  • e.g.
  • a a 1
  • Generates the following assembly-like pseudo code

LD                 R1, a ADD               R1,
R1, 1 ST          a, R1
12
Homework I
  • Compare compiler and interpreter with regard to
    the space complexity and the time complexity,
    then discuss the applications areas where using
    interpreters are better than compilers.
  • How the compiler architecture presented in class
    could be modified for better flexibilities?
  • How each 4 modules in the architecture
    contributes to the syntax analysis and semantic
    analysis respectively?
  • What are the advantages of having the phases such
    as lexical analysis phase, syntax analysis phase,
    and so on be separately modularized ?
Write a Comment
User Comments (0)
About PowerShow.com