You are on page 1of 2

Write a C program to implement a Recursive Descent Parser.

#include<stdio.h>
#include <stdlib.h>
#include <string.h>
char l;

void match(char c)
{
if(l==c)
l=getchar();
else
{
printf("Invalid Input\n");
exit(0);
}
}

void E()
{
if(l=='i')
{
match('i');
EDash();
}
}

void EDash()
{
if(l=='+')
{
match('+');
match('i');
EDash();
}
else
return;
}

void main()
{
char input[10];
printf("Enter String with $ at the end\n");
l=getchar();
E();
if(l=='$')
{
printf("\nParsing Successful\n");
}
else
{
printf("Invalid Input\n");
}

OUTPUT:
Enter String with $ at the end
i+i$
Parsing Successful

You might also like