Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

UNIT-I

What is a compiler?
A program that reads a program written in one
language and translates it into another
language.
Source language

Target language

Traditionally, compilers go from high-level


languages to low-level languages.

CS 540 Spring 2013 GMU

Compiler Architecture
In more detail:
Intermediate
Language
Source
Language

Front End
language specific

Back End
machine specific

Target Language

Separation of Concerns
Retargeting

CS 540 Spring 2013 GMU

Intermediate
Language
Source
language

Scanner
(lexical
analysis)

tokens

Parser
(syntax
analysis)

Syntactic
structure

Semantic
Analysis
(IC generator)

Intermediate
Language

Code
Optimizer

Code
Generator

Target
language

Symbol
Table

CS 540 Spring 2013 GMU

Source
languag
e

Scanner
(lexical
analysis)

tokens

Parser
(syntax
analysis)

Semantic
Analysis
(IC generator)

Code
Generator

Code
Optimizer

Tokens described formally


Breaks input into tokens
Remove white space

Symbol
Table

CS 540 Spring 2013 GMU

Input: result = a + b * c / d
Tokens:

result, =, a, +, b, *, c, /, d
identifiers
operators

CS 540 Spring 2013 GMU

Source
language

Scanner
(lexical
analysis)

tokens

Parser
(syntax
analysis)

Syntactic
structure

Semantic
Analysis
(IC generator)

Code
Generator

Target
language

Code
Optimizer

Syntax described formally


Tokens organized into syntax tree
that describes structure
Error checking (syntax)

Symbol
Table

CS 540 Spring 2013 GMU

Input: result = a + b * c /
d
Exp

::= Exp + Exp


|
Exp - Exp
|
Exp * Exp
|
Exp / Exp
|
ID

Assign ::=

ID = Exp

Assign

ID

Exp
Exp + Exp
ID

Exp * Exp
ID

Exp / Exp
ID

CS 540 Spring 2013 GMU

ID

Source
language

Scanner
(lexical
analysis)

Parser
(syntax
analysis)

Syntactic
structure

Syntactic/semantic
structure

Semantic
Analysis
(IC generator)

Code
Generator

Target
language

Syntactic/semantic
structure

Code
Optimizer

Meaning
Type/Error Checking
Intermediate Code Generation
abstract machine

Symbol
Table

CS 540 Spring 2013 GMU

Source
language

Scanner
(lexical
analysis)

Parser
(syntax
analysis)

Semantic
Analysis
(IC generator)

Code
Generator

Target
language

Syntactic/semantic
structure

Code
Optimizer

Improving efficiency (machine


independent)
Finding optimal code is NP

Syntactic/semantic
structure

Symbol
Table

CS 540 Spring 2013 GMU

10

Syntactic/semantic
structure
Source
language

Scanner
(lexical
analysis)

Parser
(syntax
analysis)

Semantic
Analysis
(IC generator)

Code
Optimizer

IC to real machine code


Memory management, register
allocation, instruction selection,
instruction scheduling,

Code
Generator

Target
language

Syntactic/semantic
structure

Symbol
Table

CS 540 Spring 2013 GMU

11

Issues Driving Compiler


Design
Correctness
Speed (runtime and compile time)
Degrees of optimization
Multiple passes
Space
Feedback to user
Debugging

CS 540 Spring 2013 GMU

12

Related to Compilers
Interpreters (direct execution)
Assemblers
Preprocessors
Text formatters (non-WYSIWYG)
Analysis tools

CS 540 Spring 2013 GMU

13

You might also like