473,507 Members | 9,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

First and follow

1 New Member
hey i am a student and i want a C program to compute the first and follow of any given productions.Plzzz rply soon......
Sep 18 '08 #1
6 24920
weaknessforcats
9,208 Recognized Expert Moderator Expert
Please read the posting guidelines.

I can help with specific programming and design issues but I cannot provide complete solutions or act as a tutor.
Sep 18 '08 #2
JosAH
11,448 Recognized Expert MVP
Since you're repeating your previous question, I repeat my question to you:
do you know how to compute the first and follow sets given a grammar?

kind regards,

Jos
Sep 18 '08 #3
curiously enough
79 New Member
"i want a C program to compute the first and follow of any given productions."
say what?
Sep 18 '08 #4
donbock
2,426 Recognized Expert Top Contributor
"i want a C program to compute the first and follow of any given productions."
say what?
Finding the first and follow sets of a given grammar are things you would have to do if you were writing your own lex or flex.
Sep 18 '08 #5
JosAH
11,448 Recognized Expert MVP
Finding the first and follow sets of a given grammar are things you would have to do if you were writing your own lex or flex.
Make that 'yacc' or 'bison' etc. Lex and flex use a simple NFA ---> DFA construct
(Non - Deterministic Finite Automaton) to build their lexical analyzer tables.

kind regards,

Jos
Sep 19 '08 #6
nirjhor003
1 New Member
#include<stdio.h>
#include<ctype.h>
char a[8][8];
int n=5 ;
struct firTab
{
int n;
char firT[5];
};
struct folTab
{
int n;
char folT[5];
};
struct folTab follow[5];
struct firTab first[5];
int col;
void findFirst(char,char);
void findFollow(char,char);
void folTabOperation(char,char);
void firTabOperation(char,char);
void main()
{
int i,j,c=0,cnt=0;
char ip;
char b[8];
printf("\n\t\t======FIRST AND FOLLOW SET====== \n\nEnter Production Amount : ");
scanf("%d",&n);
printf("\n\tenter %d productions in format E->T+G\n",n);
printf("\t------------------------------------\n");
for(i=0; i<n; i++)
{
scanf("%s",&a[i]);
}
for(i=0; i<n; i++)
{
c=0;
for(j=0; j<i+1; j++)
{
if(a[i][0] == b[j])
{
c=1;
break;
}
}
if(c !=1)
{
b[cnt] = a[i][0];
cnt++;
}

}
printf("\n");

for(i=0; i<cnt; i++)
{
col=1;
first[i].firT[0] = b[i];
first[i].n=0;
findFirst(b[i],i);
}
for(i=0; i<cnt; i++)
{
col=1;
follow[i].folT[0] = b[i];
follow[i].n=0;
findFollow(b[i],i);
}

printf("\n");
for(i=0; i<cnt; i++)
{
for(j=0; j<=first[i].n; j++)
{
if(j==0)
{
printf("First(%c) : {",first[i].firT[j]);
}
else
{
printf(" %c",first[i].firT[j]);
}
}
printf(" } ");
printf("\n");
}
printf("\n");
for(i=0; i<cnt; i++)
{
for(j=0; j<=follow[i].n; j++)
{
if(j==0)
{
printf("Follow(%c) : {",follow[i].folT[j]);
}
else
{
printf(" %c",follow[i].folT[j]);
}
}
printf(" } ");

printf("\n");
}

}
void findFirst(char ip,char pos)
{
int i;
for(i=0; i<n; i++)
{
if(ip == a[i][0])
{
if(isupper(a[i][3]))
{
findFirst(a[i][3],pos);
}
else
{

first[pos].firT[col]=a[i][3];
first[pos].n++;
col++;
}
}
}
}
void findFollow(char ip,char row)
{
int i,j;
if(row==0 && col==1)
{
follow[row].folT[col]= '$';
col++;
follow[row].n++;
}
for(i=0; i<n; i++)
{
for(j=3; j<7; j++)
{
if(a[i][j] == ip)
{
if(a[i][j+1] == '\0')
{
if(a[i][j] != a[i][0])
{
folTabOperation(a[i][0],row);
}
}
else if(isupper(a[i][j+1]))
{
if(a[i][j+1] != a[i][0])
{
firTabOperation(a[i][j+1],row);

}
}
else
{
follow[row].folT[col] = a[i][j+1];
col++;
follow[row].n++;


}
}
}
}
}
void folTabOperation(char ip,char row)
{
int i,j;
for(i=0; i<5; i++)
{
if(ip == follow[i].folT[0])
{
for(j=1; j<=follow[i].n; j++)
{
follow[row].folT[col] = follow[i].folT[j];
col++;
follow[row].n++;
}
}
}
}
void firTabOperation(char ip,char row)
{
int i,j;
for(i=0; i<5; i++)
{
if(ip == first[i].firT[0])
{
for(j=1; j<=first[i].n; j++)
{
if(first[i].firT[j] != '0')
{
follow[row].folT[col] = first[i].firT[j];
follow[row].n++;
col++;
}
else
{
folTabOperation(ip,row);
}
}
}
}

}
Jul 17 '16 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6524
by: Nobody | last post by:
Does anyone have some python code snippets for finding First() and Follow() sets of an LL(1) grammar handy? Thanks
12
6005
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
7
1908
by: Matt L. | last post by:
In summary, I don't know how/why the following code works and would like to know. I'm trying to match the first 3 characters of a variable (filename). The code below crudely works, but only if I...
5
5406
by: cj | last post by:
Thanks to everyone that has helped me. Now I'm trying to write my first program. I have an example of one that I need to write about. Any help getting me started is appreciated. I'm having trouble...
3
3236
by: Rizvi | last post by:
The Grammer is given: S ---> id=E; E ---> E+T | E-T | T T ---> T*F | T/F | F F ---> P^F | P P ---> -P | L L ---> (E) | id | num -------------------------------- I've fond the following...
3
1632
by: galathaea | last post by:
it surprises me how often engineers confuse states with actions i think this is the fundamental reification behind procedural statemess and this mistake infects a lot of great projects with...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.