0% found this document useful (0 votes)
307 views

CS8602 CD Mini Project Report 2017

The document describes a mini project report on compiler design. It discusses implementing syntax directed translation schemes, type checking, and intermediate code generation. The project involves creating a grammar for expressions with addition and multiplication and augmenting it with syntax directed translation rules to evaluate expressions and check for semantic errors. The program code provided generates intermediate code by identifying operators in an input expression and outputting expressions of the form "variable := left_operand operator right_operand".

Uploaded by

addssdfa
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views

CS8602 CD Mini Project Report 2017

The document describes a mini project report on compiler design. It discusses implementing syntax directed translation schemes, type checking, and intermediate code generation. The project involves creating a grammar for expressions with addition and multiplication and augmenting it with syntax directed translation rules to evaluate expressions and check for semantic errors. The program code provided generates intermediate code by identifying operators in an input expression and outputting expressions of the form "variable := left_operand operator right_operand".

Uploaded by

addssdfa
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

ANAND INSTITUTE OF HIGHER TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

ACADEMIC YEAR: 2019-2020

MINI PROJECT REPORT

Complier Design
Create Frameworks For Syntax Directed Translation Schemes, Type Checking And
Intermediate Code Generation..

Supervised by: Marks: 21/25

Mrs.K.AMSAVALLI AP/CSE

Submitted by:

NAME: Mythili

YEAR : III CSE


Create Frameworks For Syntax Directed Translation Schemes, Type Checking And
Intermediate Code Generation..

TABLE OF CONTENTS

1. ABSTARCT

2. INTRODUCTION

3. SOFTWARE DESCRIPTION

4. HARDWARE DESCRIPTION

7. PROGRAM

8. SCREEN SHOTS

9. CONCLUSION
ABSTRACT:

Syntax Directed Translation are augmented rules to the grammar that facilitate semantic
analysis. SDT involves passing information bottom-up and/or top-down the parse tree in form of
attributes attached to the nodes. Syntax directed translation rules use lexical values of nodes,
constants and attributes associated to the non-terminals in their definitions. The general approach
to Syntax-Directed Translation is to construct a parse tree or syntax tree and compute the values
of attributes at the nodes of the tree by visiting them in some order. In many cases, translation
can be done during parsing without building an explicit tree.

INTRODUCTION:
This is a grammar to syntactically validate an expression having additions and multiplications in
it. Now, to carry out semantic analysis we will augment SDT rules to this grammar, in order to
pass some information up the parse tree and check for semantic errors, if any. In this example we
will focus on evaluation of the given expression, as we don’t have any semantic assertions to
check in this very basic.

E -> E+T { E.val = E.val + T.val } PR#1


E -> T { E.val = T.val } PR#2
T -> T*F { T.val = T.val * F.val } PR#3
T -> F { T.val = F.val } PR#4
F -> INTLIT { F.val = INTLIT.lexval } PR#5
For understanding translation rules further, we take the first SDT augmented to [ E -> E+T ]
production rule. The translation rule in consideration has val as attribute for both the non-
terminals – E & T. Right hand side of the translation rule corresponds to attribute values of right
side nodes of the production rule and vice-versa. Generalizing, SDT are augmented rules to a
CFG that associate 1) set of attributes to every node of the grammar and 2) set of translation
rules to every production rule using attributes, constants and lexical values.

SOFTWARE REQUIREMENTS:

 Turbo C
 Web Browser: Microsoft Internet Explorer, Mozilla, Google Chrome or later
 MySQL Server (back-end)
 Operating System: Windows XP / Windows7/ Windows Vista

HARDWARE REQUIREMENTS:

Processor: Intel Core Processor Or Better Performance

Memory 1gb Ram Or more Hard Disk space minimum 3 Gb for database usage for future

PROGRAM:

program:

#include"stdio.h"
#include"conio.h"
#include"string.h"
inti=1,j=0,no=0,tmpch=90;
charstr[100],left[15],right[15];
voidfindopr();
voidexplore();
voidfleft(int);
voidfright(int);
structexp
{
intpos;
charop;
}k[15];
voidmain()
{
clrscr();
printf("\t\tINTERMEDIATE CODE GENERATION\n\n");
printf("Enter the Expression :");
scanf("%s",str);
printf("The intermediate code:\t\tExpression\n");
findopr();
explore();
getch();
}
void findopr()
{
for(i=0;str[i]!='\0';i++)
if(str[i]==':')
{
k[j].pos=i;
k[j++].op=':';
}
for(i=0;str[i]!='\0';i++)
if(str[i]=='/')
{
k[j].pos=i;
k[j++].op='/';
}
for(i=0;str[i]!='\0';i++)
if(str[i]=='*')
{
k[j].pos=i;
k[j++].op='*';
}
for(i=0;str[i]!='\0';i++)
if(str[i]=='+')
{
k[j].pos=i;
k[j++].op='+';
}
for(i=0;str[i]!='\0';i++)
if(str[i]=='-')
{
k[j].pos=i;
k[j++].op='-';
}
}
void explore()
{
i=1;
while(k[i].op!='\0')
{
fleft(k[i].pos);
fright(k[i].pos);
str[k[i].pos]=tmpch--;
printf("\t%c := %s%c%s\t\t",str[k[i].pos],left,k[i].op,right);
for(j=0;j <strlen(str);j++)
if(str[j]!='$')
printf("%c",str[j]);
printf("\n");
i++;
}
fright(-1);
if(no==0)
{
fleft(strlen(str));
printf("\t%s := %s",right,left);
getch();
exit(0);
}
printf("\t%s :=  %c",right,str[k[--i].pos]);
getch();
}
void fleft(int x)
{
int w=0,flag=0;
x--;
while(x!= -1 &&str[x]!= '+' &&str[x]!='*'&&str[x]!='='&&str[x]!='\0'&&str[x]!='-'&&str[x]!
='/'&&str[x]!=':')
{
if(str[x]!='$'&& flag==0)
{
left[w++]=str[x];
left[w]='\0';
str[x]='$';
flag=1;
}
x--;
}
}
void fright(int x)
{
int w=0,flag=0;
x++;
while(x!= -1 && str[x]!= '+'&&str[x]!='*'&&str[x]!='\0'&&str[x]!='='&&str[x]!=':'&&str[x]!
='-'&&str[x]!='/')
{
if(str[x]!='$'&& flag==0)
{
right[w++]=str[x];
right[w]='\0';
str[x]='$';
flag=1;
}
x++;
}
}

SCREENSHOTS:
CONCLUSION:

A variable or procedure has to be declared before it can be used. Declaration involves allocation
of space in memory and entry of type and name in the symbol table. A program may be coded
and designed keeping the target machine structure in mind, but it may not always be possible to
accurately convert a source code to its target language. Taking the whole program as a
collection of procedures and sub-procedures, it becomes possible to declare all the names local
to the procedure. Memory allocation is done in a consecutive manner and names are allocated to
memory in the sequence they are declared in the program. We use offset variable and set it to
zero {offset = 0} that denote the base address. The source programming language and the target
machine architecture may vary in the way names are stored, so relative addressing is used.
While the first name is allocated memory starting from the memory location 0 {offset=0}, the
next name declared later, should be allocated memory next to the first one.

You might also like