+ All Categories
Home > Education > Compiler

Compiler

Date post: 30-Jul-2015
Category:
Upload: igz-software-house
View: 44 times
Download: 2 times
Share this document with a friend
Popular Tags:
11
Date :- 16,jan,2015 Compiler Presented to: Sir Khalid Mehmood Group Name: Tech Routers Members: Muhammad Ahtisham 2813 Nouman Chudhary 2463 Waqas Ahmad 2481 Junaid Pervaiz 2468 Umair Ilyas 2809 Jawad Mian 2490 Sohaib Raza 2497 Muhammad Waqas 2803
Transcript

Date :- 16,jan,2015

CompilerPresented to: Sir Khalid Mehmood

Group Name: Tech RoutersMembers:

Muhammad Ahtisham 2813 Nouman Chudhary 2463

Waqas Ahmad 2481Junaid Pervaiz 2468

Umair Ilyas 2809Jawad Mian 2490Sohaib Raza 2497Muhammad Waqas 2803

What Do Compilers Do (1)

2

A compiler acts as a translator, transforming human-oriented programming languages into computer-oriented machine languages.

Ignore machine-dependent details for programmer

Programming Language(Source)

CompilerMachineLanguage(Target)

3

Any compiler must perform two major tasks

Analysis of the source program Synthesis of a machine-language program

The Structure of a Compiler (1)

Compiler

Analysis Synthesis

Preprocessors, Compilers, Assemblers, and Linkers

Preprocessor

Compiler

Assembler

Linker

Skeletal Source Program

Source Program

Target Assembly Program

Relocatable Object Code

Absolute Machine Code

Libraries andRelocatable Object Files

Try for example:gcc -v myprog.c

The Structure of a Compiler (2)

5

Scanner ParserSemanticRoutines

CodeGenerator

Optimizer

SourceProgram Tokens Syntactic

Structure

Symbol andAttribute

Tables

(Used by all Phases of The Compiler)

(Character Stream)

IntermediateRepresentation

Target machine code

The Structure of a Compiler (3)

6

Scanner ParserSemanticRoutines

CodeGenerator

Optimizer

SourceProgram Tokens Syntactic

Structure

Symbol andAttribute

Tables

(Used by allPhases of The Compiler)

Scanner The scanner begins the analysis of the source

program by reading the input, character by character, and grouping characters into individual words and symbols (tokens)

RE ( Regular expression ) NFA ( Non-deterministic Finite Automata ) DFA ( Deterministic Finite Automata )

(Character Stream)

IntermediateRepresentation

Target machine code

The Structure of a Compiler (4)

7

Scanner ParserSemanticRoutines

CodeGenerator

Optimizer

SourceProgram Tokens Syntactic

Structure

Symbol andAttribute

Tables

(Used by allPhases of The Compiler)

Parser Given a formal syntax specification (typically as a

context-free grammar [CFG] ), the parse reads tokens and groups them into units as specified by the productions of the CFG being used.

As syntactic structure is recognized, the parser either calls corresponding semantic routines directly or builds a syntax tree.

CFG ( Context-Free Grammar ) GAA ( Grammar Analysis Algorithms )

(Character Stream)

IntermediateRepresentation

Target machine code

The Structure of a Compiler (5)

8

Scanner ParserSemanticRoutines

CodeGenerator

Optimizer

SourceProgram

(Character Stream)

Tokens Syntactic

Structure

IntermediateRepresentation

Symbol andAttribute

Tables

(Used by allPhases of The Compiler)

Semantic Routines Perform two functions

Check the static semantics of each construct Do the actual translation

The heart of a compiler

Syntax Directed Translation Semantic Processing Techniques IR (Intermediate Representation)

Target machine code

The Structure of a Compiler (6)

9

Scanner ParserSemanticRoutines

CodeGenerator

Optimizer

SourceProgram Tokens Syntactic

Structure

Symbol andAttribute

Tables

(Used by allPhases of The Compiler)

Optimizer The IR code generated by the semantic routines is

analyzed and transformed into functionally equivalent but improved IR code

This phase can be very complex and slow loop optimization, register allocation, code

scheduling

Register and Temporary Management

(Character Stream)

IntermediateRepresentation

Target machine code

The Structure of a Compiler (7)

10

SourceProgram

(Character Stream)

ScannerTokens

ParserSyntactic

StructureSemanticRoutines

IntermediateRepresentation

Optimizer

CodeGenerator

Code Generator Interpretive Code Generation Generating Code from Tree/Dag Grammar-Based Code Generator

Target machine code

The Structure of a Compiler (8)

11

Scanner [Lexical Analyzer]

Parser [Syntax Analyzer]

Semantic Process [Semantic analyzer]

Code Generator[Intermediate Code Generator]

Code Optimizer

Tokens

Parse tree

Abstract Syntax Tree w/ Attributes

Non-optimized Intermediate Code

Optimized Intermediate Code

Code Optimizer

Target machine code


Recommended