0% found this document useful (0 votes)
913 views2 pages

Write A C Program To Implement A Recursive Descent Parser.

This C program implements a recursive descent parser to parse simple expressions containing 'i' and '+i' terminals. The program takes user input, calls the E() function which calls EDash() if it encounters an 'i', EDash() recursively calls itself if it finds a '+i' looking for more terms or returns if not, and the program returns success if the end terminal '$' is found or error if invalid.

Uploaded by

Prasanna Latha
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
913 views2 pages

Write A C Program To Implement A Recursive Descent Parser.

This C program implements a recursive descent parser to parse simple expressions containing 'i' and '+i' terminals. The program takes user input, calls the E() function which calls EDash() if it encounters an 'i', EDash() recursively calls itself if it finds a '+i' looking for more terms or returns if not, and the program returns success if the end terminal '$' is found or error if invalid.

Uploaded by

Prasanna Latha
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 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