System Software Lab Manual
COET, Akola 31
Practical 2
Aim: Program for predictive parser.
Theory:
Predictive parsers can be depicted using transition diagrams for each non-terminal symbol where
the edges between the initial and the final states are labeled by the symbols (terminals and non-
terminals) of the right side of the production rule.
Program
// PROGRAM FOR PREDICTIVE PARSER
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>
void display(void);
void push(char);
char pop(void);
char stack[10];
int top=0,index=0;
char *istr,tos,curr_symb,len;
char E[]={'d','A','T','\n','+','B','\n','*','B','\n','(','A','T','\n',')','B','\n','$','B','\n'};
char A[]={'d','B','\n','+','A','T','+','\n','*','B','\n','(','B','\n',')','N','\n','$','N','\n'};
char T[]={'d','H','F','\n','+','B','\n','*','B','\n','(','H','F','\n',')','B','\n','$','B','\n'};
char H[]={'d','B','\n','+','N','\n','*','H','F','*','\n','(','B','\n',')','N','\n','$','N','\n'};
char F[]={'d','d','\n','+','B','\n','*','B','\n','(',')','E','(','\n',')','B','\n','$','B','\n'};
// for above: d=id B=blank N=null production A=E' H=T'
void main()
{
int i,j,error_flag=0;
clrscr();
printf("\n Enter Input String (at the end $) : ");
scanf("%s",istr);
len=strlen(istr);
push('$');
push('E');
printf("Stack\tInput\n");
display();
curr_symb=istr[index];
while(1)
{
tos=pop();
top--;