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

CSE B3 Compiler Lab

top down approach

Uploaded by

vidita
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)
14 views2 pages

CSE B3 Compiler Lab

top down approach

Uploaded by

vidita
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

#include<stdio.

h>
#include<string.h>
int i=0,f=0;
char str[30];

void E();
void Eprime();
void T();
void Tprime();
void F();

void E()
{
printf("\nE->TE'");
T();
Eprime();
}

void Eprime()
{
if(str[i]=='+')
{
printf("\nE'->+TE'");
i++;
T();
Eprime();
}
else if((str[i]==')')||(str[i]=='$'))
printf("\nE'->^");

void T()
{
printf("\nT->FT'");
F();
Tprime();
}

void Tprime()
{
if(str[i]=='*')
{
printf("\nT'->*FT'");
i++;
F();
Tprime();
}

else if((str[i]==')')||(str[i]=='+')||(str[i]=='$'))
{
printf("\nT'->^");
}
}

void F()
{
if(str[i]=='a')
{
printf("\nF->a");
i++;
}

else if(str[i]=='(')
{
printf("\nF->(E)");
i++;
E();
if(str[i]==')')
i++;
}
else
f=1;
}

void main()
{
int len;
printf("enter the str : ");
scanf("%s",str);
len=strlen(str);
str[len]='$';
E();
if((str[i]=='$')&&(f==0))
printf("\nstring sucessfully parsed!");
else
printf("\nsyntax Error!");
}

You might also like