0% found this document useful (0 votes)
3 views

Unit 1.1

The document outlines the syllabus for the course CSE 304: Automata and Compiler Design, covering topics such as formal languages, finite automata, context-free grammars, parsing techniques, semantic analysis, and code optimization. It includes details on course structure, assessment methods, textbooks, and web resources. Additionally, it discusses the importance of understanding compilers and translators in computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 1.1

The document outlines the syllabus for the course CSE 304: Automata and Compiler Design, covering topics such as formal languages, finite automata, context-free grammars, parsing techniques, semantic analysis, and code optimization. It includes details on course structure, assessment methods, textbooks, and web resources. Additionally, it discusses the importance of understanding compilers and translators in computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Automata and Compiler Design (CSE 304)

Unit I: Part 1

Dr. Murali Krishna Enduri


Department of CSE
1
Syllabus
SUBJECT CODE SUBJECT TITLE CORE/ ELECTIVE CREDITS
L T P C
CSE 304 Automata and Compiler Design C 3 0 0 3

UNIT I: Introduction to Automata and Compilers


Introduction to Formal Languages, Chomsky Hierarchy, Structure of Compiler, Finite
Automata – DFA, Design of NFA, Conversion of NFA to DFA, Regular expression, Conversion
of regular expression to NFA, Minimization of DFA, Applications of Finite Automata to
lexical analysis.

UNIT II: Context-free Grammars


Context-free grammars, Design of Context-free grammars, Applications of CFG to parsing,
Left Recursion, Left Factorization, Recursive Descent parsing, Computation of FIRST,
Computation of FIRST, LL(1) parsing.
Syllabus
UNIT III: Bottom-up Parsing
Bottom-up parsing: Handle pruning, Shift reduce parsing, LR parsing algorithm, Construction of
LR(0) items, SLR table construction, Construction of LR(1) items, CLR, LALR, Introduction to YACC.

UNIT IV : Semantic Analysis


Semantic Analysis: Syntax directed translation, S-attributed and L-attributed grammars,
S-attributed and L-attributed grammars, S-attributed and L-attributed grammars, overloading of
functions and operations., Intermediate code generation, Intermediate code generation, Three
address code for control flow statements, Run time storage management.

UNIT V : Code Optimization and Code Generation


Code Optimization, Principal sources of optimization , optimization of basic blocks., Construction of
flow graphs, Common sub expression elimination, Copy propagation, dead code elimination,
constant folding, operator strength reduction, Data flow analysis of flow graphs, Code generation,
A simple code generation algorithm, A simple code generation algorithm.
Syllabus
TEXTBOOKS
1. John E Hopcroft, Rajeev Motwani, Jeffrey D.Ullman, “Introduction to Automata Theory
Languages and Computation”, 3rd Edition, Pearson Education, 2011.
2. Alfred Aho, Monica S Lam, Ravi Sethi, Jeffrey D. Ullman, “CompilersPrinciples Techniques
and Tool”, 2ndEdition, Pearson Education India, 2013.

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

o Automata and Compiler Basics


o Finite Automata
oLexical Analysis
oContext Free Grammar
oSemantic Analysis
o Code Generation
o Code Optimization
Distribution of Marks

Internal Test Component Conducting Marks Converting Marks Final Conversion


Mid-term 25 20 50
Theory CSE
CLA 1 20 10
CLA 2 20 10
CLA3 10 10
Total 50

External Assessment tool Conducting Marks Final Conversion


End semester theory exam Final exam 50 50
CSE
Total 50
Continuous Assessment

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?

1. Complexity Theory : Can all algorithms be made more efficient?


2. Computability Theory : Can all problems be solved using a
computer?
3. Automata Theory: Given a computational problem, what is the
simplest computer or model that can solve it?

What makes some problems computationally hard and others easy?

9
1. Sets and Set operations

2. Functions

3. Graph notations

4. Theorems and Proofs

5. Strings and Languages

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

4. Theorems and Proofs

5. Strings and Languages

20
21
What is complier?

ⓘ Start presenting to display the poll results on this slide.


23
What is translator?

ⓘ Start presenting to display the poll results on this slide.


24
Translators
What do you understand by the terms translator?

A translator or language processor is a program that translates an input program written in a


programming language into an equivalent program in another language.

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?

ⓘ Start presenting to display the poll results on this slide.


26
Translators

What do you understand by the terms translator?

Different types of Translators are:

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

Compiler is a type of translator, which takes a program written in a high-level programming


language as input and translates into an equivalent program in low-level language such as
machine language or assembly language.

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

Source Program Target Program


29
Why Study Compiler?

Its essential to understand the heart of programming by computer


engineering students.

There may be need of designing a compiler for any software language


in the profession.

Increases understanding of language semantics.

Helps to handle language performance issues.

Opportunity for non-trivial programming project


30
History

• Software for early computers were written in assembly language.


• The need of reusability of code gave birth to programming
languages.
• This need grow huge to overcome the cost restriction of compiler.

1. The concept of machine independent programming gave birth


to the need of compilers in 1950s.
2. The 1st compiler was written by Grace Hopper in 1952 for A-0
programming language.
31
History

1. The 1st complete compiler was developed by FORTRAN team lead by


John Backus @ IBM in 1957.
2. COBOL was the 1st language to be compiled on multiple platforms in
1960.
3. Earlier compilers were written in assembly languages.
4. The 1st compiler in HLL was created for LISP by Tim Hart & Mike
Levin @ MIT, USA in 1962, which was a selfhosting Compiler.
5. Most compilers are made in C or Pascal languages.
6. However the trend is changing to self-hosting compilers, which can
compile the source code of the same language in which they are
created.
32
Translator and Interpreter
A translator or language processor is a program that translates an input program written in a
programming language into an equivalent program in another language.

An interpreter is another common kind of Translator.


Interpreter: This software converts the high-level language into low-level language line
by line and executed.

33
Interpreter

1. It takes less memory than compiler.


2. It takes more time than compiler.
3. An interpreter, however, can usually give better error diagnostics
than a compiler, because it executes the source program statement
by statement.
4. It takes more time to build.
5. The machine-language target program produced by a compiler is
usually much faster than an interpreter at mapping inputs to
outputs.

34
Difference between compiler and interpreter

35
Translators

What do you understand by the terms translator?

Different types of Translators are:

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

• Semantic Analysis Front End

• Intermediate Code Generation machine independent.

• Code Optimization Synthesis Part

• Code Generation Back End


machine dependent

41
Structure of Compiler

• Lexical Analysis
• Syntax Analysis Analysis Part

• Semantic Analysis Front End

• Intermediate Code Generation machine independent.

• 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

• Semantic Analysis Front End

• Intermediate Code Generation machine independent.

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

3. Automatic door controller

4. Binary string with divisible by 4

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

– Similar proof to those for union and intersection.


– Alternatively, since L1– L2 is the same as L1 ∩(L2)c, we can just
apply Theorems intersection closure and complement closure

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

You might also like