Unit 1.1
Unit 1.1
Unit I: Part 1
REFERENCES
1. Peter Linz, “An introduction to Formal Languages and Automata”, 6th Edition, Jones &
Bartlett, 2016
2. V. Raghavan, “Principles of Compiler Design”, 1st Edition, McGraw Hill Education, 2017.
WEB RESOURCES
1.https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-004-computation-structures-spring-2017/c11/
2.https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-035-computer-language-engineering-spring-2010/
3.https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/
The Course covers
Other than this one MIDTERM and End semester exam will be there.
7
Playing it safe in CSE-304
If you follow these 4 simple rules during the class, you'll make
sure that you do well in the course:
1. Attend every Theory classes and learn new things from every
class.
2. Read the course material (textbook sections assigned +
slides).
3. Submit everything (Assignments, Quizzes, Exams) on time -
don't be late.
4. Don't cheat.
What are Fundamental Capabilities and Limitations of computers?
9
1. Sets and Set operations
2. Functions
3. Graph notations
10
1. Sets and Set operations
1. Set
2. Empty set
3. Singleton set
4. Multi set
5. Sets operations: Union, Intersection, Minus, Complement
6. Ordered Pair (Cross Product)
7. Power set
11
1. Functions
1. Domain
2. Range
12
1. Graph notations
1. Nodes
1. Edges
2. Directed Graph
3. Undirected Graph
4. Degree
1. Subgraph
1. Connected Graph
2. Disconnected graph
3. Path
4. Cycle
5. Tree
13
1. Theorems and Proofs
1. Theorem
2. Lemma
3. Corollaries
4. Proofs: 3 types
14
15
16
17
18
1. Strings and Languages
1. Alphabet
2. String
3. Length of string
4. Substring
5. String Reverse
6. String Concatenation
19
1. Sets and Set operations
2. Functions
3. Graph notations
20
21
What is complier?
The source language can be low level language like assembly language or a high level
language like C, C++, JAVA, FORTRAN, and so on.
The target language can be a low level language (assembly language) or a machine
language (set of instructions executed directly by a CPU).
Which of the following are transulators?
o Compiler
o Interpreter
o Assembler
o Cross-Compiler
o Language Translator / Source to source translator / Language Converter
o Language Rewriter
o Decompiler
o Compiler-Compiler
o Linker
o Loader
What is a Compiler
The program written in high-level language is known as source program, and the program
converted into low-level language is known as object (or target) program.
What is a Compiler
33
Interpreter
34
Difference between compiler and interpreter
35
Translators
o Compiler
o Interpreter
o Assembler
o Cross-Compiler
o Language Translator / Source to source translator / Language Converter
o Language Rewriter
o De-compiler
o Compiler-Compiler
o Linker
o Loader
Structure of Compiler
Compilers bridge the gap between high level language & machine
hardware.
• Compiler requires:
1. Finding errors in syntax of program.
2. Generating correct & efficient object code.
3. Run-time organization.
4. Formatting o/p according to linker/ assembler
37
Structure of Compiler
38
Structure of Compiler
39
40
Structure of Compiler
• Lexical Analysis
• Syntax Analysis Analysis Part
41
Structure of Compiler
• Lexical Analysis
• Syntax Analysis Analysis Part
• Determines operations implied by the source program which are recorded in a tree structure
called the Syntax Tree.
• Breaks up the source code into basic pieces, while storing info. in the symbol table.
Synthesis Part
• Code Optimization Back End
• Code Generation machine dependent
42
Structure of Compiler
• Lexical Analysis
• Syntax Analysis Analysis Part
Synthesis Part
• Code Optimization Back End
• Code Generation machine dependent
• Constructs the target code from the syntax tree, and from the information in the symbol
table.
• Here, code optimization offers efficiency of code generation with least use of
resources.
43
Finite Automata?
1. Electric Switch
2. Fan Regulator
44
Formal Definition of a Finite Automaton
45
Construct Finite Automaton
46
47
Draw Deterministic finite automata (DFA) of a string with at
least two a’s and at least two b’s
Draw Deterministic finite automata (DFA) of a string with exactly one a and at
least one b
This DFA should accept the strings such as ab, ba, abb, bab, bba, abbb, babb, bbab, bbba, abbbb…. etc but it should not
accept string such as a, b, bb, bbb, aabb, ababa… etc.
48
Regular Language:
49
50
Language operations
51
Concatenation
52
The Star Operation
53
The Star Operation
54
Closure under operations
The set of regular (FA-recognizable) languages is closed under all six
operations (union, intersection, complement, set difference,
concatenation, star).
Complement of Regular Language:
Theorem 1:The class of regular languages are closed under complement.
In other words, if L is a regular language then LC is also a regular language.
Proof: Interchange
accepting and
non-accepting
states.
55
Intersection of two Regular Languages:
Theorem 2: The class of regular languages are closed under intersection.
In other words, If L1 and L2 are regular languages then L1ՈL2 is also a regular language
56
Union of two Regular Languages:
57
Set Difference of two Regular Languages:
Theorem 2: The class of regular languages are closed under set difference.
In other words, If L1 and L2 are regular languages then L1– L2 is also a regular language
58
Concatenation of two Regular Languages:
Theorem 3: The class of regular languages are closed under concatenation.
In other words, If L1 and L2 are regular languages then L1o L2 is also a regular language
How to combine?
–We seem to need to “guess”when to shift to M2.
–Leads to our next model, NFAs, which are FAs that can guess.
59