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......
6 24938
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.
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
"i want a C program to compute the first and follow of any given productions."
say what?
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.
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
#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);
}
}
}
}
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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.
|
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...
|
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...
|
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:
| |
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
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |