Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
2 views
2 pages
assignment2 compiler lab
Uploaded by
Filza Zarqa
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
Download now
Download
Save assignment2 compiler lab For Later
Download
Save
Save assignment2 compiler lab For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
2 views
2 pages
assignment2 compiler lab
Uploaded by
Filza Zarqa
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
Download now
Download
Save assignment2 compiler lab For Later
Carousel Previous
Carousel Next
Download
Save
Save assignment2 compiler lab For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 2
Search
Fullscreen
ASSIGNMENT-2
Write a C program to remove left recursion from a given grammar.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void removeLeftRecursion(char nonTerminal, char alpha[], char
beta[])
{
char newNonTerminal = nonTerminal + ('a' - 'A');
printf("\nTransformed Grammar:\n");
printf("%c -> %s%c'\n", nonTerminal, beta, newNonTerminal);
printf("%c' -> %s%c' | ε\n", newNonTerminal, alpha,
newNonTerminal);
}
int main()
{
char input[100], nonTerminal, alpha[50], beta[50];
printf("Enter a grammar rule (Format: A -> Aα | β):\n");
fgets(input, sizeof(input), stdin);
sscanf(input, "%c -> %[^|] | %[^\n]", &nonTerminal, alpha,
beta);
if (alpha[0] == nonTerminal)
{
removeLeftRecursion(nonTerminal, alpha + 1, beta);
}
else
{
printf("\nNo Left Recursion Detected.\nOriginal Grammar:
%s", input);
}
Zarqa Gulrez(22310237)
return 0;
}
Output:
Zarqa Gulrez(22310237)
You might also like
Lecture - 6 Left Recursion
PDF
No ratings yet
Lecture - 6 Left Recursion
8 pages
CSE2002_Session21_TopDownParsingSession2
PDF
No ratings yet
CSE2002_Session21_TopDownParsingSession2
23 pages
3025-CD
PDF
No ratings yet
3025-CD
26 pages
6.LAB_MANUAL_SS
PDF
No ratings yet
6.LAB_MANUAL_SS
16 pages
CD - Lab Manual - Classroom
PDF
No ratings yet
CD - Lab Manual - Classroom
18 pages
Practicals - 1-11 - Sudarshan - 91900103137
PDF
No ratings yet
Practicals - 1-11 - Sudarshan - 91900103137
23 pages
Compiler Presentation[Group 1]
PDF
No ratings yet
Compiler Presentation[Group 1]
15 pages
CC lab 1-4
PDF
No ratings yet
CC lab 1-4
13 pages
Department of Information Technology System Software Lab: 1. Write Source Code For Recursive Descent Parsing
PDF
No ratings yet
Department of Information Technology System Software Lab: 1. Write Source Code For Recursive Descent Parsing
11 pages
Practical 4 to 6 cd (1)
PDF
No ratings yet
Practical 4 to 6 cd (1)
18 pages
SP Ait LM
PDF
No ratings yet
SP Ait LM
19 pages
Sarthak - 13th July
PDF
No ratings yet
Sarthak - 13th July
12 pages
Lecture 05-b
PDF
No ratings yet
Lecture 05-b
17 pages
Practical 01: Aim: Write A Program To Create, Read and Write Into A File. Code
PDF
No ratings yet
Practical 01: Aim: Write A Program To Create, Read and Write Into A File. Code
15 pages
Practical-6_TO_10[2]
PDF
No ratings yet
Practical-6_TO_10[2]
19 pages
Shubham Pr 1
PDF
No ratings yet
Shubham Pr 1
4 pages
CD Lab Manual
PDF
No ratings yet
CD Lab Manual
7 pages
Compiler design file part 2
PDF
No ratings yet
Compiler design file part 2
4 pages
Experiment 1: D I T C: Tt1 Batch: B
PDF
No ratings yet
Experiment 1: D I T C: Tt1 Batch: B
10 pages
Compiler_Top downCompiler
PDF
No ratings yet
Compiler_Top downCompiler
6 pages
CD 5
PDF
No ratings yet
CD 5
4 pages
UNIT-2-1-RD-Parser
PDF
No ratings yet
UNIT-2-1-RD-Parser
27 pages
Implementation of Shift Reduce Parsing Algorithm: Action
PDF
No ratings yet
Implementation of Shift Reduce Parsing Algorithm: Action
22 pages
Left Recursion Removal
PDF
No ratings yet
Left Recursion Removal
11 pages
Lec 09-Left Recursion Removal
PDF
No ratings yet
Lec 09-Left Recursion Removal
23 pages
program-2
PDF
No ratings yet
program-2
5 pages
Lesson 18
PDF
No ratings yet
Lesson 18
32 pages
Module 2
PDF
No ratings yet
Module 2
36 pages
Elliminating Left Rec - Fact
PDF
No ratings yet
Elliminating Left Rec - Fact
5 pages
Compiler Design Record (21072)
PDF
No ratings yet
Compiler Design Record (21072)
48 pages
Ex 8
PDF
No ratings yet
Ex 8
1 page
1aad0d4e-5819-4498-90a5-fe2c5d44181c
PDF
No ratings yet
1aad0d4e-5819-4498-90a5-fe2c5d44181c
2 pages
Compilation_Lab_Sheet_7
PDF
No ratings yet
Compilation_Lab_Sheet_7
3 pages
1aad0d4e-5819-4498-90a5-fe2c5d44181c
PDF
No ratings yet
1aad0d4e-5819-4498-90a5-fe2c5d44181c
2 pages
516
PDF
No ratings yet
516
4 pages
CIS524Summer2022-HW4
PDF
No ratings yet
CIS524Summer2022-HW4
3 pages
Compiler Design Unit 2
PDF
No ratings yet
Compiler Design Unit 2
84 pages
Syntax Analysis
PDF
No ratings yet
Syntax Analysis
47 pages
R20_CD_LAB2
PDF
No ratings yet
R20_CD_LAB2
33 pages
Ex 8
PDF
No ratings yet
Ex 8
1 page
exp7spcc
PDF
No ratings yet
exp7spcc
12 pages
Compiler Lab A
PDF
No ratings yet
Compiler Lab A
3 pages
Shubham Pr 2
PDF
No ratings yet
Shubham Pr 2
2 pages
Ex 7
PDF
No ratings yet
Ex 7
1 page
Exp 3
PDF
No ratings yet
Exp 3
1 page
Experiment-7 //WAP To Check Whether A Grammar Is Left Recursive or Not, If So Remove It
PDF
No ratings yet
Experiment-7 //WAP To Check Whether A Grammar Is Left Recursive or Not, If So Remove It
2 pages
Chapter 4 - C (Syntax Free Grammar)
PDF
No ratings yet
Chapter 4 - C (Syntax Free Grammar)
11 pages
2K19 - CO - 378 SIDHANT JAIN - Program-2
PDF
No ratings yet
2K19 - CO - 378 SIDHANT JAIN - Program-2
1 page
Left Recursion
PDF
No ratings yet
Left Recursion
1 page
123
PDF
No ratings yet
123
1 page
Cycle Test - I Solution
PDF
No ratings yet
Cycle Test - I Solution
7 pages
LL (1) Parser
PDF
No ratings yet
LL (1) Parser
4 pages
Compiler Design Exp. File (1-5)
PDF
No ratings yet
Compiler Design Exp. File (1-5)
18 pages
Left Recursion
PDF
No ratings yet
Left Recursion
11 pages
What Is Left Recursion and How It Is Eliminated?: Compiler Design Programming Languages Computer Programming
PDF
No ratings yet
What Is Left Recursion and How It Is Eliminated?: Compiler Design Programming Languages Computer Programming
5 pages
Chapter 2 - Left Recursive
PDF
No ratings yet
Chapter 2 - Left Recursive
10 pages
Left Recursion and Elimination
PDF
No ratings yet
Left Recursion and Elimination
4 pages
LRec 1011
PDF
No ratings yet
LRec 1011
2 pages
C Language Programming Codes
From Everand
C Language Programming Codes
Durgesh
No ratings yet
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
Karan Bhandari
No ratings yet