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

System Software Lab Prog

This document describes the implementation of the second pass of a two-pass assembler. It takes the output of the first pass assembler, which includes labels and their addresses, and generates an absolute listing by replacing symbolic addresses with numeric values from the symbol table. It handles different instruction types, outputting operands in hexadecimal for BYTE instructions, decimal for WORD, and just printing other instruction types. It determines operation codes and their numeric codes by searching an operation code table.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

System Software Lab Prog

This document describes the implementation of the second pass of a two-pass assembler. It takes the output of the first pass assembler, which includes labels and their addresses, and generates an absolute listing by replacing symbolic addresses with numeric values from the symbol table. It handles different instruction types, outputting operands in hexadecimal for BYTE instructions, decimal for WORD, and just printing other instruction types. It determines operation codes and their numeric codes by searching an operation code table.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

LENGTH OF MACRO

Program code:3

REG NO:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int l;
char s[25];
FILE *fp;
clrscr();
fp=fopen("macro.dat","w");
do
{
printf("\n enter the macro instuction:");
gets(s);
fwrite(&s,sizeof(s),1,fp);
}
while(strcmp(s,"mend")!=0);
l=-1;
fclose(fp);
fp=fopen("macro.dat","r");
fread(&s,sizeof(s),1,fp);
while(!feof(fp))
{
if(strcmp(s,"mend")!=0)
l++;
else
break;
fread(&s,sizeof(s),1,fp);
}
printf("the length(no of lines)of macro:%d",l);
fclose(fp);
getch();
}
OUTPUT
enter the macro instuction:macro
enter the macro instuction:add a
enter the macro instuction:add b
enter the macro instuction:sta c
enter the macro instuction:mend
the length(no of lines)of macro:3
-

IMPLEMENTATION OF SYMBOL TABLE


Program code:2

REG NO:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
int i=0;
FILE *fp;
void create();
void insert();
void display();
void search();
void modify();
struct symbol
{
char name[20];
int val;
}s[10];
void main()
{
int ch;
clrscr();
do
{
printf("\n1.create\n2.insert\n3.modify\n4.search\n5.display");
printf("\nenter ur choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
break;
case 2:
insert();
break;
case 3:
modify();
break;
case 4:
search();
break;
case 5:
display();
break;
default:
printf("\ninvalid choice");
}
}while(ch<6);
}
void create()
{

char c;
i=0;
fp=fopen("symbol.txt","w");
do
{
printf("\n\tenter the symbol name\t");
scanf("%s",&s[i].name);
fflush(stdin);
printf("\n\t\tenter the value\t");
scanf("%d",&s[i].val);
fwrite(&s[i],sizeof(s[i]),1,fp);
i++;
printf("\ndo u want to continue\t");
fflush(stdin);
c=getchar();
}
while(c=='y');
fclose(fp);
}
void insert()
{
char c;
fp=fopen("symbol.txt","a");
do
{
printf("\n\tenter the symbol name");
scanf("%s",s[i].name);
fflush(stdin);
printf("\n\tenter the value\t");
scanf("%d",&s[i].val);
fwrite(&s[i],sizeof(s[i]),1,fp);
i++;
printf("\ndo u want to continue\t");
fflush(stdin);
c=getchar();
}
while(c=='y');
fclose(fp);
}
void search()
{
char a[10];
int flag=0;
fp=fopen("symbol.txt","r");
printf("\n\tenter the symbol\t\t");
scanf("%s",a);
i=0;
fread(&s[i],sizeof(s[i]),1,fp);
while(!feof(fp))
{
if(strcmp(s[i].name,a)==0)
flag=flag+1;

i++;
fread(&s[i],sizeof(s[i]),1,fp);
}
if(flag==0)
{
printf("\n\t\tthe symbol is not found");
}
else
printf("\n\t\tthe symbol is found");
fclose(fp);
}
void display()
{
i=0;
fp=fopen("symbol.txt","r");
fread(&s[i],sizeof(s[i]),1,fp);
while(!feof(fp))
{
printf("\ncontents");
printf("\n\t\tthe name is\t\t%s",s[i].name);
fflush(stdin);
printf("\n\t\tthe value is\t\t%d",s[i].val);
i++;
fread(&s[i],sizeof(s[i]),1,fp);
}
fclose(fp);
}
void modify()
{
char z[20];
int flag=0,i=0;
fp=fopen("symbol.txt","r+");
fread(&s[i],sizeof(s[i]),1,fp);
printf("enter the symbol to modify");
scanf("%s",z);
while(!feof(fp))
{
if(strcmp(z,s[i].name)==0)
{
flag=1;
printf("value to modify");
scanf("%d",&s[i].val);
fseek(fp,ftell(fp)-sizeof(s[i]),0);
fwrite(&s[i],sizeof(s[i]),1,fp);
i++;
}
else
flag=0;
fread(&s[i],sizeof(s[i]),1,fp);
}
fclose(fp);
if(flag==1)

printf("\nthe value is modified");


else
printf("\nthe value is not modified");
}
output
1.create
2.insert
3.modify
4.search
5.display
enter ur choice1
enter the symbol name

enter the value 10


do u want to continue

enter the symbol name

enter the value 20


do u want to continue

1.create
2.insert
3.modify
4.search
5.display
enter ur choice2
enter the symbol namec
enter the value 30
do u want to continue

1.create
2.insert
3.modify
4.search
5.display
enter ur choice5
contents
the name is
the value is

a
10

the name is
the value is

b
20

contents

contents
the name is
the value is

c
30

1.create
2.insert
3.modify
4.search
5.display
enter ur choice3
enter the symbol to modifyb
value to modify240
the value is modified
1.create
2.insert
3.modify
4.search
5.display
enter ur choice5
contents
the name is
the value is
contents
the name is
the value is
contents
the name is
the value is
1.create
2.insert
3.modify
4.search
5.display
enter ur choice 4
enter the symbol

a
10
b
240
c
30

the symbol is found


1.create
2.insert
3.modify
4.search
5.display
enter ur choice4
enter the symbol
x
the symbol is not found
1.create
2.insert
3.modify
4.search
5.display
enter ur choice 6

FILE MANIPULATION (Student Details)


Program code:1

REG NO:

#include<stdio.h>
#include<conio.h>
struct stud
{
char n[25];
int m1,m2,m3,tot;
float avg;
}s[15];
void main()
{
char *g[9];
FILE *fp;
int i,a;
clrscr();
fp=fopen("stud.txt","w");
printf("\t \t STUDENT DETAILS");
printf("\n Enter the Number of Students :
scanf("%d",&a);
for(i=0;i<a;i++)
{
printf("\n Name : ");
scanf("%s",&s[i].n);
printf("\n Mark 1 : ");
scanf("%d",&s[i].m1);
printf("\n Mark 2 : ");
scanf("%d",&s[i].m2);
printf("\n Mark 3 : ");
scanf("%d",&s[i].m3);
s[i].tot=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].tot/3;
printf("\n Total = %d",s[i].tot);
printf("\n\n Average = %f\n",s[i].avg);
printf("\n ------------------");
fwrite(&s[i],sizeof(s[i]),1,fp);
// fflush(stdin);
}

");

printf("\n Details entered...\n\n\n\n");


fclose(fp);
fp=fopen("ip.txt","r");
printf("\n Name \t M1 \t M2 \t M3 \t Total \t Average \t
Grade");
printf("\n---------------------------------------------------------");

for(i=0;i<a;i++)
{
// fread(&s[i],sizeof(s[i]),1,fp);
if(s[i].avg>=80)
{
strcpy(g,"O");
}
else if((s[i].avg>=70)&&(s[i].avg<80))
{
strcpy(g,"A");
}
else if((s[i].avg>=60)&&(s[i].avg<70))
{
strcpy(g,"B");
}
else
{
strcpy(g,"C");
}
printf("\n %s \t %d \t %d \t %d \t %d \t %f \t
%s",s[i].n,s[i].m1,s[i].m2,s[i].m3,s[i].tot,s[i].avg,g);
printf("\n");
}
fclose(fp);
getch();
}
Output:
STUDENT DETAILS
Enter the Number of Students : 3
Name : manu
Mark 1 : 80
Mark 2 : 85
Mark 3 : 90
Total = 255
Average = 85.000000
-----------------Name : gouti
Mark 1 : 88
Mark 2 : 88
Mark 3 : 80
Total = 256
Average = 85.000000
-----------------Name : vino
Mark 1 : 90
Mark 2 : 85
Mark 3 : 80
Total = 255
Average = 85.000000
-----------------Details entered...
Name
M1
M2
M3
Total
Average
Grade
----------------------------------------------------------------90
255
85.000000
O
gouti

88

88

80

256

85.000000

vino

90

85

80

255

85.000000

manu

80

85

IMPLEMENTATION OF PASS1 OF TWO PASS ASSEMBLER


Program code:4

REG NO:

#include<stdio.h>
#include<string.h>
#include<conio.h>
char opcode[10],operand[10],label[10],optab[10];
int locctr,initial,len,fin,temp,mnemonics;
FILE *fp1,*fp2,*fp3,*fp4;
void main()
{
fp1=fopen("input.dat","r");
fp2=fopen("out.dat","r");
fp3=fopen("output.dat","w");
fp4=fopen("symbol.dat","w");
clrscr();
fscanf(fp1,"%s %s %s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
locctr=atoi(operand);
initial=locctr;
fprintf(fp3,"%d\t %s\t %s\t %s\n",locctr,label,opcode,operand);
fscanf(fp1," %s\t %s\t %s\n",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fscanf(fp2,"%s %d\n",optab,mnemonics);
if(strcmp(optab,opcode)==0)
{

locctr=locctr+3;
fprintf(fp3,"%d\t %s\t %s\t %s\n",locctr,label,opcode,operand);
}
else
{
if(strcmp(opcode,"WORD")==0)
{
locctr=locctr+3;
temp=locctr-initial;
fprintf(fp4,"%s\t %d\n",label,locctr);
fprintf(fp3,"%d\t %s\t %s\t %s\n",locctr,label,opcode,operand);
}
else
if(strcmp(opcode,"BYTE")==0)
{
locctr++;
fprintf(fp4,"%s\t %d\n",label,locctr);
fprintf(fp3,"%d\t %s\t %s\t %s\n",locctr,label,opcode,operand);
}
else
if(strcmp(opcode,"RESW")==0)
{
locctr=locctr+(3*atoi(operand));
fprintf(fp4,"%s\t %d\n",label,locctr);
fprintf(fp3,"%s\t %d\n",label,locctr);
}
}
fscanf(fp1,"%s %s %s\n",label,opcode,operand);
}
fprintf(fp3,"%d\t %s\t %s\t %s\n",locctr,label,opcode,operand);

fin=locctr;
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
printf("...output..");
fp3=fopen("output.dat","r");
fscanf(fp3,"%s\t %s\t %s\t %s\n",optab,label,opcode,operand);
do
{
printf("\n %s\t %s\t %s\t %s\n",optab,label,opcode,operand);
fscanf(fp3,"%s %s %s %s\n",optab,label,opcode,operand);
}
while(!feof(fp3));
printf("....symtab...");
fp4=fopen("symbol.dat","r");
fscanf(fp4,"%s %s\n",opcode,operand);
do
{
printf("\n %s\t %s\n",opcode,operand);
fscanf(fp4,"%s %s\n",opcode,operand);
}while(!feof(fp4));
printf("\n %s\t %s\n",opcode,operand);
len=fin-initial;
printf("\n length of the pgm is %d",len);
getch();}

INPUT
Input.dat
** START 2000
** LDA FIVE
** STA ALPHA
** LDCH CHARZ
** STCH C1
ALPHA RESW 1
FIVE WORD 5
CHAR BYTE C'Z'
C1 RESB 1
** END **
Out.dat
**
START 2000
2000 **
LDA
FIVE
2003 **
STA
ALPHA
2006 **
LDCH CHARZ
2009 **
STCH c1
2012 ALPHA RESW 1
2015 FIVE WORD 5
2018 CHARZ BYTE c 'z
2019 c
RESB 1
2020 **
END
**
OUTPUT

Output.dat
LDA 00
STA 0c
LDCH

50

STCH

54

Symbol.dat
ALPHA
FIVE
CHARZ
C1

3012
3015
3018
3019

IMPLEMENTATION OF PASS2 OF TWO PASS ASSEMBLER

Program code:5

REG NO:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
char
a[10],ad[10],label[10],opcode[10],operand[10],mnemonic[10],symbol
[10];
int i,address,code,add,len,actual_len;
FILE *fp1,*fp2,*fp3,*fp4;
clrscr();
fp1=fopen("assmlist.dat","w");
fp2=fopen("symtab.dat","r");
fp3=fopen("out.dat","r");
fp4=fopen("optab.dat","r");
fscanf(fp3,"%s %s %s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
fprintf(fp1,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp3,"%d %s %s %s",&address,label,opcode,operand);
}
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"BYTE")==0)
{
fprintf(fp1,"%d\t%s\t%s\t%s\t",address,label,opcode,operand);
len=strlen(operand);
actual_len=len-3;

for(i=2;i<(actual_len+2);i++)
{
itoa(operand[i],ad,16);
fprintf(fp1,"%s",ad);
}
fprintf(fp1,"\n");
}
else if(strcmp(opcode,"WORD")==0)
{
len=strlen(operand);
itoa(atoi(operand),a,10);
fprintf(fp1,"%d\t%s\t%s\t%s\t00000%s\n",address,label,opcode,oper
and,a);
}
else if((strcmp(opcode,"RESB")==0)||(strcmp(opcode,"RESW")==0))
{
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
}
else
{
rewind(fp4);
fscanf(fp4,"%s %d",mnemonic,&code);
while(strcmp(opcode,mnemonic)!=0)
fscanf(fp4,"%s %d",mnemonic,&code);
if(strcmp(operand,"**")==0)
{
fprintf(fp1,"%d\t%s\t%s\t%s\t%d0000\n",address,label,opcode,opera
nd,code);
}
else
{

rewind(fp2);
fscanf(fp2,"%s%d",symbol,&add);
while(strcmp(operand,symbol)!=0)
{
fscanf(fp2,"%s %d",symbol,&add);
}
fprintf(fp1,"%d\t%s\t%s\t%s\t%d
%d\n",address,label,opcode,operand,code,add);
}
}
fscanf(fp3,"%d\t%s\t%s\t%s",&address,label,opcode,operand);
}
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
printf("finished");
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
getch();
}

INPUT

Symtab.dat
ALPHA 2012
FIVE 2015
CHARZ 2018
C1 2019
Intermediate.dat
**
START 3000
3000
**
LDA
3003
**
STA
3006
**
LDCH
3009
**
STCH
3012
ALPHA RESW
3015
FIVE WORD
3018
CHARZ BYTE
3019
C1
RESB
3019
**
END
Optab.dat
LDA 33
STA 44
LDCH 53
STCH 57

FIVE
ALPHA
CHARZ
C1
1
5
C'EOF'
1
**

OUTPUT
Assmlist.dat
3000
3003
3006
3009
3012
3015
3018
3019
3019

**
START
3000
**
LDA FIVE 33 3015
**
STA ALPHA
44 3012
**
LDCH CHARZ
53 3018
**
STCH C1
57 3019
ALPHA
RESW 1
FIVE WORD 5
000005
CHARZ
BYTE C'EOF'
454f46
C1
RESB 1
**
END **

IMPLEMENTATION OF SINGLE PASS ASSEMBLER


PROGRAM CODE:6

REG NO:

#include<stdio.h>
#include<conio.h>
#include<fcntl.h>
#include<string.h>
struct symbol
{
char name[10];
int address;
}
s[50];
void main()
{
int i=0,locptr=0,t;
FILE *f1,*f2,*f3,*f4;
char *ch,t1[10],t2[10],t3[10],d1[10],d2[10];
clrscr();
f1=fopen("cprogram1.dat","r");
f3=fopen("coutput1.dat","w");
fscanf(f1,"%s\t%s\t%s\t",t1,t2,t3);
if(strcmp(t2,"START")==0)
locptr=atoi(t3);
while(fscanf(f1,"%s\t%s\t%s\t",t1,t2,t3)>0)
{
if(strcmp(t2,"END")==0)
break;
fprintf(f3,"\n%d\t%s\t%s\t%s",locptr,t1,t2,t3);
if(strcmp(t1,"WORD")==0)
{
s[i].address=locptr;
locptr=locptr+1;
}
else if(strcmp(t2,"BYTE")==0)
{
s[i].address=locptr;
locptr=locptr+1;
}
else if(strcmp(t2,"RESW")==0)
{
s[i].address=locptr;
locptr=locptr+(3*atoi(t3));
}
else if(strcmp(t2,"RESB")==0)
{
s[i].address=locptr;
locptr=locptr+(1*atoi(t3));
}
else
{

locptr=locptr+3;
goto jump;
}
strcpy(s[i].name,t1);
i++;
continue;
jump:
f2=fopen("coptab.dat","r");
while(fscanf(f2,"%s\t%s",d1,d2)>0)
{
if(strcmp(t2,d1)==0)
break;
}
fprintf(f3,"\t%s",d2);
for(t=0;t<i;t++)
{
if(strcmp(s[t].name,t3)==0)
{
fprintf(f3,"%d",s[i].address);
break;
}
}
}
f4=fopen("csymtab.dat","w");
for(t=0;t<i;t++)
{
fprintf(f4,"\n %s\t%d",s[t].name,s[t].address);
}
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);
t=open("coutput1.txt",O_RDONLY);
while(read(t,ch,1)>0)
printf("%s",ch);
getch();
}

INPUT
cprogram1.dat
** START 2000
ALPHA RESW 1
FIVE WORD 5
CHARZ BYTE C'EOF'
C1
RESW 1
** LDA
FIVE
** STA
ALPHA
** LDCH CHARZ
** STCH C1
** END **
coptab.dat
LDA 00
STA 30
LDCH 50
STCH 54
END *
OUTPUT
coutput1.txt
2000 ALPHA
2003 FIVE WORD
2006 CHARZ
2007 C1
RESW
2010 **
LDA
2013 **
STA
2016 **
LDCH
2019 **
STCH

RESW 1
5
BYTE C'EOF'
1
FIVE 002003
ALPHA
302000
CHARZ
502006
C1
542007

IMPLEMENTATION OF ABSOLUTE LOADER


PROGRAM CODE:7

REG NO:

# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
char input[10];
int start,length,address;
FILE *fp1,*fp2;
clrscr();
fp1=fopen("input.dat","r");
fp2=fopen("output.dat","w");
fscanf(fp1,"%s",input);
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%d",&start);
fscanf(fp1,"%d",&length);
fscanf(fp1,"%s",input);
}
else if(strcmp(input,"T")==0)
{
fscanf(fp1,"%d",&address);
fscanf(fp1,"%s",input);
fprintf(fp2,"%d\t%c%c\n",address,input[0],input[1]);
fprintf(fp2,"%d\t%c%c\n",(address+1),input[2],input[3]);
fprintf(fp2,"%d\t%c%c\n",(address+2),input[4],input[5]);
address+=3;
fscanf(fp1,"%s",input);
}
else
{
fprintf(fp2,"%d\t%c%c\n",address,input[0],input[1]);
fprintf(fp2,"%d\t%c%c\n",(address+1),input[2],input[3]);
fprintf(fp2,"%d\t%c%c\n",(address+2),input[4],input[5]);
address+=3;
fscanf(fp1,"%s",input);
}
}
fclose(fp1);
fclose(fp2);

printf("FINISHED");
getch();
}
INPUT FILE
INPUT.DAT
H 1000 232
T 1000 142033 483039 102036
T 2000 298300 230000 282030 302015
E
OUTPUT FILE
OUTPUT.DAT
1000 14
1001 20
1002 33
1003 48
1004 30
1005 39
1006 10
1007 20
1008 36
2000 29
2001 83
2002 00
2003 23
2004 00
2005 00
2006 28
2007 20
2008 30
2009 30
2010 20
2011 15

IMPLEMENTATION OF RELOCATABLE LOADER


PROGRAM CODE: 8

REG NO:

# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <stdlib.h>
void main()
{
char add[6],length[10],input[10],binary[12],bitmask[12],relocbit;
int start,inp,len,i,address,opcode,addr,actualadd;
FILE *fp1,*fp2;
clrscr();
printf("Enter the actual starting address : ");
scanf("%d",&start);
fp1=fopen("relinput.dat","r");
fp2=fopen("reloutput.dat","w");
fscanf(fp1,"%s",input);
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%s",add);
fscanf(fp1,"%s",length);
fscanf(fp1,"%s",input);
}
if(strcmp(input,"T")==0)
{
fscanf(fp1,"%d",&address);
fscanf(fp1,"%s",bitmask);
address+=start;
len=strlen(bitmask);
for(i=0;i<len;i++)
{
fscanf(fp1,"%d",&opcode);
fscanf(fp1,"%d",&addr);
relocbit=bitmask[i];
if(relocbit=='0')
actualadd=addr;
else
actualadd=addr+start;
fprintf(fp2,"%d\t%d%d\n",address,opcode,actualadd);
address+=3;
}

fscanf(fp1,"%s",input);
}
}
fclose(fp1);
fclose(fp2);
printf("FINISHED");
getch();
}
INPUT : RELINPUT.DAT
H 1000 200
T 1000 11001 14 1033 48 1039 90 1776 92 1765 57 1765
T 2011 11110 23 1838 43 1979 89 1060 66 1849 99 1477
E 1000
OUTPUT :
Enter the actual starting address :4000
RELOUTPUT.DAT
4000 144033
4003 484039
4006 901776
4009 921765
4012 574765
5011 234838
5014 434979
5017 894060
5020 664849
5023 991477

IMPLEMENTATION OF MACROPROCESSOR(EXPANSION)
PROGRAM CODE: 9

REG NO:

# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <stdlib.h>
struct deftab
{
char lab[10];
char opc[10];
char oper[10];
}d[10];
void main()
{
char label[10],opcode[10],operand[10],newlabel[10],newoperand[10];
char macroname[10];
int i,lines;
FILE *f1,*f2,*f3;
clrscr();
f1=fopen("macin.dat","r");
f2=fopen("macout.dat","w");
f3=fopen("deftab.dat","w");
fscanf(f1,"%s%s%s",label,opcode,operand);
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"MACRO")==0)
{
strcpy(macroname,label);
fscanf(f1,"%s%s%s",label,opcode,operand);
lines=0;
while(strcmp(opcode,"MEND")!=0)
{
fprintf(f3,"%s\t%s\t%s\n",label,opcode,operand);
strcpy(d[lines].lab,label);
strcpy(d[lines].opc,opcode);
strcpy(d[lines].oper,operand);
fscanf(f1,"%s%s%s",label,opcode,operand);
lines++;
}
}
else if(strcmp(opcode,macroname)==0)
{

printf("Lines = %d\n",lines);
for(i=0;i<lines;i++)
{
fprintf(f2,"%s\t%s\t%s\n",d[i].lab,d[i].opc,d[i].oper);
printf("DLAB = %s\nDOPC = %s\nDOPER =
%s\n",d[i].lab,d[i].opc,d[i].oper);
}
}
else
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(f1,"%s%s%s",label,opcode,operand);
}
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fclose(f1);
fclose(f2);
fclose(f3);
printf("FINISHED");
getch();
}
INPUT FILE :
MACIN.DAT
CALC START 1000
SUM MACRO **
** LDA #5
** ADD #10
** STA 2000
** MEND **
** LDA LENGTH
** COMP ZERO
** JEQ LOOP
** SUM **
LENGTH WORD 5
ZERO WORD 0
LOOP SUM **
** END **
OUTPUT FILES :
MACOUT.DAT
CALC START 1000
** LDA LENGTH
** COMP ZERO
** JEQ LOOP
** LDA #5
** ADD #10
** STA 2000
LENGTH WORD 5
ZERO WORD 0
** LDA #5
** ADD #10
** STA 2000
** END **
DEFTAB.DAT
** LDA #5
** ADD #10
** STA 2000

IMPLEMENTATION PASS 1 OF DIRECT LINKING LOADER


PROGRAM CODE:10
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
char w[20],hex[20],locadd[10];
int dh(char a[30])
{
int i2,j2=0,m2=1,h=0,b[20];
for(i2=0;a[i2]!='\0';i2++)
{
switch(a[i2])
{
case '0':
b[j2]=0;
break;
case '1':
b[j2]=1;
break;
case '2':
b[j2]=2;
break;
case '3':
b[j2]=3;
break;
case '4':
b[j2]=4;
break;
case '5':
b[j2]=5;
break;
case '6':
b[j2]=6;
break;
case '7':
b[j2]=7;
break;
case '8':
b[j2]=8;
break;
case '9':
b[j2]=9;
break;
case 'A':
b[j2]=10;
break;
case 'B':
b[j2]=11;
break;

REG NO:

case 'C':
b[j2]=12;
break;
case 'D':
b[j2]=13;
break;
case 'E':
b[j2]=14;
break;
case 'F':
b[j2]=15;
break;
}
j2++;
}
j2--;
for(;j2>=0;j2--)
{
h=h+b[j2]*m2;
m2=m2*16;
}
return h;
}
void hd(int h)
{
int l=0,p2;
while(h>0)
{
p2=h%16;
h=h/16;
switch(p2)
{
case 0:
hex[l]='0';
break;
case 1:
hex[l]='1';
break;
case 2:
hex[l]='2';
break;
case 3:
hex[l]='3';
break;
case 4:
hex[l]='4';
break;
case 5:
hex[l]='5';
break;
case 6:

case
case
case
case
case
case
case
case
case

hex[l]='6';
break;
7:
hex[l]='7';
break;
8:
hex[l]='8';
break;
9:
hex[l]='9';
break;
10:
hex[l]='A';
break;
11:
hex[l]='B';
break;
12:
hex[l]='C';
break;
13:
hex[l]='D';
break;
14:
hex[l]='E';
break;
15:
hex[l]='F';
break;

}
l++;
}
hex[l]='\0';
}
void rev(char a1[20])
{
int d,j1=0,i1;
d=strlen(a1);
for(i1=d-1;i1>=0;i1--)
{
locadd[j1]=a1[i1];
j1++;
}
locadd[j1]='\0';
}
int main()
{
FILE *fp;
char
f1[10],c[10],arr[50][30],pr_name[10],start_add[10],len[10],rel[10
],add[30][30];
int i=0,m=0,t1,t2,k1,t3,p=0;

printf("Enter the loadtime address:");


scanf("%s",rel);
fp=fopen("dy1file.c","r");
fscanf(fp,"%s",c);
while(!feof(fp))
{
strcpy(arr[i],c);
fscanf(fp,"%s",c);
i++;
}
int k=0;
printf("controlsection
symbol address length\n");
while(k<i)
{
if(strcmp(arr[k],"H")==0)
{
if(m==0)
{
strcpy(pr_name,arr[k+1]);
t1=dh(arr[k+2]);
t2=dh(rel);
t1=t1+t2;
hd(t1);
rev(hex);
strcpy(start_add,locadd);
t1=dh(arr[k+3]);
hd(t1);
rev(hex);
strcpy(len,locadd);
printf("\n%s\t\t\t%s\t%s\n",pr_name,start_add,len);
m=1;
}
else
{
strcpy(pr_name,arr[k+1]);
t1=dh(arr[k+2]);
t2=dh(rel);
t3=dh(len);
t1=t1+t2+t3;
hd(t1);
rev(hex);
strcpy(start_add,locadd);
t1=dh(arr[k+3]);
hd(t1);
rev(hex);
strcpy(len,locadd);
printf("\n%s\t\t\t%s\t%s\n",pr_name,start_add,len);
}
k=k+4;
}

else if(strcmp(arr[k],"D")==0)
{
int k1=1;k++;
while(strcmp(arr[k],"R")!=0&&strcmp(arr[k],"T")!=0)
{
if(strcmp(arr[k],"R")!=0)
{
if(k1%2!=0)
{
printf("\n\t\t%s\t",arr[k]);
k++;k1++;p++;
}
else
{
t1=dh(arr[k]);
t2=dh(start_add);
t1=t1+t2;
hd(t1);
rev(hex);
printf("%s\n",locadd);
k++;k1++;p++;
}
}
}
}
else
{
if(k==i-1)
exit(0);
k++;
}
}
return 0;
}

SAMPLE I/P AND O/P:


I/P FILE:
H PROGA 000000 000063
D LISTA 000040 ENDA 000054
R LISTB ENDB
T 000020 0A 03201D 77100004 050014
T 000054 0F 000014 FFFFF6 00003F 000014 FFFFC0
M 000024 05+LISTB
E
H PROGB 000000 00007F
D LISTB 000060 ENDB 000070
R LISTA ENDA
T 000036 0B 03100000 772027 05100000
T 000070 0F 000000 FFFFF6 FFFFFF FFFFF0 000060
M 000037 05+LISTA
M 00003E 06+ENDA
M 00003E 06-LISTA
E
O/P:
Enter the loadtime address:4000
controlsection
symbol address length
PROGA

4000

63

LISTA 4040
ENDA
PROGB

4054
4063

LISTB 40C3
ENDB

40D3

7F

IMPLEMENTATION PASS 2 OF DIRECT LINKING LOADER


PROGRAM CODE: 11
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
char w[20],hex[20],locadd[10];
int dh(char a[30])
{
int i2,j2=0,m2=1,h=0,b[20];
for(i2=0;a[i2]!='\0';i2++)
{
switch(a[i2])
{
case '0':
b[j2]=0;
break;
case '1':
b[j2]=1;
break;
case '2':
b[j2]=2;
break;
case '3':
b[j2]=3;
break;
case '4':
b[j2]=4;
break;
case '5':
b[j2]=5;
break;
case '6':
b[j2]=6;
break;
case '7':
b[j2]=7;
break;
case '8':
b[j2]=8;
break;
case '9':
b[j2]=9;
break;
case 'A':
b[j2]=10;
break;
case 'B':
b[j2]=11;
break;

REG NO:

case 'C':
b[j2]=12;
break;
case 'D':
b[j2]=13;
break;
case 'E':
b[j2]=14;
break;
case 'F':
b[j2]=15;
break;
}
j2++;
}
j2--;
for(;j2>=0;j2--)
{
h=h+b[j2]*m2;
m2=m2*16;
}
return h;
}
void hd(int h)
{
int l=0,p2;
while(h>0)
{
p2=h%16;
h=h/16;
switch(p2)
{
case 0:
hex[l]='0';
break;
case 1:
hex[l]='1';
break;
case 2:
hex[l]='2';
break;
case 3:
hex[l]='3';
break;
case 4:
hex[l]='4';
break;
case 5:
hex[l]='5';

break;
case 6:
hex[l]='6';
break;
case 7:
hex[l]='7';
break;
case 8:
hex[l]='8';
break;
case 9:
hex[l]='9';
break;
case 10:
hex[l]='A';
break;
case 11:
hex[l]='B';
break;
case 12:
hex[l]='C';
break;
case 13:
hex[l]='D';
break;
case 14:
hex[l]='E';
break;
case 15:
hex[l]='F';
break;
}
l++;
}
hex[l]='\0';
}
void rev(char a1[20])
{
int d,j1=0,i1;
d=strlen(a1);
for(i1=d-1;i1>=0;i1--)
{
locadd[j1]=a1[i1];
j1++;
}
locadd[j1]='\0';
}
int main()
{
FILE *fp,*fp1;

int
i=0,j,k,m=0,t1,t2,t3,t4,t5,t6,l1,l2,i2,s1,p=0,k1,j1,i7,i9,
t,i1,temp,i3,t7,m1=0;
char
c[20],arr[150][30],rel[10],len[10],op,sym[10],tstart[10],
tlen[10],buff[10],dlen[10],arr2[250][30],obj1[30][30],len_h[
10],rel1[10],rel2[10],len2[10],o[30];
fp=fopen("dy2file.c","r");
fscanf(fp,"%s",c);
while(!feof(fp))
{
strcpy(arr[i],c);
fscanf(fp,"%s",c);
i++;
}
fp1=fopen("es.c","r");
i1=0;
fscanf(fp1,"%s",c);
while(!feof(fp1))
{
if(i1==1)
{
strcpy(rel,c);
strcpy(rel1,c);
}
else if(i1==2){
strcpy(len,c);
strcpy(len_h,c);}
i1++;
fscanf(fp1,"%s",c);
}
k=0;
while(k<i)
{
if(strcmp(arr[k],"H")==0)
{
if(m1==0)
{
m1=1;
strcpy(len2,"0");
}
else
{
t1=dh(rel);
t2=dh(len_h);
strcpy(len2,len_h);
t2=t2+t1;
hd(t2);
rev(hex);
strcpy(rel,locadd);

strcpy(len_h,arr[k+3]);
}
m=0;
k=k+4;
}
else if(strcmp(arr[k],"T")==0)
{
if(m==0)
{
t1=dh(rel);
t2=dh(arr[k+1]);
t3=dh(rel);
t2=t2+t3;
if(t2-t1==0){}
else
{
for(s1=t2-t1;s1>0;s1--)
{
strcpy(arr2[p],"XX");p++;
}
}
strcpy(tstart,arr[k+1]);
strcpy(tlen,arr[k+2]);
m=1;
}
else
{
t1=dh(tstart);
t2=dh(tlen);
t3=t1+t2;
hd(t3);
rev(hex);
t4=dh(locadd);
t5=dh(arr[k+1]);
t6=(t5)-t4;
if(t6==1)
{}
else
{
for(s1=t6;s1>0;s1--)
{
strcpy(arr2[p++],"XX");
}
}
strcpy(tstart,arr[k+1]);
strcpy(tlen,arr[k+2]);
}
k=k+3;

}
else if(strcmp(arr[k],"E")==0)
{
k++;
}
else if (strcmp(arr[k],"M")==0)
{
l1=0;l2=0;i1=0;k1=0;
t=dh(arr[k+1]);
int t7=dh(len2);
t=t+t7;
while(arr[k+2][l1]!='-'&&arr[k+2][l1]!='+')
{
l1++;
}
op=arr[k+2][l1];
for(i2=l1+1;i2<strlen(arr[k+2]);i2++)
{
sym[l2]=arr[k+2][i2];
l2++;
}
sym[l2]='\0';
fp1=fopen("es.c","r");
fscanf(fp1,"%s",buff);
while(!feof(fp1))
{
if(strcmp(buff,sym)==0)
{
fscanf(fp1,"%s",buff);
strcpy(dlen,buff);
}
fscanf(fp1,"%s",buff);
}
while(i1<t)
{
while(k1<p&&i1<t)
{
for(j1=0;arr2[k1][j1]!='\0';j1=j1+2)
{
i1=i1+1;
if(i1==t)
{
t1=dh(arr2[k1]);
t2=dh(dlen);
if(op=='+')
t1=t1+t2;
else if(op=='-')
t1=t1-t2;
hd(t1);
rev(hex);
switch(strlen(locadd))

{
case 6:
strcpy(o,"00");
break;
case 7:
strcpy(o,"0");
break;
case 8:
strcpy(o,"");
break;
}
strcat(o,locadd);
strcpy(arr2[k1],o);
}
}
k1++;
}
}
k=k+3;
}
else
if(strcmp(arr[k],"D")==0||(strcmp(arr[k],"R")==0))
{
while(strcmp(arr[k],"T")!=0)
{
k++;
}
}
else
{
strcpy(arr2[p],arr[k]);
p++;
k++;
}
}
k=0;
while(k<p)
{
if(k==0){
strcpy(obj1[0],arr2[k]);k++;}
else{
strcat(obj1[0],arr2[k]);k++;}
}
temp=dh(rel1);
hd(temp);
rev(hex);
i=0;
while(obj1[0][i]!='\0')
{
printf("\n%X\t",temp);

i7=0;
while(i7<32)
{
for(i9=0;i9<8;i9++)
{
if(obj1[0][i]=='\0')
printf("X");
else
{
printf("%c",obj1[0][i]);
i=i+1;
}
i7++;
}
printf("\t");
}
temp=dh(locadd);
t2=dh("10");
temp=temp+t2;
hd(temp);
rev(hex);
}
return 0;
}

SAMPLE I/P AND O/P:


I/P:
PROGA

4000
LISTA 4040
ENDA 4054
4063
LISTB 40C3
ENDB 40D3

PROGB

63
7F

H PROGA 000000 000063


D LISTA 000040 ENDA 000054
R LISTB ENDB
T 000020 0A 03201D 77100004 050014
T 000054 0F 000014 FFFFF6 00003F 000014 FFFFC0
M 000024 05+LISTB
E
H PROGB 000000 00007F
D LISTB 000060 ENDB 000070
R LISTA ENDA
T 000036 0B 03100000 772027 05100000
T 000070 0F 000000 FFFFF6 FFFFFF FFFFF0 000060
M 000037 05+LISTA
M 00003E 06+ENDA
M 00003E 06-LISTA
E
O/P:
4000
4010
4020
4030
4040
4050
4060
4070
4080
4090
40A0
40B0
40C0
40D0
40E0

XXXXXXXX
XXXXXXXX
03201D77
XXXXXXXX
0804AD94
XXXXXXXX
00003F00
XXXXXXXX
XXXXXXXX
XXXXXXXX
10000077
XXXXXXXX
XXXXXXXX
XXXXXXXX
FFFFFFFF

XXXXXXXX
XXXXXXXX
1040C705
XXXXXXXX
XXXXXXXX
XXXXXXXX
0014FFFF
XXXXXXXX
XXXXXXXX
XXXXXXXX
20270510
XXXXXXXX
XXXXXXXX
XXXXXXXX
F0000060

XXXXXXXX
XXXXXXXX
0014XXXX
XX0804EC
XXXXXXX
XXXX0000
C0XXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
0000XXXX
XXXXXXXX
XXXXXXXX
XX000000
XXXXXXXX

XXXXXXXX
XXXXXXXX
XXXXXXXX
58XXXXXX
XXXXXXXX
14FFFFF6
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXX03
XXXXXXXX
XXXXXXXX
XXXXXXXX
FFFFF6FF
XXXXXXXX

IMPLEMENTATION OF TEXT EDITOR


PROGRAM CODE:12
REG NO:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
char
a[1000],ch,b,d,name[200],data[1000],s[20],cp[1000],lp[1000],g[10]
,cp1[1000],lp1[1000];
int i=0,n,l,j,k,op,p,slen,llen,dlen,dlen1,slen1,llen1,p1;
FILE *fp,*fp1;
void save();
void open();
void main()
{
clrscr();
printf("\n------------\n");
printf("\ntexteditor\n");
printf("\n------------\n");
do
{
printf("\noptions \n1. create a new text \n2. deleting a char
\n3. inserting a char \n4. open a file \n5. insert a Word \n6.
delete a Word \n7. exit\n");
scanf("%d",&op);
switch(op)
{
case 1:
printf("\nenter your Data Here(Esc to stop):\n");
do
{
ch=getch();
if(ch!=13)
{
printf("%c",ch);
a[i]=ch;
i++;
}
}while(ch!=13);
save();
break;
case 2:
open();
l=strlen(a);
printf("\nEnter the position for deleting the character:\n");

scanf("%d",&n);
j=n-1;
i=n-1;
while(i<l)
{
a[i]=a[++j];
i=i+1;
}
for(i=0;i<l;i++)
printf("%c",a[i]);
save();
break;
case 3:
open();
printf("Enter the position to be inserted\n");
scanf("%d",&n);
l=strlen(a);
j=l+1;
i=l;
k=n-1;
printf("enter the character to be inserted\n");
d=getch();
printf("%c",d);
printf("\n");
while(i>n-2)
{
a[j]=a[i];
j=i;
i=i-1;
}
a[k]=d;
for(i=0;i<l;i++)
printf("%c",a[i]);
save();
break;
case 4:
open();
break;
case 5:
open();
printf("\nenter the position for inserting the Word:");
scanf("%d",&p);
printf("\nenter the word: ");
scanf("%s",s);
dlen=strlen(s);

slen=strlen(a);
strncpy(cp,a,p-1);
llen=strlen(cp);
llen=slen-llen;
strrev(a);
strncpy(lp,a,llen);
strrev(lp);
strcat(cp," ");
strcat(cp,s);
strcat(cp,lp);
strcpy(a,cp);
printf("%s",cp);
printf("%s",a);
save();
break;
case 6:
open();
printf("\nDeleting a Word:\n");
printf("\nenter the position of the Word:\n");
scanf("%d",&p1);
printf("enter the substring:");
scanf("%s",g);
dlen1=strlen(g);
slen1=strlen(a);
strncpy(cp1,a,p1-1);
llen1=strlen(cp1);
llen1=slen1-llen1;
strrev(a);
llen1=llen1-dlen1;
strncpy(lp1,a,llen1);
strrev(lp1);
strcat(cp1,lp1);
strcpy(a,cp1);
printf("%s",cp1);
save();
break;
case 7:
exit(1);
break;
}
}while(1);
}
void save()
{
fp=fopen("text.txt","w");

fprintf(fp,"%s",a);
fclose(fp);
}
void open()
{
fp1=fopen("text.txt","r");
fgets(data,1000,fp1);
printf("Data in the file:\n");
printf("%s\n",data);
strcpy(a,data);
fclose(fp1);
}
Output:
-----------texteditor
-----------options
1. create a new text
2. deleting a char
3. inserting a char
4. open a file
5. insert a Word
6. delete a Word
7. exit
1
enter your Data Here(Esc to stop):
unix is a os
options
1. create a new text
2. deleting a char
3. inserting a char
4. open a file
5. insert a Word
6. delete a Word
7. exit
2
Data in the file:
unix is a os
Enter the position for deleting the character:
2
uix is a os
options
1. create a new text
2. deleting a char
3. inserting a char
4. open a file

5. insert a Word
6. delete a Word
7. exit
3
Data in the file:
uix is a os
Enter The position for inserting the character:
2
Enter the character:
n
unix is a os
options
1. create a new text
2. deleting a char
3. inserting a char
4. open a file
5. insert a Word
6. delete a Word
7. exit
5
Data in the file:
unix is a os
Enter The position for inserting the word:
5
Enter the Word:
is
unix is is a os
options
1. create a new text
2. deleting a char
3. inserting a char
4. open a file
5. insert a Word
6. delete a Word
7. exit
6
Enter The position for deleting the word:
6
Enter the Word:
is
unix is a os

IMPLEMENTATION OF SYMBOL TABLE USING HASHING


PROGRAM CODE :13

REG NO:

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
int flag,i2;
char var[][200]={"int","float","char","double"};
int count[5]={2,4,1,4};
char temp[30],temp1[30],type1[10],size1;
int i,j,k=0,m,ch;
struct list
{
char sym[10];
int add;
char type[10];
int size;
char val[10];
struct list *next;
};
typedef struct list *ls;
struct hash
{
struct list *header[10];
int ct;
};
struct hash *h;
typedef struct hash *ptr;
ptr createhash()
{
int i1=0;
struct hash *temp2;
temp2=(ptr)malloc(sizeof(struct hash));
temp2->ct=0;
for(i1=0;i1<10;i1++)
{
temp2->header[i1]=(ls)malloc(sizeof(struct list));
temp2->header[i1]->next=NULL;
strcpy(temp2->header[i1]->sym,"\0");
strcpy(temp2->header[i1]->type,"\0");
strcpy(temp2->header[i1]->val,"\0");
}
return temp2;
}
int search(ls p,char temp[])
{
flag=1;
p=p->next;
while(p!=NULL)

{
if(strcmp(p->sym,temp)==0)
{
flag=0;
return flag;
}
p=p->next;
}
return flag;
}
ls search1(ls p,char temp[])
{
//flag=1;
p=p->next;
while(p!=NULL)
{
if(strcmp(p->sym,temp)==0)
{
return p;
}
p=p->next;
}
return p;
}
ls findprev(ls p,char temp[])
{
while(p->next!=NULL)
{
if(strcmp(p->next->sym,temp)==0)
return p;
p=p->next;
}
return p;
}
void delete(ls p,char temp[])
{
ls q;
flag=search(p,temp);
if(flag!=0)
{
printf("***************symbol not
found*****************");
}
else
{
q=findprev(p,temp);
q->next=q->next->next;
}
}
void insertlist(ls p,char temp[],char temp1[],int size1,char
type1[])

{
ls q;
flag=search(p,temp);
if(flag!=0)
{
q=(ls)malloc(sizeof(struct list));
while(p->next!=NULL)
{
p=p->next;
}
strcpy(q->sym,temp);
strcpy(q->type,type1);
strcpy(q->val,temp1);
q->size=size1;
p->next=q;
q->next=NULL;
}
else
{
printf("**************symbol already
exists************");
}
}
int hashkey(char temp[])
{
i2=0;
while(*temp!='\0')
i2+=*temp++;
i2=i2%10;
//intf("\nHash:%d",i2);
return i2;
}
void inserthash(char temp[],char temp1[],int size1,char type1[])
{
i2=hashkey(temp);
insertlist(h->header[i2],temp,temp1,size1,type1);
}
void modify(ls p,char temp[])
{
ls q;
flag=search(p,temp);
if(flag!=0) printf("************symbol not
found************");
else
{
q=findprev(p,temp);
q=q->next;
printf("Enter the new value:");
scanf("%s",temp1);
strcpy(q->val,temp1);

}
}
void displaylist(ls p)
{
p=p->next;
while(p!=NULL)
{
printf("[%s,%s,%d,%s]\t",p->sym,p->type,p->size,p>val);
p=p->next;
}
}

void display()
{
int i3;
printf("\n");
for(i3=0;i3<10;i3++)
{
printf("%d\t",i3);
displaylist(h->header[i3]);
printf("\n");
}
}
int main()
{
FILE *fp;
ls p;
int q1=0;
char f1[10],c[10],arr[30],b;
h=createhash();
printf("Enter the file name:");
scanf("%s",f1);
fp=fopen(f1,"r");
fscanf(fp,"%s",c);
while(!feof(fp))
{
for(m=0;m<3;m++)
{
if(strcmp(c,var[m])==0)
{
fscanf(fp,"%c",&b);
while(b!=';'&&b!='\n')
{
fscanf(fp,"%c",&b);
while(b!=','&&b!=';'&&b!='\n')
{
if(isalpha(b)!=0)
{

temp[i]=b;
i++;
}
else if(isdigit(b)!=0)
{
temp1[j]=b;
j++;
}
else if(b=='.')
{
if(isdigit(arr[q11])!=0)
{
temp1[j]=b;
j++;
}
}

arr[q1]=b;q1++;
fscanf(fp,"%c",&b);
}
temp[i]='\0';
temp1[j]='\0';
size1=count[m];
strcpy(type1,c);
inserthash(temp,temp1,size1,type1);
i=0;j=0;k++,q1=0;
temp[i]=temp1[j]=arr[q1]='\0';
}
}
}
fscanf(fp,"%s",c);
}
printf("\n1.Insert\n2.delete\n3.search\n4.modify\n5.displa
y\n6.exit\nEnter the choice:");
scanf("%d",&ch);
while(ch<=6)
{
switch(ch)
{
case 1:
printf("Enter the symbol to be
inserted:");
scanf("%s",temp);
printf("Enter the datatype:");
scanf("%s",type1);
printf("Enter the value:");
scanf("%s",temp1);

for(i=0;i<3;i++)
{
if(strcmp(type1,var[i])==0)
size1=count[i];
}
inserthash(temp,temp1,size1,type1);
break;
case 2:
printf("Enter the symbol to delete:");
scanf("%s",temp);
i=hashkey(temp);
delete(h->header[i],temp);
break;
case 3:
printf("Enter the symbol to search:");
scanf("%s",temp);
i=hashkey(temp);
p=search1(h->header[i],temp);
if(p==NULL) printf("************symbol
doesnt exists***************");
else
{
printf("The symbol is present:");
Printf("\nname:%s\nvalue:%s\ntype:%s\nsize:%d",p->sym,p>val,p->type,p->size);
}
break;
case 4:
printf("Enter the symbol to search:");
scanf("%s",temp);
i=hashkey(temp);
modify(h->header[i],temp);
break;
case 5:
display();
break;
case 6:
exit(0);
break;
}
printf("\n1.Insert\n2.delete\n3.search\n4.modify\n5.displa
y\n6.exit\nEnter the choice:");
scanf("%d",&ch);
}
display();
return 0;
}
Enter the file name:token.c
1.Insert

2.delete
3.search
4.modify
5.display
6.exit
Enter the
Enter the
Enter the
Enter the

choice:1
symbol to be inserted:abc
datatype:int
value:43

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5
0
1
2
3
4
5
6
7

8
9

[main,int,2,]
[f,int,2,]
[ch,char,1,]
[abc,int,2,43]
[a,int,2,]

[add,float,4,]

[b,int,2,340]
[c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:2
Enter the symbol to delete:add
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5
0
1
2

[main,int,2,]
[f,int,2,]

3
4
5
6
7
8
9

[ch,char,1,]
[abc,int,2,43]
[a,int,2,]
[b,int,2,340]
[c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:2
Enter the symbol to delete:s
***************symbol not found*****************
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:3
Enter the symbol to search:abc
The symbol is present:
name:abc
value:43

type:int
size:2
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
enter the choice:3
Enter the symbol to search:d
************symbol doesnt exists***************
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:4

Enter the symbol to search:a


Enter the new value:10
1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:5
0
1
2
3
4
5
6
7
8
9

[main,int,2,]
[f,int,2,]
[ch,char,1,]
[abc,int,2,43]
[a,int,2,10]
[b,int,2,340]
[c,float,4,]

1.Insert
2.delete
3.search
4.modify
5.display
6.exit
Enter the choice:6

You might also like