Session 12
Session 12
COURSE CODE:21CS3204R
2
• 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.
3
For example:
consider the below grammar to accept the input string “id * id” using S-R parser
E→E+T|T
T→T*F | F
F→(E)|id
Actions of the Shift-reduce parser using Stack implementation
4
STACK INPUT ACTION
$ Id*id$ Shift
$T *id$ Shift
$T $ Reduce with E T
$E $ Accept
5
EX:2
6
CONFLICTS DURING SHIFTREDUCE PARSING
7
It is caused when the grammar allows a rule to be reduced for particular token, but, at the
same time, allowing another rule to be shifted for that same token.
Reduce Conflits:
the parser always reduces by the rule that was given first in the rules section of the yacc
input.
Again, the conflict is reported in the yacc output so that users can ensure that the choice
is correct. Precedence is not consulted in reduce-reduce conflicts.
8
Thank you