SlideShare a Scribd company logo
Parsing Methods
Parsing
Top down parsing Bottom up parsing (Shift reduce)
Back tracking
Parsing without
backtracking (predictive
Parsing)
LR parsing
Operator precedence
LALR
CLR
SLR
Recursive
descent
LL(1)
LR parser
• LR parsing is most efficient method of bottom up parsing which can be used to
parse large class of context free grammar.
• The technique is called LR(k) parsing:
1. The “L” is for left to right scanning of input symbol,
2. The “R” for constructing right most derivation in reverse,
3. The “k” for the number of input symbols of look ahead that are used in
making parsing decision.
LR parsing
program
INPUT
OUTPUT
a + b $
X
Y
Z
$
Parsing Table
Action Goto
Parsing Methods
Parsing
Top down parsing Bottom up parsing (Shift reduce)
Back tracking
Parsing without
backtracking (predictive
parsing)
LR parsing
Operator precedence
LALR
CLR
SLR
Recursive
descent
LL(1)
Computation of closure & go to function
X Xb
Closure(I):
X X b
Goto(I,X)
X X b
.
.
Steps to construct SLR parser
1. Construct Canonical set of LR(0) items
2. Construct SLR parsing table
3. Parse the input string
Example: SLR(1)- simple LR
S  AA
A  aA | b
S’.S
S. AA
A. aA
A. b
S’ S.
S A . A
A. aA
A. b
A. aA
A. b
A a . A
A b.
A. aA
A. b
A a . A
A b.
A. aA
A. b
A a . A
A b.
S AA .
A aA .
𝑰𝟎
𝑰𝟏
𝑰𝟐
𝑰3 𝑰6
𝑰5
𝑰3
𝑰3
𝑰4
𝑰4
𝑰4
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆)
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴)
𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎)
Augmented
grammar
LR(0) item set
Rules to construct SLR parsing table
1. Construct 𝐶 = { 𝐼0, 𝐼1, … … . 𝐼𝑛}, the collection of sets of LR(0) items for 𝐺’.
2. State 𝑖 is constructed from 𝐼𝑖. The parsing actions for state 𝑖 are determined as
follow :
a) If [ 𝐴 → 𝛼. 𝑎𝛽 ] is in 𝐼𝑖 and GOTO (𝐼𝑖 , 𝑎) = 𝐼𝑗 , then set 𝐴𝐶𝑇𝐼𝑂𝑁[𝑖, 𝑎] to “shift j”.
Here a must be terminal.
b) If [𝐴 → 𝛼. ] is in 𝐼𝑖, then set 𝐴𝐶𝑇𝐼𝑂𝑁[𝑖, 𝑎] to “reduce A 𝛼” for all a in 𝐹𝑂𝐿𝐿𝑂𝑊(𝐴);
here A may not be S’.
c) If [𝑆 → 𝑆. ] is in 𝐼𝑖, then set action [𝑖, $] to “accept”.
3. The goto transitions for state i are constructed for all non terminals A using
the𝑖𝑓 𝐺𝑂𝑇𝑂( 𝐼𝑖 , 𝐴 ) = 𝐼𝑗 𝑡ℎ𝑒𝑛 𝐺𝑂𝑇𝑂 [𝑖, 𝐴] = 𝑗.
4. All entries not defined by rules 2 and 3 are made error.
Example: SLR(1)- simple LR
Action Go to
Item
set
a b $ S A
0 S3 S4 1 2
1 Accept
2 S3 S4 5
3 S3 S4 6
4 R3 R3 R3
5 R1
6 R2 R2 R2
S’. S
S. AA
A. aA
A. b
S’ S.
S A . A
A. aA
A. b
A. aA
A. b
A a . A
A b.
A. aA
A. b
A a . A
A b.
A. aA
A. b
A a . A
A b.
S AA .
A aA .
𝑰𝟎
𝑰𝟏
𝑰𝟐
𝑰3 𝑰6
𝑰5
𝑰3
𝑰3
𝑰4
𝑰4
𝑰4
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆)
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴)
𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎)
S  AA
A  aA | b
𝐹𝑜𝑙𝑙𝑜𝑤(𝑆) = {$}
𝐹𝑜𝑙𝑙𝑜𝑤(𝐴) = {𝑎, 𝑏, $}
Parsing Methods
Parsing
Top down parsing Bottom up parsing (Shift reduce)
Back tracking
Parsing without
backtracking (predictive
Parsing)
LR parsing
Operator precedence
LALR
CLR
SLR
Recursive
descent
LL(1)
How to calculate look ahead?
How to calculate look ahead?
SCC
C cC | d
Closure(I)
S’.S,$
S.CC,
C.cC,
C.d,
S’  . S , $
A  𝜶 . X 𝜷 , 𝒂
Lookahead = First 𝜷𝒂
First $
= $
$
S  . C C , $
A  𝜶 . X 𝜷 , 𝒂
Lookahead = First 𝜷𝒂
First 𝐶$
= 𝒄, 𝒅
c|d
c|d
Example: CLR(1)- canonical LR
S  AA
A  aA | b
S’.S,$
S.AA,$
A.aA, a|b
A.b, a|b
S’ S., $
S A.A,$
A.aA, $
A. b, $
A.aA ,a|b
A. b, a|b
Aa.A, a|b
A b., a|b
A. aA,$
A. b, $
A a.A,$
A b. ,$
A.aA , a|b
A.b , a|b
A a.A , a|b
A b., a|b
S AA. ,$
A aA.,a|b
𝑰𝟎
𝑰𝟏
𝑰𝟐
𝑰3
𝑰8
𝑰5 𝑰6
𝑰3
𝑰7
𝑰4
𝑰4
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆)
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴)
𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎)
Augmented
grammar
A aA.,$
𝑰9
A. aA,$
A. b, $
A a.A,$
A b. ,S
𝑰6
𝑰7
LR(1) item set
Example: CLR(1)- canonical LR
S  AA
A  aA | b
S’.S,$
S.AA,$
A.aA, a|b
A.b, a|b
S’ S., $
S A.A,$
A.aA, $
A. b, $
A.aA ,a|b
A. b, a|b
Aa.A, a|b
A b., a|b
A. aA,$
A. b, $
A a.A,$
A b. ,S
A.aA , a|b
A.b , a|b
A a.A , a|b
A b., a|b
S AA. ,$
A aA.,a|b
𝑰𝟎
𝑰𝟏
𝑰𝟐
𝑰3
𝑰8
𝑰5 𝑰6
𝑰3
𝑰7
𝑰4
𝑰4
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆)
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴)
𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎)
A aA.,$
𝑰9
Item
set
Action Go to
a b $ S A
0 S3 S4 1 2
1 Accept
2 S6 S7 5
3 S3 S4 8
4 R3 R3
5 R1
6 S6 S7 9
7 R3
8 R2 R2
9 R2
A. aA,$
A. b, $
A a.A,$
A b. ,S
𝑰6
𝑰7
Parsing Methods
Parsing
Top down parsing Bottom up parsing (Shift reduce)
Back tracking
Parsing without
backtracking (predictive
Parsing)
LR parsing
Operator precedence
LALR
CLR
SLR
Recursive
descent
LL(1)
A aA.,a|b
Example: LALR(1)- look ahead LR
S  AA
A  aA | b
S’.S,$
S.AA,$
A.aA, a|b
A.b, a|b
S’ S., $
S A.A,$
A.aA, $
A. b, $
A.aA ,a|b
A. b, a|b
Aa.A, a|b
A b., a|b
A. aA,$
A. b, $
A a.A,$
A b. ,$
A.aA , a|b
A.b , a|b
A a.A , a|b
A b., a|b
S AA. ,$
𝑰𝟎
𝑰𝟏
𝑰𝟐
𝑰3
𝑰8
𝑰5 𝑰6
𝑰3
𝑰7
𝑰4
𝑰4
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆)
𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏)
𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴)
𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎)
A aA.,$
𝑰9
A. aA,$
A. b, $
A a.A,$
A b. ,$
𝑰6
𝑰7
CLR
𝑰36
A.aA , a|b|$
A. b, a|b|$
Aa.A, a|b|$
A b., a|b|$
𝑰47
A aA.,a|b|$
𝑰89
Example: LALR(1)- look ahead LR
Item
set
Action Go to
a b $ S A
0 S3 S4 1 2
1 Accept
2 S6 S7 5
3 S3 S4 8
4 R3 R3
5 R1
6 S6 S7 9
7 R3
8 R2 R2
9 R2
Item
set
Action Go to
a b $ S A
0 S36 S47 1 2
1 Accept
2 S36 S47 5
36 S36 S47 89
47 R3 R3 R3
5 R1
89 R2 R2 R2
CLR Parsing Table LALR Parsing Table

More Related Content

What's hot

Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman
 
Parsing
ParsingParsing
Parsing
khush_boo31
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
Akshaya Arunan
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
Arab Open University and Cairo University
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
Top down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptxTop down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptx
LaibaFaisal3
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
8neutron8
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
Ratnakar Mikkili
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
KHYATI PATEL
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
Jothi Lakshmi
 
Parsing
ParsingParsing
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
Nitin Mohan Sharma
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
LakshmiSamivel
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 
Slr parser
Slr parserSlr parser
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
Md Tajul Islam
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 

What's hot (20)

Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Parsing
ParsingParsing
Parsing
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Top down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptxTop down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptx
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
 
Parsing
ParsingParsing
Parsing
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Slr parser
Slr parserSlr parser
Slr parser
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
 

Similar to 10-SLR parser practice problems-02-06-2023.pptx

Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
PremBorse1
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
bolovv
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
kartikaVashisht
 
UNIT 2 (1).pptx
UNIT 2 (1).pptxUNIT 2 (1).pptx
UNIT 2 (1).pptx
Abhishek Tirkey
 
BOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptxBOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptx
SnehaTiwari84
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
Ravi Rao
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
compiler design.pdf
compiler design.pdfcompiler design.pdf
compiler design.pdf
RijuMandal11
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
ayyankhanna6480086
 
lalr. fo engineering student those who to
lalr. fo engineering student those who tolalr. fo engineering student those who to
lalr. fo engineering student those who to
HjJordTzong
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
Linear logic (and Linear Lisp)
Linear logic (and Linear Lisp)Linear logic (and Linear Lisp)
Linear logic (and Linear Lisp)
Sosuke MORIGUCHI
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
BapanKar2
 
Ch4b
Ch4bCh4b
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
Austin Benson
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
Mahesh Kumar Chelimilla
 
Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4
Iffat Anjum
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
Najmul Hassan
 

Similar to 10-SLR parser practice problems-02-06-2023.pptx (20)

Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
UNIT 2 (1).pptx
UNIT 2 (1).pptxUNIT 2 (1).pptx
UNIT 2 (1).pptx
 
BOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptxBOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptx
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
compiler design.pdf
compiler design.pdfcompiler design.pdf
compiler design.pdf
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
 
lalr. fo engineering student those who to
lalr. fo engineering student those who tolalr. fo engineering student those who to
lalr. fo engineering student those who to
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
Linear logic (and Linear Lisp)
Linear logic (and Linear Lisp)Linear logic (and Linear Lisp)
Linear logic (and Linear Lisp)
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
 
Ch4b
Ch4bCh4b
Ch4b
 
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
LR(0) PARSER
 
Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
 
Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
 

More from venkatapranaykumarGa

9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT
venkatapranaykumarGa
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
venkatapranaykumarGa
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
venkatapranaykumarGa
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
venkatapranaykumarGa
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
venkatapranaykumarGa
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
venkatapranaykumarGa
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
venkatapranaykumarGa
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
venkatapranaykumarGa
 
7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx
venkatapranaykumarGa
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 

More from venkatapranaykumarGa (13)

9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
 
7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 

Recently uploaded

220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
Kalna College
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
Celine George
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
andagarcia212
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGHKHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
shreyassri1208
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
Kalna College
 

Recently uploaded (20)

220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGHKHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
 

10-SLR parser practice problems-02-06-2023.pptx

  • 1. Parsing Methods Parsing Top down parsing Bottom up parsing (Shift reduce) Back tracking Parsing without backtracking (predictive Parsing) LR parsing Operator precedence LALR CLR SLR Recursive descent LL(1)
  • 2. LR parser • LR parsing is most efficient method of bottom up parsing which can be used to parse large class of context free grammar. • The technique is called LR(k) parsing: 1. The “L” is for left to right scanning of input symbol, 2. The “R” for constructing right most derivation in reverse, 3. The “k” for the number of input symbols of look ahead that are used in making parsing decision. LR parsing program INPUT OUTPUT a + b $ X Y Z $ Parsing Table Action Goto
  • 3. Parsing Methods Parsing Top down parsing Bottom up parsing (Shift reduce) Back tracking Parsing without backtracking (predictive parsing) LR parsing Operator precedence LALR CLR SLR Recursive descent LL(1)
  • 4. Computation of closure & go to function X Xb Closure(I): X X b Goto(I,X) X X b . .
  • 5. Steps to construct SLR parser 1. Construct Canonical set of LR(0) items 2. Construct SLR parsing table 3. Parse the input string
  • 6. Example: SLR(1)- simple LR S  AA A  aA | b S’.S S. AA A. aA A. b S’ S. S A . A A. aA A. b A. aA A. b A a . A A b. A. aA A. b A a . A A b. A. aA A. b A a . A A b. S AA . A aA . 𝑰𝟎 𝑰𝟏 𝑰𝟐 𝑰3 𝑰6 𝑰5 𝑰3 𝑰3 𝑰4 𝑰4 𝑰4 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆) 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴) 𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎) Augmented grammar LR(0) item set
  • 7. Rules to construct SLR parsing table 1. Construct 𝐶 = { 𝐼0, 𝐼1, … … . 𝐼𝑛}, the collection of sets of LR(0) items for 𝐺’. 2. State 𝑖 is constructed from 𝐼𝑖. The parsing actions for state 𝑖 are determined as follow : a) If [ 𝐴 → 𝛼. 𝑎𝛽 ] is in 𝐼𝑖 and GOTO (𝐼𝑖 , 𝑎) = 𝐼𝑗 , then set 𝐴𝐶𝑇𝐼𝑂𝑁[𝑖, 𝑎] to “shift j”. Here a must be terminal. b) If [𝐴 → 𝛼. ] is in 𝐼𝑖, then set 𝐴𝐶𝑇𝐼𝑂𝑁[𝑖, 𝑎] to “reduce A 𝛼” for all a in 𝐹𝑂𝐿𝐿𝑂𝑊(𝐴); here A may not be S’. c) If [𝑆 → 𝑆. ] is in 𝐼𝑖, then set action [𝑖, $] to “accept”. 3. The goto transitions for state i are constructed for all non terminals A using the𝑖𝑓 𝐺𝑂𝑇𝑂( 𝐼𝑖 , 𝐴 ) = 𝐼𝑗 𝑡ℎ𝑒𝑛 𝐺𝑂𝑇𝑂 [𝑖, 𝐴] = 𝑗. 4. All entries not defined by rules 2 and 3 are made error.
  • 8. Example: SLR(1)- simple LR Action Go to Item set a b $ S A 0 S3 S4 1 2 1 Accept 2 S3 S4 5 3 S3 S4 6 4 R3 R3 R3 5 R1 6 R2 R2 R2 S’. S S. AA A. aA A. b S’ S. S A . A A. aA A. b A. aA A. b A a . A A b. A. aA A. b A a . A A b. A. aA A. b A a . A A b. S AA . A aA . 𝑰𝟎 𝑰𝟏 𝑰𝟐 𝑰3 𝑰6 𝑰5 𝑰3 𝑰3 𝑰4 𝑰4 𝑰4 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆) 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴) 𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎) S  AA A  aA | b 𝐹𝑜𝑙𝑙𝑜𝑤(𝑆) = {$} 𝐹𝑜𝑙𝑙𝑜𝑤(𝐴) = {𝑎, 𝑏, $}
  • 9. Parsing Methods Parsing Top down parsing Bottom up parsing (Shift reduce) Back tracking Parsing without backtracking (predictive Parsing) LR parsing Operator precedence LALR CLR SLR Recursive descent LL(1)
  • 10. How to calculate look ahead? How to calculate look ahead? SCC C cC | d Closure(I) S’.S,$ S.CC, C.cC, C.d, S’  . S , $ A  𝜶 . X 𝜷 , 𝒂 Lookahead = First 𝜷𝒂 First $ = $ $ S  . C C , $ A  𝜶 . X 𝜷 , 𝒂 Lookahead = First 𝜷𝒂 First 𝐶$ = 𝒄, 𝒅 c|d c|d
  • 11. Example: CLR(1)- canonical LR S  AA A  aA | b S’.S,$ S.AA,$ A.aA, a|b A.b, a|b S’ S., $ S A.A,$ A.aA, $ A. b, $ A.aA ,a|b A. b, a|b Aa.A, a|b A b., a|b A. aA,$ A. b, $ A a.A,$ A b. ,$ A.aA , a|b A.b , a|b A a.A , a|b A b., a|b S AA. ,$ A aA.,a|b 𝑰𝟎 𝑰𝟏 𝑰𝟐 𝑰3 𝑰8 𝑰5 𝑰6 𝑰3 𝑰7 𝑰4 𝑰4 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆) 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴) 𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎) Augmented grammar A aA.,$ 𝑰9 A. aA,$ A. b, $ A a.A,$ A b. ,S 𝑰6 𝑰7 LR(1) item set
  • 12. Example: CLR(1)- canonical LR S  AA A  aA | b S’.S,$ S.AA,$ A.aA, a|b A.b, a|b S’ S., $ S A.A,$ A.aA, $ A. b, $ A.aA ,a|b A. b, a|b Aa.A, a|b A b., a|b A. aA,$ A. b, $ A a.A,$ A b. ,S A.aA , a|b A.b , a|b A a.A , a|b A b., a|b S AA. ,$ A aA.,a|b 𝑰𝟎 𝑰𝟏 𝑰𝟐 𝑰3 𝑰8 𝑰5 𝑰6 𝑰3 𝑰7 𝑰4 𝑰4 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆) 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴) 𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎) A aA.,$ 𝑰9 Item set Action Go to a b $ S A 0 S3 S4 1 2 1 Accept 2 S6 S7 5 3 S3 S4 8 4 R3 R3 5 R1 6 S6 S7 9 7 R3 8 R2 R2 9 R2 A. aA,$ A. b, $ A a.A,$ A b. ,S 𝑰6 𝑰7
  • 13. Parsing Methods Parsing Top down parsing Bottom up parsing (Shift reduce) Back tracking Parsing without backtracking (predictive Parsing) LR parsing Operator precedence LALR CLR SLR Recursive descent LL(1)
  • 14. A aA.,a|b Example: LALR(1)- look ahead LR S  AA A  aA | b S’.S,$ S.AA,$ A.aA, a|b A.b, a|b S’ S., $ S A.A,$ A.aA, $ A. b, $ A.aA ,a|b A. b, a|b Aa.A, a|b A b., a|b A. aA,$ A. b, $ A a.A,$ A b. ,$ A.aA , a|b A.b , a|b A a.A , a|b A b., a|b S AA. ,$ 𝑰𝟎 𝑰𝟏 𝑰𝟐 𝑰3 𝑰8 𝑰5 𝑰6 𝑰3 𝑰7 𝑰4 𝑰4 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑆) 𝐺𝑜 𝑡𝑜 (𝐼0, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝑏) 𝐺𝑜 𝑡𝑜 (𝐼2, 𝐴) 𝐺𝑜 𝑡𝑜 (𝐼3, 𝑎) A aA.,$ 𝑰9 A. aA,$ A. b, $ A a.A,$ A b. ,$ 𝑰6 𝑰7 CLR 𝑰36 A.aA , a|b|$ A. b, a|b|$ Aa.A, a|b|$ A b., a|b|$ 𝑰47 A aA.,a|b|$ 𝑰89
  • 15. Example: LALR(1)- look ahead LR Item set Action Go to a b $ S A 0 S3 S4 1 2 1 Accept 2 S6 S7 5 3 S3 S4 8 4 R3 R3 5 R1 6 S6 S7 9 7 R3 8 R2 R2 9 R2 Item set Action Go to a b $ S A 0 S36 S47 1 2 1 Accept 2 S36 S47 5 36 S36 S47 89 47 R3 R3 R3 5 R1 89 R2 R2 R2 CLR Parsing Table LALR Parsing Table