Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 2

#include<iostream>

#include<string>
#include<string.h>
using namespace std;

// recursive descent for thsi grammer


/*
E->TE'
E'->+TE'|NULL
T->FT'
T'->*FT'|NULL
F->(E)|a
*/

// input string a+a*a


/**/

void E();
void T();
void F();
void Eds();
void Tds();
int i,error;
char input[100];
int main(){

cout<<"Enter the input string"<<endl;


cin>>input;
E();
if(i==strlen(input) && error==0)
{
cout<<"string accepted succesfully"<<endl;
}
else{
cout<<"rejected"<<endl;
}
return 0;
}

void E()
{
T();
Eds();
}

void T()
{
F();
Tds();
}
void Eds()
{
if(input[i]=='+')
{
i++;
T();
Eds();
}
}

void Tds()
{
if(input[i]=='*')
{
i++;
F();
Tds();
}

void F()
{

if(input[i]=='a')
{
i++;
}
else if(input[i]=='(')
{
i++;
E();
if(input[i]==')')
{
i++;
}
else{
error=1;
}
}

else{
error=1;
}
}

You might also like