CS8602 CD Mini Project Report 2017
CS8602 CD Mini Project Report 2017
Complier Design
Create Frameworks For Syntax Directed Translation Schemes, Type Checking And
Intermediate Code Generation..
Mrs.K.AMSAVALLI AP/CSE
Submitted by:
NAME: Mythili
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.
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:
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.