2. Course Outline
Introduction
Lexical Analysis definition - using Regular Expressions – (REs)
Lexical Analysis using Deterministic Finite Automata – (DFA)
Lexical Analysis using Non-Deterministic Finite Automata – (NFA)
and Transfer NFA to DFA.
Syntax Analysis using CFG.
Syntax Analysis, Parsing trees and Ambiguity.
CD-Course-FSH 1st Term 2017-2018
2
3. Course Outline (continue)
Removing Left Recursion and Left Factoring.
Syntax Analysis (CFG) using Top-down parsing.
First and Follow operators.
Syntax analysis (CFG) using Bottom-Up (predictive/LR) parsing.
Construction of “LR Parsing Tables” / “parsing Table LL1”.
Semantic analysis
Intermediate code and code generation.
3
CD-Course-FSH 1st Term 2017-2018
4. Why?
Why Study Compilers?
Enhance understanding of programming languages.
Have an in-depths knowledge of low-level machine
executables.
Write compilers and interpreters for various
programming languages and domain-specific
languages.
Learn various system-building tools.
Learn interesting compiler theory and algorithms.
4
CD-Course-FSH 1st Term 2017-2018
5. Why?
Why Study Compilers?
5
Developer
Researcher
• Select which programming language is the best for the
problem/system on hand.
• Know how the code you are writing is compiled, and how the
compiler can intelligently optimize your code.
• Can easily gain the basic knowledge about compilers that allows
you to surf into the open research problems
• Learn how to optimize the compiler time and resources, especially
for portable devices.
CD-Course-FSH 1st Term 2017-2018
6. Compiler and Interpreter
Compiler
Is a special program that transforms
statements written in a particular
programming language(the source language)
into another computer language (the target
language).
6
CD-Course-FSH 1st Term 2017-2018
10. A Language-Processing System
10
Preprocessor
A preprocessor, generally considered
as a part of compiler, is a tool that
produces input for compilers. It deals
with macro-processing, augmentation,
file inclusion, language extension, etc.
Ex: include library in C
CD-Course-FSH 1st Term 2017-2018
11. A Language-Processing System
11
Compiler
A compiler is a special program that
processes statements written in a
particular programming language and
turns them into machine language or
"code" that a computer's processor
uses.
CD-Course-FSH 1st Term 2017-2018
13. A Language-Processing System
13
Linker
A linker tool is used to link all the parts
of the program together for execution
(executable machine code).
CD-Course-FSH 1st Term 2017-2018
14. Phases of Compiler
14
Lexical Analyzer (Scanner)
reads a stream of characters and puts them
together into some meaningful (with respect to
the source language) units called tokens.
Lexical Analyzer
(Scanner)Character
Stream
Token
Stream
CD-Course-FSH 1st Term 2017-2018
15. Phases of Compiler
15
Syntax Analyzer (Parsing)
• Takes a stream of tokens from the scanner,
and
• Determines if the syntax (structure) of the
program is correct according to the
(context-free) grammar of the source
language.
Syntax Analyzer
Token Syntax Tree
CD-Course-FSH 1st Term 2017-2018
16. Phases of Compiler
16
Syntax Analyzer (Parsing) continue
• It generates a data structure, called a
parse tree or an abstract syntax tree,
which describes the syntactic structure of
the program.
CD-Course-FSH 1st Term 2017-2018
17. Phases of Compiler
17
Example:
position := initial + rate * 60
would be grouped into the following tokens;
1. The identifier position
2. The assignment symbol :=
3. The identifier initial
4. The plus sign
5. The identifier rate.
6. The multiplication sign.
7. The number 60
LexicalAnalyzer
Syntax Analyzer
CD-Course-FSH 1st Term 2017-2018