compiler design lab manual programs JNTU university CSE departments - Code

Latest

programs

Wednesday, October 5, 2011

compiler design lab manual programs JNTU university CSE departments


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int A();
void disp();
void error();
char s[20];
int i;
void main()
{
clrscr();
printf("S -> cAd\n");
printf("A -> ab/a\n");
printf("Enter the String:\n");
scanf("%s",&s);
i=0;
if(s[i++]=='c'&&A())
{
if(s[++i]=='d'&&s[i+1]==NULL)
disp();
else
error();
}
else
error();
}
int A()
{
if(s[i++]=='a'&&s[i]=='b')
return(1);
else if(s[--i]=='a')
return(1);
else
return(0);
}
void disp()
{
printf("\nstring is valid\n");
getch();
exit(0);
}
void error()
{
printf("\nstring is invalid\n");
getch();
exit(0);
}

No comments:

Post a Comment