Professional Documents
Culture Documents
Organization
Basics of Compilers
Stages in a Compiler
Compiler Implementation
Basics of Compilers
What is a Compiler ?
Translates Code Written in Higher
Level Languages into Target
Language
Assembly
language Program
Stages in a Compiler
Stages in a Compiler
Two stages ex1.c
Preprocessed file to
Intermediate Code Back End
Intermediate Code
Back End
Intermediate Code
Target Code
generation Target Code generation
Optimization
Target Code Optimization
Generate Tokens
Ignores spaces, new line etc.
Generate error messages line by line
Helps in Macro Expansion
Lexical Analysis / Scanning
Small meaningful sequence of
characters called Tokens
C Programming language Tokens
Identifiers (user defined variables)
Keywords (while, for),
punctuation marks (Left brace/Right brace)
Operators (+ and -).
Syntax Analysis / Parsing
Do Tokens form a valid sequence ?
= b c+d is not a valid sequence
Syntax or Parse Tree can be an Output
Tree like
intermediate
Tokens Parser representatio
n (Syntax
Tree)
Semantic Analysis
Performs Type Checking
Do syntactically correct statements
make a meaningful reading ?
'x = y + 2 ; ' not meaningful if x is function
name or array and y is a float
Checks whether
Syntax Tree + Semantic prog. is
info. from Analysis meaningful or
symbol table not?
Intermediate Code Generation
Generates Intermediate Code
phases into
Pass 1
Semantic Analysis
Intermediate Code
Intermediate Code
Pass 3
Target Code generation
Back End
Target Assembly Language
(Synthesis)
Parser Generator:
These tools produce Syntax analyzers from input:
based on Grammar.
Generate parse tree
Compiler Interpreter
Pros Pros
Less space Easy debugging
Fast execution Fast Development
Cons Cons
Slow processing Not for large projects
Partly Solved Exceptions: Perl,
(Separate compilation) Python
Debugging Requires more space
Improved thru IDEs Slower execution
Interpreter in memory
all the time
Application of Compiler technology
Implementation of high level programming
languages
- Concepts of OOPs
Optimization for Computer Architecture
- Parallelism
- Memory hierarchies of machines(Reg, Arrays etc)
Design of new computer Architectures
- RISC
- CISC
- SIMD etc
Program translations
Software productivity tools
Translation of a statement
Translation of a statement
Intermediate Code Generation
Generates Intermediate Code
Parser Generator:
These tools produce Syntax analyzers from input:
based on Grammar.
Generate parse tree