FIRST:
#include<stdio.h>
#include<ctype.h>
void Find_First(char[], char);
void Array_Manipulation(char[], char);
int limit;
char production[25][25];
int main()
{
char option;
char ch;
char array[25];
int count;
printf("\nEnter Total Number of Productions:\t");
scanf("%d", &limit);
for(count = 0; count < limit; count++)
{
printf("\nValue of Production Number [%d]:\t", count + 1);
scanf("%s", production[count]);
}
do{
printf("\nEnter a Value to Find First:\t");
scanf(" %c", &ch);
Find_First(array, ch);
printf("\nFirst Value of %c:\t{ ", ch);
for(count = 0; array[count] != '\0'; count++)
{
printf(" %c ", array[count]);
}
printf("}\n");
printf("To Continue, Press Y:\t");
scanf(" %c", &option);
}while(option == 'y' || option == 'Y');
return 0;
}
void Find_First(char* array, char ch)
{
int count, j, k;
char temporary_result[20];
int x;
temporary_result[0] = '\0';
array[0] = '\0';
if(!(isupper(ch)))
{
Array_Manipulation(array, ch);
return ;
}
for(count = 0; count < limit; count++)
{
if(production[count][0] == ch)
{
if(production[count][2] == '$')
{
Array_Manipulation(array, '$');
}
else
{
j = 2;
while(production[count][j] != '\0')
{
x = 0;
Find_First(temporary_result, production[count][j]);
for(k = 0; temporary_result[k] != '\0'; k++)
{
Array_Manipulation(array,temporary_result[k]);
}
for(k = 0; temporary_result[k] != '\0'; k++)
{
if(temporary_result[k] == '$')
{
x = 1;
break;
}
}
if(!x)
{break;
}
j++;
}
}
}
}
return;
}
void Array_Manipulation(char array[], char value)
{
int temp;
for(temp = 0; array[temp] != '\0'; temp++)
{
if(array[temp] == value)
{
return;
}
}
array[temp] = value;
array[temp + 1] = '\0';
}
#include<stdio.h>
#include<ctype.h>
void Find_First(char[], char);
void Array_Manipulation(char[], char);
int limit;
char production[25][25];
int main()
{
char option;
char ch;
char array[25];
int count;
printf("\nEnter Total Number of Productions:\t");
scanf("%d", &limit);
for(count = 0; count < limit; count++)
{
printf("\nValue of Production Number [%d]:\t", count + 1);
scanf("%s", production[count]);
}
do{
printf("\nEnter a Value to Find First:\t");
scanf(" %c", &ch);
Find_First(array, ch);
printf("\nFirst Value of %c:\t{ ", ch);
for(count = 0; array[count] != '\0'; count++)
{
printf(" %c ", array[count]);
}
printf("}\n");
printf("To Continue, Press Y:\t");
scanf(" %c", &option);
}while(option == 'y' || option == 'Y');
return 0;
}
void Find_First(char* array, char ch)
{
int count, j, k;
char temporary_result[20];
int x;
temporary_result[0] = '\0';
array[0] = '\0';
if(!(isupper(ch)))
{
Array_Manipulation(array, ch);
return ;
}
for(count = 0; count < limit; count++)
{
if(production[count][0] == ch)
{
if(production[count][2] == '$')
{
Array_Manipulation(array, '$');
}
else
{
j = 2;
while(production[count][j] != '\0')
{
x = 0;
Find_First(temporary_result, production[count][j]);
for(k = 0; temporary_result[k] != '\0'; k++)
{
Array_Manipulation(array,temporary_result[k]);
}
for(k = 0; temporary_result[k] != '\0'; k++)
{
if(temporary_result[k] == '$')
{
x = 1;
break;
}
}
if(!x)
{break;
}
j++;
}
}
}
}
return;
}
void Array_Manipulation(char array[], char value)
{
int temp;
for(temp = 0; array[temp] != '\0'; temp++)
{
if(array[temp] == value)
{
return;
}
}
array[temp] = value;
array[temp + 1] = '\0';
}
FOLLOW:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int limit, x = 0;
char production[10][10], array[10];
void find_first(char ch);
void find_follow(char ch);
void Array_Manipulation(char ch);
int main()
{int count;
char option, ch;
printf("\nEnter Total Number of Productions:\t");
scanf("%d", &limit);
for(count = 0; count < limit; count++)
{
printf("\nValue of Production Number [%d]:\t", count + 1);
scanf("%s", production[count]);
}
do
{
x = 0;
printf("\nEnter production Value to Find Follow:\t");
scanf(" %c", &ch);
find_follow(ch);
printf("\nFollow Value of %c:\t{ ", ch);
for(count = 0; count < x; count++)
{
printf("%c ", array[count]);
}
printf("}\n");
printf("To Continue, Press Y:\t");
scanf(" %c", &option);
}while(option == 'y' || option == 'Y');
return 0;
}
void find_follow(char ch)
{
int i, j;
int length = strlen(production[i]);
if(production[0][0] == ch)
{
Array_Manipulation('$');
}
for(i = 0; i < limit; i++)
{
for(j = 2; j < length; j++)
{
if(production[i][j] == ch)
{
if(production[i][j + 1] != '\0')
{
find_first(production[i][j + 1]);
}
if(production[i][j + 1] == '\0' && ch != production[i][0])
{
find_follow(production[i][0]);
}
}
}
}
}
void find_first(char ch)
{
int i, k;if(!(isupper(ch)))
{
Array_Manipulation(ch);
}
for(k = 0; k < limit; k++)
{
if(production[k][0] == ch)
{
if(production[k][2] == '$')
{
find_follow(production[i][0]);
}
else if(islower(production[k][2]))
{
Array_Manipulation(production[k][2]);
}
else
{
find_first(production[k][2]);
}
}
}
}
void Array_Manipulation(char ch)
{
int count;
for(count = 0; count <= x; count++)
{
if(array[count] == ch)
{
return;
}
}
array[x++] = ch;
}
Comments
Post a Comment