CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables
by Wim Bohm and Michelle Strout
CS453 Shift-reduce Parsing 1
CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR - - PowerPoint PPT Presentation
CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables by Wim Bohm and Michelle Strout CS453 Shift-reduce Parsing 1 Plan for Today Finish PA1 this week Friday recitation: help with PA1 Also on Thursday and
CS453 Shift-reduce Parsing 1
CS453 Shift-reduce Parsing 2
Shift-reduce parsing, LR(1)
LL(k) must predict which production looking ahead k: S à SS | (S) | ε is it S à SS or (S) when I see ((((……. ? produces the parse tree TOP DOWN, with a left to right derivation LR(k) postpones the decision until all tokens of the rhs plus k more tokens
It does this by parsing BOTTOM UP
CS453 Shift-reduce Parsing 3
LR(k) parser
LR parsing algorithm
CS453 Shift-reduce Parsing 4
CS453 Shift-reduce Parsing 5
The LR parsing engine …
Shift -- push input token onto the stack Reduce -- pop a rhs off the stack and push the corresponding lhs
CS453 Shift-reduce Parsing 6
CS453 Shift-reduce Parsing 7
CS453 Shift-reduce Parsing 8
CS453 Shift-reduce Parsing 9
These algorithms get more and more sophisticated, starting from
Parser generators such as java-cup use the more sophisticated
Today the goal is to understand how to do a shift and reduce
CS453 Shift-reduce Parsing 10
CS453 Shift-reduce Parsing 11
CS453 Shift-reduce Parsing 12
CS453 Shift-reduce Parsing 13