Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Gate compiler design notes for cse

Rating
-
Sold
-
Pages
47
Grade
A+
Uploaded on
06-09-2025
Written in
2025/2026

Gate compiler design notes for cse

Institution
Course

Content preview

Department of Computer Science & Engineering



COMPILER DESIGN

LAB MANUAL

, COMPILER DESIGN LAB SYLLABUS


Sl. No. List of Experiments Page No.

1 Design a lexical analyzer for given language and the lexical analyzer should ignore
redundant spaces, tabs and new lines. It should also ignore comments. Although the
1
syntax specification states that identifiers can be arbitrarily long, you may restrict the
length to some reasonable value. Simulate the same in C language.
2
Write a C program to identify whether a given line is a comment or not. 4

3
Write a C program to recognize strings under 'a', 'a*b+', 'abb'. 5

4
Write a C program to test whether a given identifier is valid or not. 8

5
Write a C program to simulate lexical analyzer for validating operators. 9

6 Write a C program for implementing the functionalities of predictive parser for the mini
11
language.
7 Write a C program for constructing of LL (1) parsing.
14

8 Write a C program for constructing recursive descent parsing.
21

9 Write a C program to implement LALR parsing.
29
10 a) Write a C program to implement operator precedence parsing.
b) Write a C program to implement Program semantic rules to calculate the 36
expression that takes an expression with digits, + and * and computes the value.
11 Convert the BNF rules into Yacc form and write code to generate abstract syntax tree
41
for the mini language specified in Note 1.
12 Write a C program to generate machine code from abstract syntax tree generated by the
parser. The instruction set specified in Note 2 may be considered as the target code.

, EXPERIMENT- 1

OBJECTIVE:
Design a lexical analyzer for given language and the lexical analyzer should ignore redundant spaces, tabs and
new lines. It should also ignore comments. Although the syntax specification states that identifiers can be
arbitrarily long, you may restrict the length to some reasonable value. Simulate the same in C language.
RESOURCE:
Turbo C ++
PROGRAM LOGIC:
1. Read the input Expression
2. Check whether input is alphabet or digits then store it as identifier
3. If the input is is operator store it as symbol
4. Check the input for keywords

PROCEDURE:
Go to debug -> run or press CTRL + F9 to run the program

PROGRAM:
#include<string.h>
#include<ctype.h>
#include<stdio.h>
void keyword(char str[10])
{
if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||strcmp("int",str)==0||str
cmp("float",str)==0||strcmp("char",str)==0||strcmp("double",str)==0||strcmp("static",str)==0||strcmp("switch",str
)==0||strcmp("case",str)==0)
printf("\n%s is a keyword",str);
else
printf("\n%s is an identifier",str);
}
main()
{
FILE *f1,*f2,*f3;
char c,str[10],st1[10];
int num[100],lineno=0,tokenvalue=0,i=0,j=0,k=0;
printf("\nEnter the c program");/*gets(st1);*/
f1=fopen("input","w");
while((c=getchar())!=EOF)
putc(c,f1);
fclose(f1);
f1=fopen("input","r");
f2=fopen("identifier","w");
f3=fopen("specialchar","w");
while((c=getc(f1))!=EOF) {
if(isdigit(c))
{
tokenvalue=c-'0';


1

, c=getc(f1);
while(isdigit(c)) {
tokenvalue*=10+c-'0';
c=getc(f1);
}
num[i++]=tokenvalue;
ungetc(c,f1);
}
else
if(isalpha(c))
{
putc(c,f2);
c=getc(f1);
while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
{
putc(c,f2);
c=getc(f1);
}
putc(' ',f2);
ungetc(c,f1);
}
else
if(c==' '||c=='\t')
printf(" ");
else
if(c=='\n')
lineno++;
else
putc(c,f3);
}
fclose(f2);
fclose(f3);
fclose(f1);
printf("\nThe no's in the program are");
for(j=0;j<i;j++)
printf("%d",num[j]);
printf("\n");
f2=fopen("identifier","r");
k=0;
printf("The keywords and identifiersare:");
while((c=getc(f2))!=EOF) {
if(c!=' ')
str[k++]=c;
else
{
str[k]='\0';
keyword(str);
k=0; }

2

Written for

Institution
Course

Document information

Uploaded on
September 6, 2025
Number of pages
47
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$70.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
skcse

Get to know the seller

Seller avatar
skcse Saloni Kumari
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
7 months
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions