FF Cal
FF Cal
C File: FirstFollow.c
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int count, n = 0;
if (xxx == 1)
continue;
// Calling function
find_first(c, 0, 0);
ptr += 1;
int fs = 0, chk = 0;
if (first[i] == final_first[point1][fs]) {
chk = 1;
break;
}
}
if (chk == 0) {
printf("%c, ", first[i]);
final_first[point1][point2++] = first[i];
}
}
printf("}\n");
jm = n;
point1++;
}
printf("\n");
printf("=================================""\n\n");
char donee[count];
ptr = -1;
if (xxx == 1)
continue;
land += 1;
// Function call
follow(ck);
ptr += 1;
void follow(char c)
{
int i, j;
if (production[i][j + 1] == '\0'
&& c != production[i][0]) {
// Calculate the Follow of thenon-terminal in the L.H.S. of theproduction
follow(production[i][0]);
}
}
}
}
}
}
else if (!isupper(production[j][2])) {
first[n++] = production[j][2];
}
else {
// Recursion to calculate First ofthe new non-terminal we encounterat the beginning
find_first(production[j][2], j, 3);
}
}
}
}
// Including the First set of the non-terminal in the Follow ofthe original query
while (final_first[i][j] != '!') {
if (final_first[i][j] != '#') {
f[m++] = final_first[i][j];
}
else {
if (production[c1][c2] == '\0') {
// The case where we will reach theend of the production
follow(production[c1][0]);
}
else {
// Recursion to the next symbolin case we encounter a "#"
grammarfollow(production[c1][c2], c1,
c2 + 1);
}
21100BTCSE09945 30 ROHIT PATIDAR
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
}
j++;
}
}
}
OUTPUT:
4.6 Results
4.6.1 Test Case: Not required
4.6.2 Result Analysis
4.6.2.1 Advantages
• Determining Predictive Parsing Table: First and Follow sets are essential for
constructing predictive parsing tables. These tables guide the parser to choose the
right production rule based on the current input symbol and the lookahead symbol.
• Efficient Parsing: By using First and Follow sets, predictive parsers can make
parsing decisions without backtracking, leading to more efficient parsing. This
efficiency is especially important in real-time or resource-constrained
environments.
• Error Detection: First and Follow sets help in detecting syntax errors early in the
21100BTCSE09945 31 ROHIT PATIDAR