0% found this document useful (0 votes)
1K views

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy