Shubham Pr 1
Shubham Pr 1
COMPILER DESIGN
(01CE0714)
2024-2025
INDEX
Sr.
Title Date Grade Sign
No.
Write a C Program to remove Left Recursion
1
from grammar
Write a C Program to remove Left Factoring
2 from grammar
Write a C program to implement finite automata
3 and string validation.
Prepare report for Lex and install Lex on
4 Linux/Windows
(a) WALEx Program to count words, characters,
lines, Vowels and consonants from given input
5
(b) WALEx Program to generate string which is
ending with zeros.
(a) WALex Program to generate Histogram of
words
6
(b) WALex Program to remove single or multi
line comments from C program.
WALex Program to check weather given
7
statement is compound or simple.
WALex Program to extract HTML tags
8 from .html file.
Write a C Program to compute FIRST Set of the
9 given grammar
Write a C Program to compute FOLLOW Set of
10 the given grammar
Write a C Program to implement Operator
11 precedence parser
Write a C Program for constructing LL (1)
12
parsing
Write a C program to implement SLR parsing
13
Prepare a report on YACC and generate
14 Calculator Program using
YACC.
Practical 1
Title: Write a C Program to remove Left Recursion from the grammar.
Hint: A Grammar G (V, T, P, S) is left recursive if it has a production in theform. A
→ A α |β. The above Grammar is left recursive because the left of production is
occurringatafirst position on the right side of production.
Solution: It can eliminate left recursion by replacing a pair of production withA →
βA′ A → αA′|ϵ
Program :
#include <stdio.h>
#include <string.h>
#define SIZE 10
int main() {
char non_terminal;
char beta, alpha;
int num;
char production[10][SIZE];
int index = 3; /* starting of the string following "->" */
if (non_terminal == production[i][index]) {
alpha = production[i][index + 1];
printf(" is left recursive.\n");
if (production[i][index] != '\0') {
beta = production[i][index + 1];
printf("Grammar without left recursion:\n");
printf("%c->%c%c\'", non_terminal, beta, non_terminal);
printf("\n%c\'->%c%c\'|E\n", non_terminal, alpha, non_terminal);
} else {
printf(" can't be reduced\n");
}
} else {
printf(" is not left recursive.\n");
}
index = 3;
}
return 0;
}
Output: