473,666 Members | 2,208 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.Plz zz rply soon......
Sep 18 '08 #1
6 24938
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\tent er %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
6531
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
6022
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 paragraphs. So far, so good: some of the paragraphs begin with a link, and there are styles in the stylesheet for link, hover etc. The first letter is still displayed as styled for the paragraph's first-letter.
7
1917
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 move "Activities" below "Fine Arts", implying the code is not matching exactly the first 3 characters. I've left the code in my testing state for the following questions: 1. How do I specifiy the match to include all 3 characters (not just a...
5
5422
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 getting my compiler to work, access to my a drive is denied, anyone know why this is? Ok here is the info for my program: The two laws of electricity are used in this program. Law #1 The first is Ohm's Law which relates voltage, curret, and...
3
3244
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 FIRST and FOLLOW:
3
1640
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 entropising debate this error is the type of complexity growing belief that changes a simple state transition o -------o to clever decompositions into state sequences
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.