6.
Shift Reduce Parsers using Stack allocation
Aim:
To write a C program to implement Shift Reduce Parsers
Algorithm:
Get the no.of productions and the input string
Create a stack with $ symbol at the top of the stack
Push the current input symbol to the stack
If the stack that matches with the right side of the production then replace the RHS with
the corresponding non terminal
Repeat Step 3 & 4 until the input string and stack that contains only $
Display the result
Input:
Enter the no of productions -> 3
Enter the non terminal -> E
Enter the RHS -> E+E
Enter the non terminal -> E
Enter the RHS -> E-E
Enter the non terminal -> E
Enter the RHS -> a
Enter the input symbol ->a+a-a
Output:
STACK INPUT
$ a+a-a$
$a +a-a$
$E +a-a$
$E+ a-a$
$E+a -a$
$E+E -a$
$E -a$
$E- a$
$E-a $
$E-E $
$E $
$ $
Success
Result:
Thus the program for shift reduce parsers is successfully executed and the result is verified .