SlideShare a Scribd company logo
Syntax Analysis Part II Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009
Bottom-Up Parsing ,[object Object],[object Object],[object Object],[object Object],[object Object]
Operator-Precedence Parsing ,[object Object],[object Object]
Shift-Reduce Parsing Grammar: S      a   A B  e A      A   b c  |  b B      d Shift-reduce corresponds to a rightmost derivation: S    rm   a  A B  e    rm   a   A  d e    rm  a  A  b c d e    rm  a b b c d e Reducing a sentence: a  b  b c d e a  A  b c  d e a  A  d  e a  A B   e S S a  b  b  c  d  e A A B a  b  b  c  d  e A A B a  b  b  c  d  e A A a  b  b  c  d  e A These match production’s right-hand sides
Handles Handle Grammar: S      a   A B  e A      A   b c  |  b B      d A  handle  is a substring of grammar symbols in a right-sentential form  that matches a right-hand side of a production NOT a handle, because further reductions will fail (result is not a sentential form) a  b  b c d e a  A  b  c d e a  A A  e … ? a  b  b c d e a  A  b c  d e a  A  d  e a  A B   e S
Stack Implementation of Shift-Reduce Parsing Stack $ $ id $ E $ E + $ E + id $ E + E $ E + E * $ E + E * id $ E + E * E $ E + E $ E Input id+id*id$ +id*id$ +id*id$ id*id$ *id$ *id$ id$ $ $ $ $ Action shift reduce  E      id shift shift reduce  E      id shift (or reduce?) shift reduce  E      id reduce  E      E  *  E reduce  E      E  +  E accept Grammar: E      E   +   E E     E   *   E E      (   E   ) E      id Find handles to reduce How to resolve conflicts?
Conflicts ,[object Object],[object Object],[object Object]
Shift-Reduce Parsing: Shift-Reduce Conflicts Stack $ … $ … if   E   then   S Input … $ else … $ Action … shift or reduce? Ambiguous grammar: S      if   E   then   S   |   if   E   then   S   else   S   |  other Resolve in favor of shift, so  else matches closest  if
Shift-Reduce Parsing: Reduce-Reduce Conflicts Stack $ $ a Input aa$ a$ Action shift reduce  A      a  or   B      a  ? Grammar: C      A B A     a B      a Resolve in favor of reduce  A      a , otherwise we’re stuck!
LR( k ) Parsers: Use a DFA for Shift/Reduce Decisions 1 2 4 5 3 0 start a A C B a Grammar: S      C C      A B A     a B      a State I 0 : S     • C   C     • A B A    • a State I 1 : S      C • State I 2 : C      A • B B    • a State I 3 : A     a • State I 4 : C     A B • State I 5 : B     a • goto ( I 0 , C ) goto ( I 0 , a ) goto ( I 0 , A ) goto ( I 2 , a ) goto ( I 2 , B ) Can only reduce  A      a ( not  B      a)
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0  a  3 $  0  A  2 $  0  A  2   a  5 $  0  A  2  B  4 $  0  C  1 Input aa$ a a$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C ) Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S     • C   C     • A B A    • a State I 3 : A     a • goto ( I 0 , a )
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0   a   3 $  0  A  2 $  0  A  2   a  5 $  0  A  2  B  4 $  0  C  1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C )  Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S     • C   C     • A B A    • a State I 2 : C      A • B B    • a goto ( I 0 , A )
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0  a  3 $  0  A   2 $  0  A  2   a  5 $  0  A  2  B  4 $  0  C  1 Input aa$ aa$ a$ a $ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C ) Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 2 : C      A • B B    • a State I 5 : B     a • goto ( I 2 , a )
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0  a  3 $  0  A  2 $  0  A  2   a  5 $  0  A  2  B  4 $  0  C  1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C ) Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 2 : C      A • B B    • a State I 4 : C     A B • goto ( I 2 , B )
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0  a  3 $  0  A  2 $  0  A  2   a  5 $  0   A  2  B  4 $  0  C  1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C ) Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S     • C   C     • A B A    • a State I 1 : S      C • goto ( I 0 , C )
DFA for Shift/Reduce Decisions Stack $  0 $  0 $  0  a  3 $  0  A  2 $  0  A  2   a  5 $  0  A  2  B  4 $  0  C   1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce  A      a  (goto 2) shift (goto 5) reduce  B      a  (goto 4) reduce  C      AB  (goto 1) accept ( S      C ) Grammar: S      C C      A B A     a B      a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S     • C   C     • A B A    • a State I 1 : S      C • goto ( I 0 , C )
Model of an LR Parser LR Parsing Program (driver) output stack input DFA shift reduce accept error Constructed with LR(0) method, SLR method, LR(1) method, or LALR(1) method a 1 a 2 … a i … a n $ action goto s m X m s m -1 X m -1 … s 0
LR Parsing (Driver) ( s 0   X 1  s 1   X 2  s 2  … X m  s m ,  a i   a i +1  …  a n   $ ) stack input Configuration ( = LR parser state): If   action [ s m , a i ] = shift  s   then  push  a i , push  s , and advance input: ( s 0   X 1  s 1   X 2  s 2  … X m  s m   a i   s ,  a i +1  …  a n   $ ) If   action [ s m , a i ] = reduce A       and  goto [ s m-r , A ] =  s  with  r =|  |  then pop 2 r  symbols, push  A , and push  s : ( s 0   X 1  s 1   X 2  s 2  … X m-r  s m-r   A   s ,  a i   a i +1  …  a n   $ ) If   action [ s m , a i ] = accept  then  stop If   action [ s m , a i ] = error  then  attempt recovery
Example LR Parse Table Grammar: 1.  E      E   +   T 2.  E      T 3.  T     T   *   F 4.  T     F 5.  F      (   E   ) 6.  F      id Shift & goto 5 Reduce by production #1 action goto state s5 s4 s6 acc r2 s7 r2 r2 r4 r4 r4 r4 s5 s4 r6 r6 r6 r6 s5 s4 s5 s4 s6 s11 r1 s7 r1 r1 r3 r3 r3 r3 r5 r5 r5 r5 id + * ( ) $ 0 1 2 3 4 5 6 7 8 9 10 11 E T F 1 2 3 8 2 3 9 3 10
Example LR Parsing Stack $  0 $  0  id  5 $  0  F   3 $  0  T  2 $  0  T  2  *  7 $  0  T  2  *  7  id  5 $  0  T  2  *  7  F  10 $  0  T  2 $  0  E  1 $  0  E  1  +  6 $  0  E  1  +  6  id  5 $  0  E  1  +  6  F  3 $  0  E  1  +  6  T  9 $  0  E  1 Input id*id+id$ *id+id$ *id+id$ *id+id$ id+id$ +id$ +id$ +id$  +id$  id$ $ $ $ $ Action shift 5 reduce 6 goto 3 reduce 4 goto 2 shift 7 shift 5 reduce 6 goto 10 reduce 3 goto 2 reduce 2 goto 1 shift 6 shift 5 reduce 6 goto 3 reduce 4 goto 9 reduce 1 goto 1 accept Grammar: 1.  E      E   +   T 2.  E      T 3.  T     T   *   F 4.  T     F 5.  F      (   E   ) 6.  F      id
SLR Grammars ,[object Object],[object Object],S     E E      id   +   E E      id State I 0 : S     • E   E     • id   +   E E    • id State I 2 : E     id • +   E E     id • goto ( I 0 , id ) goto ( I 3 , + ) FOLLOW( E )={ $ } thus reduce on  $ Shift on  +
SLR Parsing Table ,[object Object],[object Object],1.  S     E 2.  E      id   +   E 3.  E      id FOLLOW( E )={ $ } thus reduce on  $ Shift on  + s2 acc s3 r3 s2 r2 id + $ 0 1 2 3 4 E 1 4
SLR Parsing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constructing SLR Parsing Tables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LR(0) Items of a Grammar ,[object Object],[object Object],[object Object]
Constructing the set of LR(0) Items of a Grammar ,[object Object],[object Object],[object Object],[object Object]
The Closure Operation for LR(0) Items ,[object Object],[object Object],[object Object]
The Closure Operation (Example) Grammar: E      E   +   T  |  T T     T   *   F  |  F F      (   E   ) F      id { [ E ’    •  E ] } closure ({[ E ’    • E ]}) =  { [ E ’    •  E ]   [ E     •  E   +   T ]   [ E     •  T ]   } { [ E ’    •  E ]   [ E     •  E   +   T ]   [ E     •  T ]   [ T    •  T   *   F ]   [ T    •  F ] } { [ E ’    •  E ]   [ E     •  E   +   T ]   [ E     •  T ]   [ T    •  T   *   F ]   [ T    •  F ]   [ F     •  (   E   )]   [ F     •  id ] } Add [ E  •  ] Add [ T  •  ] Add [ F  •  ]
The Goto Operation for LR(0) Items ,[object Object],[object Object],[object Object]
The Goto Operation (Example 1) Suppose  I  = Then  goto ( I , E ) =  closure ({[ E ’     E  •,  E      E  •   +   T ]}) = { [ E ’     E  •]   [ E      E  •   +   T ] } Grammar: E      E   +   T  |  T T     T   *   F  |  F F      (   E   ) F      id { [ E ’    •  E ]   [ E     •  E   +   T ]   [ E     •  T ]   [ T    •  T   *   F ]   [ T    •  F ]   [ F     •  (   E   )]   [ F     •  id ] }
The Goto Operation (Example 2) Suppose  I  = { [ E ’     E  •] ,  [ E      E  •  +   T ]   } Then  goto ( I , + ) =  closure ({[ E      E  +  •  T ]}) = { [ E      E  +  •  T ]   [ T     •  T  *  F ]   [ T     •  F ]   [ F     •  (  E  ) ]   [ F     •  id ] } Grammar: E      E   +   T  |  T T     T   *   F  |  F F      (   E   ) F      id
Example SLR Grammar and LR(0) Items Augmented grammar: 1.  C ’     C 2.  C      A B 3.  A     a 4.  B      a State I 0 : C ’    • C   C     • A B A    • a State I 1 : C ’     C • State I 2 : C      A • B B    • a State I 3 : A     a • State I 4 : C     A B • State I 5 : B     a • goto ( I 0 , C ) goto ( I 0 , a ) goto ( I 0 , A ) goto ( I 2 , a ) goto ( I 2 , B ) I 0  =  closure ({[ C ’    • C ]}) I 1  = goto( I 0 , C ) =  closure ({[ C ’     C •]}) … start final
Example SLR Parsing Table State I 0 : C ’    • C   C     • A B A    • a State I 1 : C ’     C • State I 2 : C      A • B B    • a State I 3 : A     a • State I 4 : C     A B • State I 5 : B     a • 1 2 4 5 3 0 start a A C B a Grammar: 1.  C ’     C 2.  C      A B 3.  A     a 4.  B      a s3 acc s5 r3 r2 r4 a $ 0 1 2 3 4 5 C A B 1 2 4
SLR and Ambiguity ,[object Object],[object Object],I 0 : S ’    • S   S     • L = R S    • R L    • * R   L    • id R    • L I 1 : S ’     S • I 2 : S      L • = R R     L • I 3 : S     R • I 4 : L     * • R   R    • L L    • * R   L    • id I 5 : L     id • I 6 : S      L = • R R    • L  L    • * R   L    • id I 7 : L     * R • I 8 : R     L • I 9 : S      L = R • action [2, = ]=s6 action [2, = ]=r5 no Has no SLR parsing table
LR(1) Grammars ,[object Object],[object Object],[object Object],LR(0) item: [ A  •  ] LR(1) item: [ A  •  ,  a ]
SLR Versus LR(1) ,[object Object],[object Object],I 2 : S      L • = R R     L • action [2, = ]=s6 Should not reduce on  = , because no right-sentential form begins with  R = split R     L • S      L • = R lookahead = $ action [2, $ ]=r5
LR(1) Items ,[object Object],[object Object],[object Object]
The Closure Operation for LR(1) Items ,[object Object],[object Object],[object Object]
The Goto Operation for LR(1) Items ,[object Object],[object Object]
Constructing the set of LR(1) Items of a Grammar ,[object Object],[object Object],[object Object],[object Object]
Example Grammar and LR(1) Items ,[object Object],[object Object],[object Object]
[ S ’    • S, $ ] goto( I 0 , S )= I 1   [ S    • L = R, $ ] goto( I 0 , L )= I 2   [ S    • R, $ ] goto( I 0 , R )= I 3   [ L    • * R, =/$ ] goto( I 0 , * )= I 4   [ L    • id , =/$ ] goto( I 0 , id )= I 5   [ R    • L, $ ] goto( I 0 , L )= I 2   [ S ’     S • , $ ] [ S     L • = R, $ ] goto( I 0 , = )= I 6   [ R     L • , $ ] [ S     R • , $ ] [ L     * • R, =/$ ] goto( I 4 , R )= I 7   [ R    • L, =/$ ] goto( I 4 , L )= I 8   [ L    • * R, =/$ ] goto( I 4 , * )= I 4   [ L    • id , =/$ ] goto( I 4 , id )= I 5   [ L     id • , =/$ ] [ S     L = • R, $ ] goto( I 6 , R )= I 9   [ R    • L, $ ] goto( I 6 , L )= I 10 [ L    • * R, $ ] goto( I 6 , * )= I 11   [ L    • id , $ ] goto( I 6 , id )= I 12   [ L     * R • , =/$ ] [ R     L • , =/$ ] [ S     L = R • , $ ] [ R     L • , $ ] [ L     * • R, $ ] goto( I 11 , R )= I 13 [ R    • L, $ ] goto( I 11 , L )= I 10 [ L    • * R, $ ] goto( I 11 , * )= I 11 [ L    • id , $ ] goto( I 11 , id )= I 12 [ L     id • , $ ]  [ L     * R • , $ ] I 0 : I 1 : I 2 : I 3 : I 4 : I 5 : I 6 : I 7 : I 8 : I 9 : I 10 : I 12 : I 11 : I 13 :
Constructing Canonical LR(1) Parsing Tables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example LR(1) Parsing Table Grammar: 1. S’     S 2.  S      L   =   R 3.  S      R 4.  L      *   R 5.  L      id 6.  R      L s5 s4 acc s6 r6 r3 s5 s4 r5 r5 s12 s11 r4 r4 r6 r6 r2 r6 s12 s11 r5 r4 id * = $ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 S L R 1 2 3 8 7 10 9 10 13
LALR(1) Grammars ,[object Object],[object Object],[object Object],[object Object],[object Object]
Constructing LALR(1) Parsing Tables ,[object Object],[object Object],[ L     * • R, =/$ ] [ R    • L, =/$ ]  [ L    • * R, =/$ ]  [ L    • id , =/$ ]  [ L     * • R, $ ] [ R    • L, $ ] [ L    • * R, $ ] [ L    • id , $ ] I 4 : I 11 : [ L     * • R, = / $ ] [ R    • L, = / $ ] [ L    • * R, = / $ ] [ L    • id , = / $ ] Shorthand for two items in the same set
Example LALR(1) Grammar ,[object Object],[object Object],[object Object]
[ S ’    • S, $ ] goto( I 0 , S )= I 1   [ S    • L = R, $ ] goto( I 0 , L )= I 2   [ S    • R, $ ] goto( I 0 , R )= I 3   [ L    • * R, = / $ ] goto( I 0 , * )= I 4   [ L    • id , = / $ ] goto( I 0 , id )= I 5   [ R    • L, $ ] goto( I 0 , L )= I 2   [ S ’     S • , $ ] [ S     L • = R, $ ] goto( I 0 , = )= I 6   [ R     L • , $ ] [ S     R • , $ ] [ L     * • R, = / $ ] goto( I 4 , R )= I 7   [ R    • L, = / $ ] goto( I 4 , L )= I 9   [ L    • * R, = / $ ] goto( I 4 , * )= I 4   [ L    • id , = / $ ] goto( I 4 , id )= I 5   [ L     id • , = / $ ] [ S     L = • R, $ ] goto( I 6 , R )= I 8   [ R    • L, $ ] goto( I 6 , L )= I 9 [ L    • * R, $ ] goto( I 6 , * )= I 4   [ L    • id , $ ] goto( I 6 , id )= I 5   [ L     * R • , = / $ ] [ S     L = R • , $ ] [ R     L • , = / $ ] I 0 : I 1 : I 2 : I 3 : I 4 : I 5 : I 6 : I 7 : I 8 : I 9 : Shorthand for two items [ R     L • , = ] [ R     L • , $ ]
Example LALR(1) Parsing Table Grammar: 1.  S ’     S 2.  S      L   =   R 3.  S      R 4.  L      *   R 5.  L      id 6.  R      L s5 s4 acc s6 r6 r3 s5 s4 r5 r5 s5 s4 r4 r4 r2 r6 r6 id * = $ 0 1 2 3 4 5 6 7 8 9 S L R 1 2 3 9 7 9 8
LL, SLR, LR, LALR Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LL, SLR, LR, LALR Grammars LL(1) LR(1) LR(0) SLR LALR(1)
Dealing with Ambiguous Grammars 1.  S ’     E 2.  E      E   +   E 3.  E      id Shift/reduce conflict: action [4, + ] = shift 4 action [4, + ] = reduce  E      E   +   E   When reducing on  + : yields left associativity (id+id)+id When shifting on  + : yields right associativity id+(id+id) $  0  E  1  +  3  E  4  id+id+id$ +id$ $  0 … … stack input    s2 s3 acc r3 r3 s2 s3/r2 r2 id + $ 0 1 2 3 4 E 1 4
Using Associativity and Precedence to Resolve Conflicts ,[object Object],[object Object],[object Object],[object Object],S ’     E E      E   +   E E      E   *   E E      id $  0  E  1  *  3  E  5  id*id+id$ +id$ $  0 … … stack input reduce  E      E   *   E   
Error Detection in LR Parsing ,[object Object],[object Object]
Error Recovery in LR Parsing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Bisection method
Bisection methodBisection method
Bisection method
Md. Mujahid Islam
 
Unit 3
Unit 3Unit 3
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiers
blaircomp2003
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
Neha Kaurav
 
Intro to-iterative-deepening
Intro to-iterative-deepeningIntro to-iterative-deepening
Intro to-iterative-deepening
Adel Totott
 
Min-Max algorithm
Min-Max algorithmMin-Max algorithm
Min-Max algorithm
Dr. C.V. Suresh Babu
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
Ahmed Khateeb
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
Akshaya Arunan
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithm
Hema Kashyap
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptx
Ramakrishna Reddy Bijjam
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
Ahmed Daoud
 
10 Regular VS Non Regular Language.pptx
10 Regular VS Non Regular Language.pptx10 Regular VS Non Regular Language.pptx
10 Regular VS Non Regular Language.pptx
MuhammadFaizanHameed1
 
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
allyn joy calcaben
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
BISECTION METHOD
BISECTION METHODBISECTION METHOD
Counting, mathematical induction and discrete probability
Counting, mathematical induction and discrete probabilityCounting, mathematical induction and discrete probability
Counting, mathematical induction and discrete probability
SURBHI SAROHA
 
K-Means manual work
K-Means manual workK-Means manual work
K-Means manual work
Dr.E.N.Sathishkumar
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
Mohammad Ilyas Malik
 

What's hot (20)

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Bisection method
Bisection methodBisection method
Bisection method
 
Unit 3
Unit 3Unit 3
Unit 3
 
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiers
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Intro to-iterative-deepening
Intro to-iterative-deepeningIntro to-iterative-deepening
Intro to-iterative-deepening
 
Min-Max algorithm
Min-Max algorithmMin-Max algorithm
Min-Max algorithm
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithm
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptx
 
Chapter 9 morphological image processing
Chapter 9   morphological image processingChapter 9   morphological image processing
Chapter 9 morphological image processing
 
10 Regular VS Non Regular Language.pptx
10 Regular VS Non Regular Language.pptx10 Regular VS Non Regular Language.pptx
10 Regular VS Non Regular Language.pptx
 
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
BISECTION METHOD
BISECTION METHODBISECTION METHOD
BISECTION METHOD
 
Counting, mathematical induction and discrete probability
Counting, mathematical induction and discrete probabilityCounting, mathematical induction and discrete probability
Counting, mathematical induction and discrete probability
 
K-Means manual work
K-Means manual workK-Means manual work
K-Means manual work
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 

Viewers also liked

Module 11
Module 11Module 11
Module 11
bittudavis
 
Ch9a
Ch9aCh9a
Ch4a
Ch4aCh4a
Parsing using graphs
Parsing using graphsParsing using graphs
Parsing using graphs
kpingali
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
Jothi Lakshmi
 
Lexical 2
Lexical 2Lexical 2
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
bolovv
 
Artificial intelligence in medical image processing
Artificial intelligence in medical image processingArtificial intelligence in medical image processing
Artificial intelligence in medical image processing
Farzad Jahedi
 
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
White Clarke Group
 
Artificial Intelligence in Gaming
Artificial Intelligence in GamingArtificial Intelligence in Gaming
Artificial Intelligence in Gaming
Satvik J
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
WPVKP.COM
 
Operating system kernal
Operating system kernalOperating system kernal
Operating system kernal
Sumit Rajpal
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
Akshaya Arunan
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
Shishir Jain
 

Viewers also liked (16)

Module 11
Module 11Module 11
Module 11
 
Ch9a
Ch9aCh9a
Ch9a
 
Ch4a
Ch4aCh4a
Ch4a
 
Parsing using graphs
Parsing using graphsParsing using graphs
Parsing using graphs
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
 
Lexical 2
Lexical 2Lexical 2
Lexical 2
 
Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Artificial intelligence in medical image processing
Artificial intelligence in medical image processingArtificial intelligence in medical image processing
Artificial intelligence in medical image processing
 
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
Artificial Intelligence: Use of AI and Natural Language Processing to effecti...
 
Artificial Intelligence in Gaming
Artificial Intelligence in GamingArtificial Intelligence in Gaming
Artificial Intelligence in Gaming
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
 
Operating system kernal
Operating system kernalOperating system kernal
Operating system kernal
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 

Similar to Ch4b

Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
Mahesh Kumar Chelimilla
 
LR-Parsing.ppt
LR-Parsing.pptLR-Parsing.ppt
LR-Parsing.ppt
BapanKar2
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
Maulik Togadiya
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
R Islam
 
UNIT 2 (1).pptx
UNIT 2 (1).pptxUNIT 2 (1).pptx
UNIT 2 (1).pptx
Abhishek Tirkey
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
Jena Catherine Bel D
 
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
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
BottomupparserBottomupparser
BOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptxBOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptx
SnehaTiwari84
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
venkatapranaykumarGa
 
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPTch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
FutureTechnologies3
 
Compiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLRCompiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLR
Riazul Islam
 
lr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptxlr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptx
srilakshmis17
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
BapanKar2
 
Playing with State Monad
Playing with State MonadPlaying with State Monad
Playing with State Monad
David Galichet
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
Dr. C.V. Suresh Babu
 
Ch5b.pdf
Ch5b.pdfCh5b.pdf

Similar to Ch4b (20)

Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
 
LR-Parsing.ppt
LR-Parsing.pptLR-Parsing.ppt
LR-Parsing.ppt
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
UNIT 2 (1).pptx
UNIT 2 (1).pptxUNIT 2 (1).pptx
UNIT 2 (1).pptx
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
 
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
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
BOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptxBOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptx
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
 
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPTch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
ch5-bottomupparser_jfdrhgfrfyyssf-gfrrt.PPT
 
Compiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLRCompiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLR
 
lr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptxlr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptx
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
 
Playing with State Monad
Playing with State MonadPlaying with State Monad
Playing with State Monad
 
LR(0) PARSER
LR(0) PARSERLR(0) PARSER
LR(0) PARSER
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 
Ch5b.pdf
Ch5b.pdfCh5b.pdf
Ch5b.pdf
 

More from kinnarshah8888

Yuva Msp All
Yuva Msp AllYuva Msp All
Yuva Msp All
kinnarshah8888
 
Yuva Msp Intro
Yuva Msp IntroYuva Msp Intro
Yuva Msp Intro
kinnarshah8888
 
Ch6
Ch6Ch6
Ch9c
Ch9cCh9c
Ch8a
Ch8aCh8a
Ch5a
Ch5aCh5a
Ch9b
Ch9bCh9b
Ch10
Ch10Ch10
Ch7
Ch7Ch7
Ch3
Ch3Ch3
Ch2
Ch2Ch2
Ch8b
Ch8bCh8b
Ch5b
Ch5bCh5b
Ch4c
Ch4cCh4c
Ch1
Ch1Ch1

More from kinnarshah8888 (15)

Yuva Msp All
Yuva Msp AllYuva Msp All
Yuva Msp All
 
Yuva Msp Intro
Yuva Msp IntroYuva Msp Intro
Yuva Msp Intro
 
Ch6
Ch6Ch6
Ch6
 
Ch9c
Ch9cCh9c
Ch9c
 
Ch8a
Ch8aCh8a
Ch8a
 
Ch5a
Ch5aCh5a
Ch5a
 
Ch9b
Ch9bCh9b
Ch9b
 
Ch10
Ch10Ch10
Ch10
 
Ch7
Ch7Ch7
Ch7
 
Ch3
Ch3Ch3
Ch3
 
Ch2
Ch2Ch2
Ch2
 
Ch8b
Ch8bCh8b
Ch8b
 
Ch5b
Ch5bCh5b
Ch5b
 
Ch4c
Ch4cCh4c
Ch4c
 
Ch1
Ch1Ch1
Ch1
 

Recently uploaded

Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
Fwdays
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 

Recently uploaded (20)

Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 

Ch4b

  • 1. Syntax Analysis Part II Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009
  • 2.
  • 3.
  • 4. Shift-Reduce Parsing Grammar: S  a A B e A  A b c | b B  d Shift-reduce corresponds to a rightmost derivation: S  rm a A B e  rm a A d e  rm a A b c d e  rm a b b c d e Reducing a sentence: a b b c d e a A b c d e a A d e a A B e S S a b b c d e A A B a b b c d e A A B a b b c d e A A a b b c d e A These match production’s right-hand sides
  • 5. Handles Handle Grammar: S  a A B e A  A b c | b B  d A handle is a substring of grammar symbols in a right-sentential form that matches a right-hand side of a production NOT a handle, because further reductions will fail (result is not a sentential form) a b b c d e a A b c d e a A A e … ? a b b c d e a A b c d e a A d e a A B e S
  • 6. Stack Implementation of Shift-Reduce Parsing Stack $ $ id $ E $ E + $ E + id $ E + E $ E + E * $ E + E * id $ E + E * E $ E + E $ E Input id+id*id$ +id*id$ +id*id$ id*id$ *id$ *id$ id$ $ $ $ $ Action shift reduce E  id shift shift reduce E  id shift (or reduce?) shift reduce E  id reduce E  E * E reduce E  E + E accept Grammar: E  E + E E  E * E E  ( E ) E  id Find handles to reduce How to resolve conflicts?
  • 7.
  • 8. Shift-Reduce Parsing: Shift-Reduce Conflicts Stack $ … $ … if E then S Input … $ else … $ Action … shift or reduce? Ambiguous grammar: S  if E then S | if E then S else S | other Resolve in favor of shift, so else matches closest if
  • 9. Shift-Reduce Parsing: Reduce-Reduce Conflicts Stack $ $ a Input aa$ a$ Action shift reduce A  a or B  a ? Grammar: C  A B A  a B  a Resolve in favor of reduce A  a , otherwise we’re stuck!
  • 10. LR( k ) Parsers: Use a DFA for Shift/Reduce Decisions 1 2 4 5 3 0 start a A C B a Grammar: S  C C  A B A  a B  a State I 0 : S  • C C  • A B A  • a State I 1 : S  C • State I 2 : C  A • B B  • a State I 3 : A  a • State I 4 : C  A B • State I 5 : B  a • goto ( I 0 , C ) goto ( I 0 , a ) goto ( I 0 , A ) goto ( I 2 , a ) goto ( I 2 , B ) Can only reduce A  a ( not B  a)
  • 11. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ a a$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S  • C C  • A B A  • a State I 3 : A  a • goto ( I 0 , a )
  • 12. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S  • C C  • A B A  • a State I 2 : C  A • B B  • a goto ( I 0 , A )
  • 13. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ aa$ a$ a $ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 2 : C  A • B B  • a State I 5 : B  a • goto ( I 2 , a )
  • 14. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 2 : C  A • B B  • a State I 4 : C  A B • goto ( I 2 , B )
  • 15. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S  • C C  • A B A  • a State I 1 : S  C • goto ( I 0 , C )
  • 16. DFA for Shift/Reduce Decisions Stack $ 0 $ 0 $ 0 a 3 $ 0 A 2 $ 0 A 2 a 5 $ 0 A 2 B 4 $ 0 C 1 Input aa$ aa$ a$ a$ $ $ $ Action start in state 0 shift (and goto state 3) reduce A  a (goto 2) shift (goto 5) reduce B  a (goto 4) reduce C  AB (goto 1) accept ( S  C ) Grammar: S  C C  A B A  a B  a The states of the DFA are used to determine if a handle is on top of the stack State I 0 : S  • C C  • A B A  • a State I 1 : S  C • goto ( I 0 , C )
  • 17. Model of an LR Parser LR Parsing Program (driver) output stack input DFA shift reduce accept error Constructed with LR(0) method, SLR method, LR(1) method, or LALR(1) method a 1 a 2 … a i … a n $ action goto s m X m s m -1 X m -1 … s 0
  • 18. LR Parsing (Driver) ( s 0 X 1 s 1 X 2 s 2 … X m s m , a i a i +1 … a n $ ) stack input Configuration ( = LR parser state): If action [ s m , a i ] = shift s then push a i , push s , and advance input: ( s 0 X 1 s 1 X 2 s 2 … X m s m a i s , a i +1 … a n $ ) If action [ s m , a i ] = reduce A   and goto [ s m-r , A ] = s with r =|  | then pop 2 r symbols, push A , and push s : ( s 0 X 1 s 1 X 2 s 2 … X m-r s m-r A s , a i a i +1 … a n $ ) If action [ s m , a i ] = accept then stop If action [ s m , a i ] = error then attempt recovery
  • 19. Example LR Parse Table Grammar: 1. E  E + T 2. E  T 3. T  T * F 4. T  F 5. F  ( E ) 6. F  id Shift & goto 5 Reduce by production #1 action goto state s5 s4 s6 acc r2 s7 r2 r2 r4 r4 r4 r4 s5 s4 r6 r6 r6 r6 s5 s4 s5 s4 s6 s11 r1 s7 r1 r1 r3 r3 r3 r3 r5 r5 r5 r5 id + * ( ) $ 0 1 2 3 4 5 6 7 8 9 10 11 E T F 1 2 3 8 2 3 9 3 10
  • 20. Example LR Parsing Stack $ 0 $ 0 id 5 $ 0 F 3 $ 0 T 2 $ 0 T 2 * 7 $ 0 T 2 * 7 id 5 $ 0 T 2 * 7 F 10 $ 0 T 2 $ 0 E 1 $ 0 E 1 + 6 $ 0 E 1 + 6 id 5 $ 0 E 1 + 6 F 3 $ 0 E 1 + 6 T 9 $ 0 E 1 Input id*id+id$ *id+id$ *id+id$ *id+id$ id+id$ +id$ +id$ +id$ +id$ id$ $ $ $ $ Action shift 5 reduce 6 goto 3 reduce 4 goto 2 shift 7 shift 5 reduce 6 goto 10 reduce 3 goto 2 reduce 2 goto 1 shift 6 shift 5 reduce 6 goto 3 reduce 4 goto 9 reduce 1 goto 1 accept Grammar: 1. E  E + T 2. E  T 3. T  T * F 4. T  F 5. F  ( E ) 6. F  id
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. The Closure Operation (Example) Grammar: E  E + T | T T  T * F | F F  ( E ) F  id { [ E ’  • E ] } closure ({[ E ’  • E ]}) = { [ E ’  • E ] [ E  • E + T ] [ E  • T ] } { [ E ’  • E ] [ E  • E + T ] [ E  • T ] [ T  • T * F ] [ T  • F ] } { [ E ’  • E ] [ E  • E + T ] [ E  • T ] [ T  • T * F ] [ T  • F ] [ F  • ( E )] [ F  • id ] } Add [ E  •  ] Add [ T  •  ] Add [ F  •  ]
  • 29.
  • 30. The Goto Operation (Example 1) Suppose I = Then goto ( I , E ) = closure ({[ E ’  E •, E  E • + T ]}) = { [ E ’  E •] [ E  E • + T ] } Grammar: E  E + T | T T  T * F | F F  ( E ) F  id { [ E ’  • E ] [ E  • E + T ] [ E  • T ] [ T  • T * F ] [ T  • F ] [ F  • ( E )] [ F  • id ] }
  • 31. The Goto Operation (Example 2) Suppose I = { [ E ’  E •] , [ E  E • + T ] } Then goto ( I , + ) = closure ({[ E  E + • T ]}) = { [ E  E + • T ] [ T  • T * F ] [ T  • F ] [ F  • ( E ) ] [ F  • id ] } Grammar: E  E + T | T T  T * F | F F  ( E ) F  id
  • 32. Example SLR Grammar and LR(0) Items Augmented grammar: 1. C ’  C 2. C  A B 3. A  a 4. B  a State I 0 : C ’  • C C  • A B A  • a State I 1 : C ’  C • State I 2 : C  A • B B  • a State I 3 : A  a • State I 4 : C  A B • State I 5 : B  a • goto ( I 0 , C ) goto ( I 0 , a ) goto ( I 0 , A ) goto ( I 2 , a ) goto ( I 2 , B ) I 0 = closure ({[ C ’  • C ]}) I 1 = goto( I 0 , C ) = closure ({[ C ’  C •]}) … start final
  • 33. Example SLR Parsing Table State I 0 : C ’  • C C  • A B A  • a State I 1 : C ’  C • State I 2 : C  A • B B  • a State I 3 : A  a • State I 4 : C  A B • State I 5 : B  a • 1 2 4 5 3 0 start a A C B a Grammar: 1. C ’  C 2. C  A B 3. A  a 4. B  a s3 acc s5 r3 r2 r4 a $ 0 1 2 3 4 5 C A B 1 2 4
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42. [ S ’  • S, $ ] goto( I 0 , S )= I 1 [ S  • L = R, $ ] goto( I 0 , L )= I 2 [ S  • R, $ ] goto( I 0 , R )= I 3 [ L  • * R, =/$ ] goto( I 0 , * )= I 4 [ L  • id , =/$ ] goto( I 0 , id )= I 5 [ R  • L, $ ] goto( I 0 , L )= I 2 [ S ’  S • , $ ] [ S  L • = R, $ ] goto( I 0 , = )= I 6 [ R  L • , $ ] [ S  R • , $ ] [ L  * • R, =/$ ] goto( I 4 , R )= I 7 [ R  • L, =/$ ] goto( I 4 , L )= I 8 [ L  • * R, =/$ ] goto( I 4 , * )= I 4 [ L  • id , =/$ ] goto( I 4 , id )= I 5 [ L  id • , =/$ ] [ S  L = • R, $ ] goto( I 6 , R )= I 9 [ R  • L, $ ] goto( I 6 , L )= I 10 [ L  • * R, $ ] goto( I 6 , * )= I 11 [ L  • id , $ ] goto( I 6 , id )= I 12 [ L  * R • , =/$ ] [ R  L • , =/$ ] [ S  L = R • , $ ] [ R  L • , $ ] [ L  * • R, $ ] goto( I 11 , R )= I 13 [ R  • L, $ ] goto( I 11 , L )= I 10 [ L  • * R, $ ] goto( I 11 , * )= I 11 [ L  • id , $ ] goto( I 11 , id )= I 12 [ L  id • , $ ] [ L  * R • , $ ] I 0 : I 1 : I 2 : I 3 : I 4 : I 5 : I 6 : I 7 : I 8 : I 9 : I 10 : I 12 : I 11 : I 13 :
  • 43.
  • 44. Example LR(1) Parsing Table Grammar: 1. S’  S 2. S  L = R 3. S  R 4. L  * R 5. L  id 6. R  L s5 s4 acc s6 r6 r3 s5 s4 r5 r5 s12 s11 r4 r4 r6 r6 r2 r6 s12 s11 r5 r4 id * = $ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 S L R 1 2 3 8 7 10 9 10 13
  • 45.
  • 46.
  • 47.
  • 48. [ S ’  • S, $ ] goto( I 0 , S )= I 1 [ S  • L = R, $ ] goto( I 0 , L )= I 2 [ S  • R, $ ] goto( I 0 , R )= I 3 [ L  • * R, = / $ ] goto( I 0 , * )= I 4 [ L  • id , = / $ ] goto( I 0 , id )= I 5 [ R  • L, $ ] goto( I 0 , L )= I 2 [ S ’  S • , $ ] [ S  L • = R, $ ] goto( I 0 , = )= I 6 [ R  L • , $ ] [ S  R • , $ ] [ L  * • R, = / $ ] goto( I 4 , R )= I 7 [ R  • L, = / $ ] goto( I 4 , L )= I 9 [ L  • * R, = / $ ] goto( I 4 , * )= I 4 [ L  • id , = / $ ] goto( I 4 , id )= I 5 [ L  id • , = / $ ] [ S  L = • R, $ ] goto( I 6 , R )= I 8 [ R  • L, $ ] goto( I 6 , L )= I 9 [ L  • * R, $ ] goto( I 6 , * )= I 4 [ L  • id , $ ] goto( I 6 , id )= I 5 [ L  * R • , = / $ ] [ S  L = R • , $ ] [ R  L • , = / $ ] I 0 : I 1 : I 2 : I 3 : I 4 : I 5 : I 6 : I 7 : I 8 : I 9 : Shorthand for two items [ R  L • , = ] [ R  L • , $ ]
  • 49. Example LALR(1) Parsing Table Grammar: 1. S ’  S 2. S  L = R 3. S  R 4. L  * R 5. L  id 6. R  L s5 s4 acc s6 r6 r3 s5 s4 r5 r5 s5 s4 r4 r4 r2 r6 r6 id * = $ 0 1 2 3 4 5 6 7 8 9 S L R 1 2 3 9 7 9 8
  • 50.
  • 51. LL, SLR, LR, LALR Grammars LL(1) LR(1) LR(0) SLR LALR(1)
  • 52. Dealing with Ambiguous Grammars 1. S ’  E 2. E  E + E 3. E  id Shift/reduce conflict: action [4, + ] = shift 4 action [4, + ] = reduce E  E + E When reducing on + : yields left associativity (id+id)+id When shifting on + : yields right associativity id+(id+id) $ 0 E 1 + 3 E 4 id+id+id$ +id$ $ 0 … … stack input    s2 s3 acc r3 r3 s2 s3/r2 r2 id + $ 0 1 2 3 4 E 1 4
  • 53.
  • 54.
  • 55.