Professional Documents
Culture Documents
CS21036 CD
CS21036 CD
IN COMPILER
Name : Pravin Jaiswal
USN no. : CS21036
Semester : 6th sem ‘B’
Guided by : Dr. Manish Goswami
SHIFT REDUCE PARSER
❖Shift-reduce parsing is a common technique used in bottom-up
parsing algorithms.
❖It involves two main actions: shifting and reducing.
❖Shift operation moves the next input token onto a stack.
❖Reduce operation applies a production rule to a portion of the
stack, replacing it with a non-terminal symbol.
❖Widely used in syntactic analysis for various applications.
BASIC OPERATIONS
❖ Shift: This involves moving symbols from the input buffer onto
the stack.
❖ Reduce: If the handle appears on top of the stack then, its
reduction by using appropriate production rule is done i.e. RHS of
a production rule is popped out of a stack and LHS of a production
rule is pushed onto the stack.
❖ Accept: If only the start symbol is present in the stack and the
input buffer is empty then, the parsing action is called accept.
When accepted action is obtained, it is means successful parsing is
done.
❖ Error: This is the situation in which the parser can neither
perform shift action nor reduce action and not even accept action.
EXAMPLE
Perform Shift Reduce parsing for input string “id + id + id”.
S –> S + S
S –> S * S
S –> id
ADVANTAGES
❖ Shift-reduce parsing is efficient and can handle a wide range of
context-free grammars.
❖ https://www.geeksforgeeks.org
❖ https://www.javatpoint.com/shift-reduce-parsing
❖ https://en.wikipedia.org/wiki/Shift-reduce_parser
❖ https://www.codingninjas.com/studio/library/shift-
reduce-parsing
THANK YOU