Calculating the first of a given grammar (without epsilon)

#include<stdio.h>
#include<ctype.h>
int i;
int n;
chat p[25][25];
char c;
char b;
char h;
void first(char c);
void result(char h);

main()
{
printf("Enter the number of production rules\n");
scanf("%d",&c);
for(i=0;i<n;i++)
{
printf("Rule %d:  ",i+1);
scanf("%s",p[i]);
}
printf("Enter the non terminal for which first should be calculated\n");
scanf("%s",&c);
first(c);
}

void first(char c)
{
b=c;
for(i=0;i<n;i++)
{
if(p[i][0]==b)
{
if(p[i][2]>64 && p[i][2]<97)
{
first(p[i][2]);
}
if(p[i][2]>96 && p[i][2]<122)
{
result(p[i][2]);
}
}
}
}

void result(char c)
{
h=b;
printf("The first of the non terminal  %s is : %s",c,p[i][2]);
}

Comments

Popular posts from this blog

A program to find FIRST of non-terminals of the given grammar

Desk Calculator

Write a context free grammar for structure of a english sentence, where a pronoun is followed by a verb and verb is followed by determiner. Determiner is followed by noun and noun can be followed by noun. Statement can begin with noun or a proper noun. **following program is written for example sentence"I prefer a morning flight from New Delhi".