0% found this document useful (0 votes)
11 views4 pages

Shubham Pr 1

Shubham

Uploaded by

Divya Adatiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Shubham Pr 1

Shubham

Uploaded by

Divya Adatiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MARWADI UNIVERSITY

DEPARTMENT OF COMPUTER ENGINEERING


CLASS: TC5 BATCH: A

COMPILER DESIGN
(01CE0714)

2024-2025

STUDENT LAB MANUAL

Shubham Naliyapara 92210103016


MARWADI UNIVERSITY
DEPARTMENT OF COMPUTER ENGINEERING
CLASS: TC5 BATCH: A

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.

Shubham Naliyapara 92210103016


MARWADI UNIVERSITY
DEPARTMENT OF COMPUTER ENGINEERING
CLASS: TC5 BATCH: A

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 "->" */

printf("Enter Number of Productions: ");


scanf("%d", &num);

printf("Enter the grammar as E->E-A:\n");


for (int i = 0; i < num; i++) {
scanf("%s", production[i]);
}

for (int i = 0; i < num; i++) {


printf("\nGRAMMAR: %s", production[i]);
non_terminal = production[i][0];

if (non_terminal == production[i][index]) {
alpha = production[i][index + 1];
printf(" is left recursive.\n");

while (production[i][index] != '\0' && production[i][index] != '|') {


index++;
}

Shubham Naliyapara 92210103016


MARWADI UNIVERSITY
DEPARTMENT OF COMPUTER ENGINEERING
CLASS: TC5 BATCH: A

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:

Shubham Naliyapara 92210103016

You might also like