Bottom-Up Parsing - Intro
Bottom-Up Parsing - Intro
Bottom-Up Parsing - Intro
Bottom Up Parsing
Problems:
• locate a handle
• decide which production to use (if there are more than two
candidate productions).
• In many cases, the leftmost substring which matches the
right side of some production A may not be a handle
because a reduction by this production may yield a string which
cannot be reduced to start symbol
aAbcde
aAAcde
Stack Implementation of Bottom-up parser
A bottom-up parser uses an explicit stack in its implementation
The main actions are shift and reduce
A bottom-up parser is also known as shift-reduce parser
Four operations are defined:
• shift, reduce, accept, and error
Shift: parser shifts the next token on the parser stack
Reduce: parser reduces the RHS of a production to its LHS .The handle always appears on top of the
stack
Accept: parser announces a successful completion of parsing
Error: parser discovers that a syntax error has occurred
The parser operates by:
Shifting tokens onto the stack
When a handle β is on top of stack, parser reduces β to LHS of production
Parsing continues until an error is detected or input is reduced to start symbol
Example
Consider the parsing of the input string id + id * id