Posts

Showing posts from April, 2024

first and follow

 Ex-6  Write a C program to compute the First and Follow sets for the given Grammar  /* A=aAbA  B=bBaB  A=a  B=b   */      #include<stdio.h>  #include<math.h>  #include<string.h>  #include<ctype.h>  #include<stdlib.h>  int n,m=0,p,i=0,j=0;  char a[10][10],f[10];  void follow(char c);  void first(char c);  int main(){  int i,z;  char c,ch;  printf("Enter the no of prooductions:\n");  scanf("%d",&n);  printf("Enter the productions:\n");  for(i=0;i<n;i++)  scanf("%s%c",a[i],&ch);  do{  m=0;  printf("Enter the elemets whose fisrt & follow is to be found:");  scanf("%c",&c);  first(c);  printf("First(%c)={",c);  for(i=0;i<m;i++)  printf("%c",f[i]);  printf("}\n");  strcpy(f," ");  //flushall();  m=0;  follow(c);  printf("Follow(%c)={",c);...

4. Write a C program to implement the Brute force technique of Top down Parsing.

 #include<stdio.h>   #include<stdlib.h>   #include<string.h>   int A();   char str[15];   int isave,curr_ptr=0;   int main(void)   {   printf("1.S->cAd\n2.A->ab/a\n");   printf("this is parser for the above grammar:\n");   printf("Enter any string:");   scanf("%s",&str);   while(curr_ptr<strlen(str))   {   {   if (str[curr_ptr]=='c')   curr_ptr++;   if (A())  {   curr_ptr++;   if (str[curr_ptr]=='d' && str[curr_ptr+1]=='\0')   {   printf("string is accepted by the grammar");      return 1;   }   else break;   }   else break;   }   //else break;   }   printf("string is not accepted by the grammar");   return 0;   }...