SlideShare a Scribd company logo
2
Most read
3
Most read
20
Most read
SLR PARSER
Steps:
1. create augment grammar
2. generate kernel items
3. find closure
4. compute goto()
5. construct parsing table
6. parse the string
Let us consider grammar:
S->a
S->(L)
L->S
L->L,S
• Step :1 Create augment grammar
S is start symbol in the given grammar
Augment grammar is S’-> S
• Step :2 Generate kernel items
Introduce dot in RHS of the production``
S’-> .S
• Step :3 Find closure
(Rule: A -> α.Xβ i.e if there is nonterminal next to dot then Include X production))
S’-> .S
S-> . a
S->.(L)
I0
Step :4 compute goto()
S’-> S .
I1
Goto (I0,a) S-> a .
I2
Goto (I0,( )
S’-> .S
S-> . a
S->.(L) I0
S-> (.L)
L->.S
L>.L,S
S->.a
S->.(L)
I3
Goto (I3,L )
S-> (L .)
L->L . ,S
I4
Goto (I3,S ) L->S . I5
Goto (I3,a ) S->a . I2
Goto (I3, ( )
S-> (. L )
L->.S
L>.L,S
S->.a
S->.(L)
I3
Goto (I0,S)
Goto (I4, ) ) S-> (L) . I6
Goto (I4, , ) L->L , . S
S-> . a
S->.(L)
I7
Goto (I7,S ) L->L , S . I8
Goto (I7,a ) S-> a . I2
Goto (I7,( )
S-> (.L)
L->.S
L>.L,S
S->.a
S->.(L)
I3
label Production Ending
iteration
R0 S’-> S . I1
R1 S->a . I2
R2 S->(L) . I6
R3 L->S . I5
R4 L->L,S . I8
Step :5 construct parsing table
Label the rows of table with no. of iterations
Divide the Column into two parts
• Action part: terminal symbols
• Goto part: Nonterminal symbols
Terminals Non terminals
a ( ) , $ S L
0
1
2
3
4
5
6
7
8
Step :5 construct parsing table from step 4:
Label the rows of table with no. of iterations
Divide the Column into two parts
• Action part: terminal symbols
• Goto part: Nonterminal symbols
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1
2
3 S2 S3 5 4
4 S6 S7
5
6
7 S2 S3 8
8
Goto (I0, S) 1 Goto (I3, ( ) 3
Goto (I0, a) 2 Goto (I4, ) ) 6
Goto (I0, ( ) 3
Goto (I4, ,)
7
Goto (I3, L) 4 Goto (I7, S) 8
Goto (I3, S) 5 Goto (I7, a) 2
Goto (I3, a) 2 Goto (I7, ( ) 3
Step :5 construct parsing table
Label the rows of table with no. of iterations
Divide the Column into two parts
• Action part: terminal symbols
• Goto part: Nonterminal symbols
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
label Production
Ending
iteration
Follow(LHS)
R0 S’-> S . I1 Follow(S’)={ $ }
R1 S-> a . I2
Follow(S)={ $ ) , }
R2 S-> ( L ) . I6
Follow(S)={ $ ) , }
R3 L-> S . I5
Follow(L)={ ) , }
R4 L-> L , S . I8
Follow(L)={ ) , }
Step :5 construct parsing table
Label the rows of table with no. of iterations
Divide the Column into two parts
• Action part: terminal symbols
• Goto part: Nonterminal symbols
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
label Production
Ending
iteration
Follow(LHS)
R0 S’-> S . I1 Follow(S’)={ $ }
R1 S-> a . I2
Follow(S)={ $ ) , }
R2 S-> ( L ) . I6
Follow(S)={ $ ) , }
R3 L-> S . I5
Follow(L)={ ) , }
R4 L-> L , S . I8
Follow(L)={ ) , }
Goto (I0, S) 1 Goto (I3, ( ) 3
Goto (I0, a) 2 Goto (I4, ) ) 6
Goto (I0, ( ) 3
Goto (I4, ,)
7
Goto (I3, L) 4 Goto (I7, S) 8
Goto (I3, S) 5 Goto (I7, a) 2
Goto (I3, a) 2 Goto (I7, ( ) 3
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
$0(3L4 , 7a2 )$ R1
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
$0(3L4 , 7a2 )$ R1
$0(3L4 , 7S8 )$ R4
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
$0(3L4 , 7a2 )$ R1
$0(3L4 , 7S8 )$ R4
$0(3L4 ) $ S6
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
$0(3L4 , 7a2 )$ R1
$0(3L4 , 7S8 )$ R4
$0(3L4 ) $ S6
$0(3L4)6 $ R2
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .
Step :6 String parsing
Let string w=(a,a) derived from the given grammar
S – Shift action
* shift input symbol to the stack
* shift number to the stack
R – Reduce action
* pop 2 times of RHS symbols
* shift LHS to the stack
* find the number in the parsing table for
the last two elements in the stack
ACTION GOTO
a ( ) , $ S L
0 S2 S3 1
1 accept
2 R1 R1 R1
3 S2 S3 5 4
4 S6 S7
5 R3 R3
6 R2 R2 R2
7 S2 S3 8
8 R4 R4
Stack Input Action
$0 (a,a)$ S3
$0(3 a,a)$ S2
$0(3a2 ,a)$ R1
$0(3S5 ,a)$ R3
$0(3L4 ,a)$ S7
$0(3L4 , 7 a)$ S2
$0(3L4 , 7a2 )$ R1
$0(3L4 , 7S8 )$ R4
$0(3L4 ) $ S6
$0(3L4)6 $ R2
$0S1 $ accept
Hence the string parsed successfully !!!!!!
label Production
R0 S’-> S .
R1 S-> a .
R2 S-> ( L ) .
R3 L-> S .
R4 L-> L , S .

More Related Content

PDF
Array data structure
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
LR(1) and SLR(1) parsing
PDF
LR Parsing
PPT
Parsing
PPTX
Shift reduce parser
PPTX
Quadratic probing
PPTX
Types of Parser
Array data structure
Algorithms Lecture 2: Analysis of Algorithms I
LR(1) and SLR(1) parsing
LR Parsing
Parsing
Shift reduce parser
Quadratic probing
Types of Parser

What's hot (20)

PPTX
Top down parsing
PPTX
heap Sort Algorithm
PPTX
CLR AND LALR PARSER
PDF
Bottom up parser
PPTX
Python Functions
PPTX
Context free grammar
DOCX
Nonrecursive predictive parsing
PDF
PPTX
Syntax Analysis - LR(0) Parsing in Compiler
PPTX
Regular Expression to Finite Automata
PDF
LR(1) CLR(1) Parser with Example
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PDF
Lexical Analysis - Compiler design
PPT
Linked list
PPT
Medians and order statistics
PPT
Asymptotic notations
PPTX
LALR Parser Presentation ppt
PPTX
Bootstrapping in Compiler
Top down parsing
heap Sort Algorithm
CLR AND LALR PARSER
Bottom up parser
Python Functions
Context free grammar
Nonrecursive predictive parsing
Syntax Analysis - LR(0) Parsing in Compiler
Regular Expression to Finite Automata
LR(1) CLR(1) Parser with Example
Chapter 5 -Syntax Directed Translation - Copy.ppt
Lexical Analysis - Compiler design
Linked list
Medians and order statistics
Asymptotic notations
LALR Parser Presentation ppt
Bootstrapping in Compiler
Ad

Similar to Slr parser (20)

PPTX
UNIT 2 (1).pptx
PPTX
This is a presentation on the parsing.pptx
PPT
LR_Parser compiler how to compiler lr1 ll1
PPT
LR-Parsing.ppt
PPT
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
PDF
Introduction to Functional Programming with Scala
PDF
LR0Examples.pdf LR(0) LR(1) it's my pres
PDF
Lecture11 syntax analysis_7
DOCX
11-SLR input string parsing, CLR introduction-06-06-2023.docx
PPT
Predicting Stock Market Trends Using Machine Learning and Deep Learning Algor...
PPTX
3.ASSEMBLERS.pptx
PDF
PDF
PDF
PDF
Database Systems The Complete Book 2nd Edition Molina Solutions Manual
PPTX
10-SLR parser practice problems-02-06-2023.pptx
PPTX
Bottom-up parsingn_CompilationTechnics.pptx
PPTX
Bottom-up parsingn_CompilationTechnics.pptx
PPTX
BOTTOM UP PARSING GROUP 3.pptx
UNIT 2 (1).pptx
This is a presentation on the parsing.pptx
LR_Parser compiler how to compiler lr1 ll1
LR-Parsing.ppt
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
Introduction to Functional Programming with Scala
LR0Examples.pdf LR(0) LR(1) it's my pres
Lecture11 syntax analysis_7
11-SLR input string parsing, CLR introduction-06-06-2023.docx
Predicting Stock Market Trends Using Machine Learning and Deep Learning Algor...
3.ASSEMBLERS.pptx
Database Systems The Complete Book 2nd Edition Molina Solutions Manual
10-SLR parser practice problems-02-06-2023.pptx
Bottom-up parsingn_CompilationTechnics.pptx
Bottom-up parsingn_CompilationTechnics.pptx
BOTTOM UP PARSING GROUP 3.pptx
Ad

More from Akila Krishnamoorthy (12)

PPTX
Automata Theory - Turing machine
PPTX
Automata theory - RE to DFA Conversion
PPTX
Automata theory - Push Down Automata (PDA)
PPTX
Automata theory -RE to NFA-ε
PPTX
Automata theory - NFA ε to DFA Conversion
PPTX
Automata theory - NFA to DFA Conversion
PPTX
Automata theory -- NFA and DFA construction
PPTX
Intro to automata theory
PPTX
Automata theory -Conversion of ε nfa to nfa
PPTX
Automata theory - CFG and normal forms
PPTX
Linear data structure concepts
PPTX
Keypoints c strings
Automata Theory - Turing machine
Automata theory - RE to DFA Conversion
Automata theory - Push Down Automata (PDA)
Automata theory -RE to NFA-ε
Automata theory - NFA ε to DFA Conversion
Automata theory - NFA to DFA Conversion
Automata theory -- NFA and DFA construction
Intro to automata theory
Automata theory -Conversion of ε nfa to nfa
Automata theory - CFG and normal forms
Linear data structure concepts
Keypoints c strings

Recently uploaded (20)

PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Digital Logic Computer Design lecture notes
PPT
Project quality management in manufacturing
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
Mechanical Engineering MATERIALS Selection
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
PPT on Performance Review to get promotions
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Sustainable Sites - Green Building Construction
Structs to JSON How Go Powers REST APIs.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
additive manufacturing of ss316l using mig welding
Internet of Things (IOT) - A guide to understanding
Embodied AI: Ushering in the Next Era of Intelligent Systems
Digital Logic Computer Design lecture notes
Project quality management in manufacturing
CYBER-CRIMES AND SECURITY A guide to understanding
Mechanical Engineering MATERIALS Selection
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
OOP with Java - Java Introduction (Basics)
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Arduino robotics embedded978-1-4302-3184-4.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPT on Performance Review to get promotions
CH1 Production IntroductoryConcepts.pptx
Sustainable Sites - Green Building Construction

Slr parser

  • 1. SLR PARSER Steps: 1. create augment grammar 2. generate kernel items 3. find closure 4. compute goto() 5. construct parsing table 6. parse the string Let us consider grammar: S->a S->(L) L->S L->L,S
  • 2. • Step :1 Create augment grammar S is start symbol in the given grammar Augment grammar is S’-> S • Step :2 Generate kernel items Introduce dot in RHS of the production`` S’-> .S • Step :3 Find closure (Rule: A -> α.Xβ i.e if there is nonterminal next to dot then Include X production)) S’-> .S S-> . a S->.(L) I0
  • 3. Step :4 compute goto() S’-> S . I1 Goto (I0,a) S-> a . I2 Goto (I0,( ) S’-> .S S-> . a S->.(L) I0 S-> (.L) L->.S L>.L,S S->.a S->.(L) I3 Goto (I3,L ) S-> (L .) L->L . ,S I4 Goto (I3,S ) L->S . I5 Goto (I3,a ) S->a . I2 Goto (I3, ( ) S-> (. L ) L->.S L>.L,S S->.a S->.(L) I3 Goto (I0,S)
  • 4. Goto (I4, ) ) S-> (L) . I6 Goto (I4, , ) L->L , . S S-> . a S->.(L) I7 Goto (I7,S ) L->L , S . I8 Goto (I7,a ) S-> a . I2 Goto (I7,( ) S-> (.L) L->.S L>.L,S S->.a S->.(L) I3 label Production Ending iteration R0 S’-> S . I1 R1 S->a . I2 R2 S->(L) . I6 R3 L->S . I5 R4 L->L,S . I8
  • 5. Step :5 construct parsing table Label the rows of table with no. of iterations Divide the Column into two parts • Action part: terminal symbols • Goto part: Nonterminal symbols Terminals Non terminals a ( ) , $ S L 0 1 2 3 4 5 6 7 8
  • 6. Step :5 construct parsing table from step 4: Label the rows of table with no. of iterations Divide the Column into two parts • Action part: terminal symbols • Goto part: Nonterminal symbols ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 2 3 S2 S3 5 4 4 S6 S7 5 6 7 S2 S3 8 8 Goto (I0, S) 1 Goto (I3, ( ) 3 Goto (I0, a) 2 Goto (I4, ) ) 6 Goto (I0, ( ) 3 Goto (I4, ,) 7 Goto (I3, L) 4 Goto (I7, S) 8 Goto (I3, S) 5 Goto (I7, a) 2 Goto (I3, a) 2 Goto (I7, ( ) 3
  • 7. Step :5 construct parsing table Label the rows of table with no. of iterations Divide the Column into two parts • Action part: terminal symbols • Goto part: Nonterminal symbols ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 label Production Ending iteration Follow(LHS) R0 S’-> S . I1 Follow(S’)={ $ } R1 S-> a . I2 Follow(S)={ $ ) , } R2 S-> ( L ) . I6 Follow(S)={ $ ) , } R3 L-> S . I5 Follow(L)={ ) , } R4 L-> L , S . I8 Follow(L)={ ) , }
  • 8. Step :5 construct parsing table Label the rows of table with no. of iterations Divide the Column into two parts • Action part: terminal symbols • Goto part: Nonterminal symbols ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 label Production Ending iteration Follow(LHS) R0 S’-> S . I1 Follow(S’)={ $ } R1 S-> a . I2 Follow(S)={ $ ) , } R2 S-> ( L ) . I6 Follow(S)={ $ ) , } R3 L-> S . I5 Follow(L)={ ) , } R4 L-> L , S . I8 Follow(L)={ ) , } Goto (I0, S) 1 Goto (I3, ( ) 3 Goto (I0, a) 2 Goto (I4, ) ) 6 Goto (I0, ( ) 3 Goto (I4, ,) 7 Goto (I3, L) 4 Goto (I7, S) 8 Goto (I3, S) 5 Goto (I7, a) 2 Goto (I3, a) 2 Goto (I7, ( ) 3
  • 9. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 10. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 11. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 12. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 13. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 14. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 15. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 16. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 $0(3L4 , 7a2 )$ R1 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 17. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 $0(3L4 , 7a2 )$ R1 $0(3L4 , 7S8 )$ R4 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 18. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 $0(3L4 , 7a2 )$ R1 $0(3L4 , 7S8 )$ R4 $0(3L4 ) $ S6 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 19. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 $0(3L4 , 7a2 )$ R1 $0(3L4 , 7S8 )$ R4 $0(3L4 ) $ S6 $0(3L4)6 $ R2 label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .
  • 20. Step :6 String parsing Let string w=(a,a) derived from the given grammar S – Shift action * shift input symbol to the stack * shift number to the stack R – Reduce action * pop 2 times of RHS symbols * shift LHS to the stack * find the number in the parsing table for the last two elements in the stack ACTION GOTO a ( ) , $ S L 0 S2 S3 1 1 accept 2 R1 R1 R1 3 S2 S3 5 4 4 S6 S7 5 R3 R3 6 R2 R2 R2 7 S2 S3 8 8 R4 R4 Stack Input Action $0 (a,a)$ S3 $0(3 a,a)$ S2 $0(3a2 ,a)$ R1 $0(3S5 ,a)$ R3 $0(3L4 ,a)$ S7 $0(3L4 , 7 a)$ S2 $0(3L4 , 7a2 )$ R1 $0(3L4 , 7S8 )$ R4 $0(3L4 ) $ S6 $0(3L4)6 $ R2 $0S1 $ accept Hence the string parsed successfully !!!!!! label Production R0 S’-> S . R1 S-> a . R2 S-> ( L ) . R3 L-> S . R4 L-> L , S .