How To Write Source code For Recursive Descent Parsing

Source code In C programming
#include<stdio.h>
#include<conio.h>
int c=0;
char p[20];
void s();
void l();
void lprime();
void l()
{
s();
lprime();
}
void lprime()
{
if(p[c]==',')
{
c++;
s();
lprime();
}
}
void s()
{
if(p[c]=='a')
c++;
else if(p[c]=='(')
{
c++;
l();
if(p[c]==')')
c++;
else
c--;
}
else
printf("\nInvalid Expression");
}
void main()
{
clrscr();
printf("\nImplementation of RECURSIVE DESCENT PARSER\n");
printf("\nEnter the Expression:\n");
scanf("%s",p);
s();
if(p[c]=='$')
printf("\nThe String is accepted");
else
printf("\nThe string is rejected");
getch();
}
Recursive Descent Parsing Output Result

Implementation of RECURSIVE DESCENT PARSER
Enter the Expression:
a
The string is rejected
Implementation of RECURSIVE DESCENT PARSER
Enter the Expression:
a$
The String is accepted
Recursive Descent Parsing OUTPUT
Implementation of RECURSIVE DESCENT PARSER
Enter the Expression:
(a)$
The String is accepted

Implementation of RECURSIVE DESCENT PARSER
Enter the Expression:
b*c
Invalid Expression
The string is rejected

Related post