lecture 1 1: semester review
DESCRIPTION
Lecture 1 1: Semester Review. COMP 310 0 Dept. Computer Science and Technology United International College. Introduction. Compilation vs. Interpretation Compilation stages. DFA and its equivalents. DFA&NFA Definition Accepted string Regular expression Notation Accepted string - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/1.jpg)
112/04/19 Page 1
Lecture 11: Semester Review
COMP3100Dept. Computer Science and TechnologyUnited International College
![Page 2: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/2.jpg)
112/04/19 2
Introduction
Compilation vs. Interpretation Compilation stages
![Page 3: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/3.jpg)
112/04/19 3
DFA and its equivalents DFA&NFA
Definition Accepted string
Regular expression Notation Accepted string Convert to NFA and DFA
Regular grammar Definition
DFA=NFA=Regular expression=Regular grammar
![Page 4: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/4.jpg)
112/04/19 4
Regular expression->DFA Start with a regular expression. Construct an NFA from it. Use a set of subsets construction to obtain
an equivalent DFA. Construct the minimal equivalent DFA.
![Page 5: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/5.jpg)
112/04/19 5
Convert the following regular expression to a DFA
1(0|1)*101
![Page 6: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/6.jpg)
112/04/19 6
Construct an NFA from it.
![Page 7: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/7.jpg)
112/04/19 7
Obtain an equivalent DFA
![Page 8: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/8.jpg)
112/04/19 8
![Page 9: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/9.jpg)
112/04/19 9
Minimization
![Page 10: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/10.jpg)
112/04/19 10
PDA and its relevant Context free languages
Definition PDA
Definition Difference between PDA and DFA How does it work?
A language is context-free iff a pushdown automata recognizes it
Non-deterministic PDA are more powerful than deterministic ones
![Page 11: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/11.jpg)
112/04/19 11
Parser-Top down parsing Predicts a derivation
Matches non-terminal against token observed in input
How to parse given a parse table? First set, follow set Parse table construction LL(1) grammar Convert non-LL(1) grammar to LL(1)
grammar
![Page 12: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/12.jpg)
112/04/19 12
Exercise
Given the following grammar S->a|^|(T) T->T,S|S
(1) Eliminate the left-recursion in the grammar.(2) Build the LL(1) parsing table
![Page 13: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/13.jpg)
112/04/19 13
Left-recursion Elimination
![Page 14: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/14.jpg)
112/04/19 14
Parsing table construction
![Page 15: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/15.jpg)
112/04/19 15
Parser-Bottom up parsing
Right-most derivation – Backward Start with the tokens End with the start symbol Match substring on RHS of production,
replace by LHS Parsing given parsing table for LR(0) Parsing table construction for LR(0) Right-associative is not LR(0)
![Page 16: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/16.jpg)
112/04/19 16
Parser-Bottom up parsing (2)
SLR Apply reduction only if C is in FOLLOW(X)
LR(1) LR(1) parsing table construction
LALR Constructs LR(1) DFA and then merge any 2
LR(1) states whose items are identical except lookahead
Classification of grammar
![Page 17: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/17.jpg)
112/04/19 17
Given the following grammar S->AS|b A->SA|a
(1) Build the full LR(0) DFA (2) Is it an SLR(1) grammar?
![Page 18: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/18.jpg)
112/04/19 18
![Page 19: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/19.jpg)
112/04/19 19
For state I1, note that Follow(S’)={$}. Hence, the shift-reduce conflict in state I1 can be solved in SLR(1).
For state I6, note that Follow(A)={a,b}. Hence, there is a shift-reduce conflict in state I6 which cannot solved in SLR(1).
For state I7, note that Follow(S)={a,b,$}. Hence, there is a shift-reduce conflict in state I7 which cannot solved in SLR(1).
![Page 20: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/20.jpg)
112/04/19 20
Semantic Analysis
Syntax-directed definition Semantic actions Synthesized attribute Inherited attribute
lexical, syntax, semantic errors Symbol table construction Type derivation
![Page 21: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/21.jpg)
112/04/19 21
Intermediate Code Generation
Translate high-level to low-level sentences
4 Distinct Regions of Memory Execution Stack Activation record/frame
![Page 22: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/22.jpg)
112/04/19 22
Running time organization
Parameter passing modes Value Reference Value/result Name
![Page 23: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/23.jpg)
112/04/19 23
Parameter Passing Modes
int i; int A[3]; void Q(int B) { A[1] = 3; i = 2; write(B); B = 5; } int main() { i = 1; A[1] = 2; A[2] = 4; Q(A[i]); }
![Page 24: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/24.jpg)
112/04/19 24
Mark Distribution
DFA, Regular language and Scanner 24
CFG and Parser 40
Semantic Analysis 19
Intermediate Code Generation 5
Runtime Organization 12
![Page 25: Lecture 1 1: Semester Review](https://reader035.vdocuments.net/reader035/viewer/2022062717/56812a66550346895d8de5fd/html5/thumbnails/25.jpg)
112/04/19 25
Good Luck!