SlideShare a Scribd company logo
Introduction to Compiler
Construction (Lecture 1)
Natural Languages
• What are Natural Languages?
• How do you understand the language?
• If you know multiple languages then how
can you recognize each of them?
• How you know which sentence is correct
and which one is incorrect?
Programming Languages
• What are programming languages?
• How do you understand the programming
language?
• If you know multiple programming
languages then how can you recognize each
of them?
• How do you know which syntax is correct
and which one is incorrect?
Compilers and Interpreters
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
– It also reports to its users the presence of errors
in the source program
– C++ uses compiler
Compiler
Error messages
Source
Program
Target
Program
Input
Output4
Compilers and Interpreters
Interpreter
Source
Program
Input
Output
Error messages
• “Interpretation”
– Interpreter is a program that reads an executable
program and produces the results of running that
program. OR
– Instead of producing a target program as a translation,
an interpreter performs the operations implied by the
source program.
– GWBASIC is an example of Interpreter
5
Why study compilers?
• Application of a wide range of theoretical
techniques
– Data Structures
– Theory of Computation
– Algorithms
– Computer Architecture
• Good SW engineering experience
• Better understanding of programming
languages
Features of compilers
• Correctness
– preserve the meaning of the code
• Speed of target code
• Recognize legal and illegal program.
• Speed of compilation
• Good error reporting/handling
• Cooperation with the debugger
• Manage storage of all variables and codes.
• Support for separate compilation
Introduction to Compiler
Construction (Lecture 2)
Classification of Compilers
1. Single Pass Compilers
2. Two Pass Compilers
3. Multipass Compilers
Single Pass Compiler
• Source code directly transforms into
machine code.
– For example Pascal
source
code
target
code
Front EndCompiler
Two Pass Compiler
• Use intermediate representation
– Why?
source
code
target
code
Front End Back End
IR
Front End
Two pass compiler
• intermediate representation (IR)
• front end maps legal code into IR
• back end maps IR onto target machine
• simplify retargeting
• allows multiple front ends
• multiple passes ⇒ better code
12
© Oscar Nierstrasz
Multipass compiler
• analyzes and changes IR
• goal is to reduce runtime
• must preserve values
13
Comparison
• One pass compilers are generally faster than
Multipass Compilers
• Multipass ensures the correctness of small
program rather than the correctness of a
large program (high quality code)
Lecture 3
Front end
• recognize legal code
• report errors
• produce IR
• preliminary storage map
• shape code for the back end
16
Scanner
• Breaks the source code text into small
pieces called tokens.
• It is also known as Lexical Analyzer
Scanner / Lexical Analyser
• map characters to tokens
• character string value for a token is a lexeme
• eliminate white space
x = x + y <id,x> = <id,x> + <id,y>
18
Syntactic Analysis – Parsing
Majid ate the apple
Front end –Analysis– Machine
Independent
• The front end consists of those phases, that
depend primarily on the source language
and are largely independent of the target
machine.
Parser
• recognize context-free syntax
• guide context-sensitive analysis
• construct IR(s)
• produce meaningful error messages
• attempt error correction
21
BACK END
• Synthesis process
• Machine dependent
• The back end includes those portions of the
compiler that depends on the target machine
and generally, these portions do not depend
on the source language
Back end
• translate IR into target machine code
• choose instructions for each IR operation
• decide what to keep in registers at each point
• ensure conformance with system interfaces
23
Compiler Structure
• Front end
– Front end Maps legal code into IR
– Recognize legal/illegal programs
• report/handle errors
– Generate IR
– The process can be automated
• Back end
– Translate IR into target code
• instruction selection
• register allocation
• instruction scheduling
Lecture 4
The Analysis-Synthesis Model
of Compilation
• There are two parts to compilation:
– Analysis determines the operations implied by
the source program which are recorded in a tree
structure
– Synthesis takes the tree structure and translates
the operations therein into the target program
26
ANALYSIS PROCEDURE
• During analysis, the operation implied by
the source program are determined and
recorded in a hierarchical structure called a
tree.
• Often a special type of tree called a Syntax
tree in which each node represents an
operation and the children of a node
represent the arguments of the operation.
Lexical Analyzer
Syntax Analyzer
Semantic Analyzer
character stream position = initial + rate * 60
<id,1> <=> <id,2> <+> <id,3> <*> <60>
=
<id,1>
<id,2>
<id,3>
+
*
60
=
<id,1>
<id,2>
<id,3>
+
*
inttofloat
60
REMEMBER
The front end is responsible for
analysis process while the back
end is responsible for Synthesis
Other Tools that Use the
Analysis-Synthesis Model
• Editors (syntax highlighting)
• Pretty printers (e.g. Doxygen)
• Static checkers (e.g. Lint and Splint)
• Interpreters
• Text formatters (e.g. TeX and LaTeX)
• Silicon compilers (e.g. VHDL)
• Query interpreters/compilers (Databases)
30
Structure Editors
• A structure editor takes as input a sequence of
commands to build a source program.
• The structure editor not only performs the text
creation and modification functions of an ordinary
text editor but it also analyzes the program text,
putting an appropriate hierarchical structure on the
source program.
• Thus the structure editor can perform additional
tasks that are useful in the preparation of
programs.
Structure Editors (cont..)
• For example, it can check that the input is
correctly formed, can supply key words
automatically (e.g. when the user types
while the editor supplies the matching do
and reminds the user that a conditional must
come between them).
Pretty printers
• A pretty printer analyzes a program and
prints it in such a way that the structure of
the program becomes clearly visible.
• For example comments may appear in a
special font, and the statements may appear
with an amount of indentation proportional
to the depth of their nesting in the
hierarchical organization of the statement.
Static Checkers
• A static checker reads a program, analyzes it, and
attempts to discover potential bugs without
running the program.
• A static checker may detect that parts of the source
program can never be executed, or that a certain
variable might be used before being defined.
• In addition, it can catch logical errors such as
trying to use a real variable as a pointer,
employing the type checking techniques.
Interpreters• Instead of producing a target program as a
translation, an interpreter performs the
operations implied by the source program.
• For example, for an assignment statement
an interpreter might build a tree and then
carry out the operations at the nodes as it
“walks” the tree.
:=
<id,1>
<id,2>
<id,3>
+
*
60
position := initial + rate * 60
Interpreters (cont..)• At the root it would discover it had an assignment to
perform, so it would call a routine to evaluate the
expression on the right, and then store the resulting value
in the location associated with the identifier position.
• At the right child of the root, the routine would discover it
had to compute the sum of two expressions
• It would call itself recursively to compute the value of
expression rate * 60
• It would then add that value to the value of the variable
initial
Text Formatters
• A text formatter takes input that is a stream
of characters, most of which is text to be
typeset, but some of which includes
commands to indicate paragraphs, figures or
mathematical structures like subscripts and
superscripts.
Silicon compilers
• A silicon compiler has a source language
that is similar or identical to a conventional
programming language.
• However, the variables of the language
represent, not locations in memory but
logical signals (0 or 1) or groups of signals
in a switching circuit.
Query interpreters
• A query interpreter translates a predicate
containing relational and Boolean operators
into commands to search a database for
records satisfying that predicate.
JIT compilation

More Related Content

What's hot (20)

PPT
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
PPTX
Error Detection & Recovery
Akhil Kaushik
 
PDF
Lecture 01 introduction to compiler
Iffat Anjum
 
PPT
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
PDF
Syntax analysis
Akshaya Arunan
 
PPTX
Lexical Analysis - Compiler Design
Akhil Kaushik
 
PDF
Code optimization in compiler design
Kuppusamy P
 
PPTX
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
PPT
Compiler Design
Mir Majid
 
PPTX
Phases of compiler
Akhil Kaushik
 
PPTX
Principal Sources of Optimization in compiler design
LogsAk
 
PPTX
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
PPT
Compiler Construction
Army Public School and College -Faisal
 
PDF
Compiler Construction | Lecture 1 | What is a compiler?
Eelco Visser
 
PPTX
Phases of Compiler
Tanzeela_Hussain
 
PPTX
Compiler Chapter 1
Huawei Technologies
 
PPT
phases of a compiler
Ms.SHANTHI.S CSE
 
PPTX
Specification-of-tokens
Dattatray Gandhmal
 
PPTX
Syntax Analysis in Compiler Design
MAHASREEM
 
PPTX
Input-Buffering
Dattatray Gandhmal
 
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Error Detection & Recovery
Akhil Kaushik
 
Lecture 01 introduction to compiler
Iffat Anjum
 
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Syntax analysis
Akshaya Arunan
 
Lexical Analysis - Compiler Design
Akhil Kaushik
 
Code optimization in compiler design
Kuppusamy P
 
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
Compiler Design
Mir Majid
 
Phases of compiler
Akhil Kaushik
 
Principal Sources of Optimization in compiler design
LogsAk
 
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Compiler Construction | Lecture 1 | What is a compiler?
Eelco Visser
 
Phases of Compiler
Tanzeela_Hussain
 
Compiler Chapter 1
Huawei Technologies
 
phases of a compiler
Ms.SHANTHI.S CSE
 
Specification-of-tokens
Dattatray Gandhmal
 
Syntax Analysis in Compiler Design
MAHASREEM
 
Input-Buffering
Dattatray Gandhmal
 

Viewers also liked (19)

PPT
Compiler Construction
Sarmad Ali
 
PPTX
Compiler Construction Course - Introduction
Muhammad Sanaullah
 
PPT
Lexical analyzer
Ashwini Sonawane
 
PPT
Compiler Design Basics
Akhil Kaushik
 
DOC
Compiler Design(NANTHU NOTES)
guest251d9a
 
PPTX
Compilers
Bense Tony
 
PDF
Introduction to Functional Languages
suthi
 
PPTX
Passescd
BBDITM LUCKNOW
 
PPT
Classification of Compilers
Sarmad Ali
 
PPT
Compiler Design Tutorial
Sarit Chakraborty
 
PDF
Compiler unit 1
BBDITM LUCKNOW
 
PPTX
Compilers
Satyamevjayte Haxor
 
PDF
Assesing speaking skills
syed ahmed
 
PPTX
Compiler construction
Muhammed Afsal Villan
 
PPTX
7 compiler lab
MashaelQ
 
PDF
MTech Seminar Presentation [IIT-Bombay]
Sagar Ahire
 
Compiler Construction
Sarmad Ali
 
Compiler Construction Course - Introduction
Muhammad Sanaullah
 
Lexical analyzer
Ashwini Sonawane
 
Compiler Design Basics
Akhil Kaushik
 
Compiler Design(NANTHU NOTES)
guest251d9a
 
Compilers
Bense Tony
 
Introduction to Functional Languages
suthi
 
Passescd
BBDITM LUCKNOW
 
Classification of Compilers
Sarmad Ali
 
Compiler Design Tutorial
Sarit Chakraborty
 
Compiler unit 1
BBDITM LUCKNOW
 
Assesing speaking skills
syed ahmed
 
Compiler construction
Muhammed Afsal Villan
 
7 compiler lab
MashaelQ
 
MTech Seminar Presentation [IIT-Bombay]
Sagar Ahire
 
Ad

Similar to Introduction to Compiler Construction (20)

PPTX
Compiler an overview
amudha arul
 
PPT
Introduction to compiler design and phases of compiler
Ranjeet Reddy
 
PPTX
Compiler Design Introduction With Design
rashmishekhar81
 
PPTX
Compiler Design Introduction
Thapar Institute
 
PPT
Compiler Design Basics
Akhil Kaushik
 
PPTX
4_5802928814682016556.pptx
AshenafiGirma5
 
PPTX
Cd ch1 - introduction
mengistu23
 
PPTX
CD - CH1 - Introduction to compiler design.pptx
ZiyadMohammed17
 
PPTX
Compiler Construction from very basic start
voyoc79528
 
PPTX
Chapter 1.pptx
NesredinTeshome1
 
PDF
Compilers Principles, Practice & Tools Compilers
ssuser964532
 
PPTX
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
PPT
Concept of compiler in details
kazi_aihtesham
 
PPTX
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 
PPTX
Introduction to Compilers
Akhil Kaushik
 
PPTX
Unit 1 part1 Introduction of Compiler Design.pptx
Neelkaranbind
 
PPTX
Compiler Construction
Ahmed Raza
 
PDF
Chapter1pdf__2021_11_23_10_53_20.pdf
DrIsikoIsaac
 
DOCX
Techniques & applications of Compiler
Preethi AKNR
 
PPTX
COMPILER DESIGN PPTS.pptx
MUSHAMHARIKIRAN6737
 
Compiler an overview
amudha arul
 
Introduction to compiler design and phases of compiler
Ranjeet Reddy
 
Compiler Design Introduction With Design
rashmishekhar81
 
Compiler Design Introduction
Thapar Institute
 
Compiler Design Basics
Akhil Kaushik
 
4_5802928814682016556.pptx
AshenafiGirma5
 
Cd ch1 - introduction
mengistu23
 
CD - CH1 - Introduction to compiler design.pptx
ZiyadMohammed17
 
Compiler Construction from very basic start
voyoc79528
 
Chapter 1.pptx
NesredinTeshome1
 
Compilers Principles, Practice & Tools Compilers
ssuser964532
 
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
Concept of compiler in details
kazi_aihtesham
 
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 
Introduction to Compilers
Akhil Kaushik
 
Unit 1 part1 Introduction of Compiler Design.pptx
Neelkaranbind
 
Compiler Construction
Ahmed Raza
 
Chapter1pdf__2021_11_23_10_53_20.pdf
DrIsikoIsaac
 
Techniques & applications of Compiler
Preethi AKNR
 
COMPILER DESIGN PPTS.pptx
MUSHAMHARIKIRAN6737
 
Ad

More from Sarmad Ali (11)

PPTX
Network Engineer Interview Questions with Answers
Sarmad Ali
 
PDF
RDBMS Model
Sarmad Ali
 
PDF
RDBMS Algebra
Sarmad Ali
 
PDF
RDBMS ERD
Sarmad Ali
 
PDF
RDBMS ER2 Relational
Sarmad Ali
 
PDF
RDBMS Arch & Models
Sarmad Ali
 
PDF
RDBMS ERD Examples
Sarmad Ali
 
PPT
Management Information System-MIS
Sarmad Ali
 
PDF
Introduction to RDBMS
Sarmad Ali
 
PDF
About Data Base
Sarmad Ali
 
PPT
Management information system-MIS
Sarmad Ali
 
Network Engineer Interview Questions with Answers
Sarmad Ali
 
RDBMS Model
Sarmad Ali
 
RDBMS Algebra
Sarmad Ali
 
RDBMS ERD
Sarmad Ali
 
RDBMS ER2 Relational
Sarmad Ali
 
RDBMS Arch & Models
Sarmad Ali
 
RDBMS ERD Examples
Sarmad Ali
 
Management Information System-MIS
Sarmad Ali
 
Introduction to RDBMS
Sarmad Ali
 
About Data Base
Sarmad Ali
 
Management information system-MIS
Sarmad Ali
 

Recently uploaded (20)

PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
community health nursing question paper 2.pdf
Prince kumar
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 

Introduction to Compiler Construction

  • 2. Natural Languages • What are Natural Languages? • How do you understand the language? • If you know multiple languages then how can you recognize each of them? • How you know which sentence is correct and which one is incorrect?
  • 3. Programming Languages • What are programming languages? • How do you understand the programming language? • If you know multiple programming languages then how can you recognize each of them? • How do you know which syntax is correct and which one is incorrect?
  • 4. Compilers and Interpreters • “Compilation” – Translation of a program written in a source language into a semantically equivalent program written in a target language – It also reports to its users the presence of errors in the source program – C++ uses compiler Compiler Error messages Source Program Target Program Input Output4
  • 5. Compilers and Interpreters Interpreter Source Program Input Output Error messages • “Interpretation” – Interpreter is a program that reads an executable program and produces the results of running that program. OR – Instead of producing a target program as a translation, an interpreter performs the operations implied by the source program. – GWBASIC is an example of Interpreter 5
  • 6. Why study compilers? • Application of a wide range of theoretical techniques – Data Structures – Theory of Computation – Algorithms – Computer Architecture • Good SW engineering experience • Better understanding of programming languages
  • 7. Features of compilers • Correctness – preserve the meaning of the code • Speed of target code • Recognize legal and illegal program. • Speed of compilation • Good error reporting/handling • Cooperation with the debugger • Manage storage of all variables and codes. • Support for separate compilation
  • 9. Classification of Compilers 1. Single Pass Compilers 2. Two Pass Compilers 3. Multipass Compilers
  • 10. Single Pass Compiler • Source code directly transforms into machine code. – For example Pascal source code target code Front EndCompiler
  • 11. Two Pass Compiler • Use intermediate representation – Why? source code target code Front End Back End IR Front End
  • 12. Two pass compiler • intermediate representation (IR) • front end maps legal code into IR • back end maps IR onto target machine • simplify retargeting • allows multiple front ends • multiple passes ⇒ better code 12
  • 13. © Oscar Nierstrasz Multipass compiler • analyzes and changes IR • goal is to reduce runtime • must preserve values 13
  • 14. Comparison • One pass compilers are generally faster than Multipass Compilers • Multipass ensures the correctness of small program rather than the correctness of a large program (high quality code)
  • 16. Front end • recognize legal code • report errors • produce IR • preliminary storage map • shape code for the back end 16
  • 17. Scanner • Breaks the source code text into small pieces called tokens. • It is also known as Lexical Analyzer
  • 18. Scanner / Lexical Analyser • map characters to tokens • character string value for a token is a lexeme • eliminate white space x = x + y <id,x> = <id,x> + <id,y> 18
  • 19. Syntactic Analysis – Parsing Majid ate the apple
  • 20. Front end –Analysis– Machine Independent • The front end consists of those phases, that depend primarily on the source language and are largely independent of the target machine.
  • 21. Parser • recognize context-free syntax • guide context-sensitive analysis • construct IR(s) • produce meaningful error messages • attempt error correction 21
  • 22. BACK END • Synthesis process • Machine dependent • The back end includes those portions of the compiler that depends on the target machine and generally, these portions do not depend on the source language
  • 23. Back end • translate IR into target machine code • choose instructions for each IR operation • decide what to keep in registers at each point • ensure conformance with system interfaces 23
  • 24. Compiler Structure • Front end – Front end Maps legal code into IR – Recognize legal/illegal programs • report/handle errors – Generate IR – The process can be automated • Back end – Translate IR into target code • instruction selection • register allocation • instruction scheduling
  • 26. The Analysis-Synthesis Model of Compilation • There are two parts to compilation: – Analysis determines the operations implied by the source program which are recorded in a tree structure – Synthesis takes the tree structure and translates the operations therein into the target program 26
  • 27. ANALYSIS PROCEDURE • During analysis, the operation implied by the source program are determined and recorded in a hierarchical structure called a tree. • Often a special type of tree called a Syntax tree in which each node represents an operation and the children of a node represent the arguments of the operation.
  • 28. Lexical Analyzer Syntax Analyzer Semantic Analyzer character stream position = initial + rate * 60 <id,1> <=> <id,2> <+> <id,3> <*> <60> = <id,1> <id,2> <id,3> + * 60 = <id,1> <id,2> <id,3> + * inttofloat 60
  • 29. REMEMBER The front end is responsible for analysis process while the back end is responsible for Synthesis
  • 30. Other Tools that Use the Analysis-Synthesis Model • Editors (syntax highlighting) • Pretty printers (e.g. Doxygen) • Static checkers (e.g. Lint and Splint) • Interpreters • Text formatters (e.g. TeX and LaTeX) • Silicon compilers (e.g. VHDL) • Query interpreters/compilers (Databases) 30
  • 31. Structure Editors • A structure editor takes as input a sequence of commands to build a source program. • The structure editor not only performs the text creation and modification functions of an ordinary text editor but it also analyzes the program text, putting an appropriate hierarchical structure on the source program. • Thus the structure editor can perform additional tasks that are useful in the preparation of programs.
  • 32. Structure Editors (cont..) • For example, it can check that the input is correctly formed, can supply key words automatically (e.g. when the user types while the editor supplies the matching do and reminds the user that a conditional must come between them).
  • 33. Pretty printers • A pretty printer analyzes a program and prints it in such a way that the structure of the program becomes clearly visible. • For example comments may appear in a special font, and the statements may appear with an amount of indentation proportional to the depth of their nesting in the hierarchical organization of the statement.
  • 34. Static Checkers • A static checker reads a program, analyzes it, and attempts to discover potential bugs without running the program. • A static checker may detect that parts of the source program can never be executed, or that a certain variable might be used before being defined. • In addition, it can catch logical errors such as trying to use a real variable as a pointer, employing the type checking techniques.
  • 35. Interpreters• Instead of producing a target program as a translation, an interpreter performs the operations implied by the source program. • For example, for an assignment statement an interpreter might build a tree and then carry out the operations at the nodes as it “walks” the tree. := <id,1> <id,2> <id,3> + * 60 position := initial + rate * 60
  • 36. Interpreters (cont..)• At the root it would discover it had an assignment to perform, so it would call a routine to evaluate the expression on the right, and then store the resulting value in the location associated with the identifier position. • At the right child of the root, the routine would discover it had to compute the sum of two expressions • It would call itself recursively to compute the value of expression rate * 60 • It would then add that value to the value of the variable initial
  • 37. Text Formatters • A text formatter takes input that is a stream of characters, most of which is text to be typeset, but some of which includes commands to indicate paragraphs, figures or mathematical structures like subscripts and superscripts.
  • 38. Silicon compilers • A silicon compiler has a source language that is similar or identical to a conventional programming language. • However, the variables of the language represent, not locations in memory but logical signals (0 or 1) or groups of signals in a switching circuit.
  • 39. Query interpreters • A query interpreter translates a predicate containing relational and Boolean operators into commands to search a database for records satisfying that predicate.

Editor's Notes

  • #14: Code improvement - unclear slide
  • #17: preliminary storage map =&gt; prepare symbol table? shape code for the back end =&gt; same as produce IR?
  • #19: character string value for a token is a lexeme Typical tokens: id, number, do, end … Key issue is speed