0% found this document useful (0 votes)
93 views6 pages

Symbol Table Creation

The document describes the implementation of a symbol table with functions for insertion, searching, modification, and display. The symbol table is implemented as an array of structures with label and address fields. Functions are provided to insert new symbols, search for symbols by label, modify the address of an existing symbol, and display the entire symbol table. The program takes user input to call these functions and demonstrate their use.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views6 pages

Symbol Table Creation

The document describes the implementation of a symbol table with functions for insertion, searching, modification, and display. The symbol table is implemented as an array of structures with label and address fields. Functions are provided to insert new symbols, search for symbols by label, modify the address of an existing symbol, and display the entire symbol table. The program takes user input to call these functions and demonstrate their use.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Symbol table creation Name: K.

BALAJI Date:
#include<stdio.h> #include<conio.h> struct intermediate { int addr; char label[10]; char mnem[10]; char op[10]; }res; struct symbol { char symbol[10]; int addr; }sy; void main() { FILE *s1,*p1; clrscr(); s1=fopen("inter.txt","r+"); p1=fopen("symbol.txt","w"); while(!feof(s1)) { fscanf(s1,"%d %s %s %s",&res.addr,res.label,res.mnem,res.op); if(strcmp(res.label,"NULL")!=0) { strcpy(sy.symbol,res.label); sy.addr=res.addr; fprintf(p1,"%s\t%d\n",sy.symbol,sy.addr); } } fcloseall(); printf("symbol table created"); getch(); }

Exercise No: 1a

Input Files inter.txt 0 NULL START 500 500 A DS 100 600 B DC 10 610 FIRST PRINT A 612 NULL READ B 613 NULL END FIRST

Output Files: Symbol.txt A 500 B 600 FIRST 610

Implementations of symbol table with features like insert, modify, search, and display. Name: K.BALAJI Ex.no:1b Date:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> int cnt=0; struct symtab { char label[20]; int addr; }sy[50]; void insert(); int search(char *); void display(); void modify(); void main() { int ch,val; char lab[10]; do { printf("\n 1.insert\n2.display\n3.search\n4.modify\n5.exit\n"); scanf("%d",&ch); switch(ch) { case 1: insert(); break; case 2: display(); break; case 3: printf("enter the label"); scanf("%s",lab); val=search(lab); if(val==1) printf("label is found"); else printf("label is not found"); break; case 4: modify();

break; case 5: exit(0); break; } }while(ch<5); } void insert() { int val; char lab[10]; printf("enter the label"); scanf("%s",lab); val=search(lab); if(val==1) printf("duplicate symbol"); else { strcpy(sy[cnt].label,lab); printf("enter the address"); scanf("%d",&sy[cnt].addr); cnt++; } } int search(char *s) { int flag=0,i; for(i=0;i<cnt;i++) { if(strcmp(sy[i].label,s)==0) flag=1; } return flag; } void modify() { int val,ad,i; char lab[10]; printf("enter the label"); scanf("%s",lab); val=search(lab); if(val==0) printf("no such symbol"); else { printf("label is found \n");

printf("enter the address"); scanf("%d",&ad); for(i=0;i<cnt;i++) { if(strcmp(sy[i].label,lab)==0) sy[i].addr=ad; } } } void display() { int i; for(i=0;i<cnt;i++) printf("%s\t%d\n",sy[i].label,sy[i].addr); }

Input and output 1.insert 2.display 3.search 4.modify 5.exit 1 enter the label A enter the address 2000 1.insert 2.display 3.search 4.modify 5.exit 1 enter the label SUB enter the address 3000 1.insert 2.display 3.search 4.modify 5.exit 1 enter the label MUL enter the address 4000 1.insert 2.display 3.search 4.modify

5.exit 2 A 2000 SUB 3000 MUL 4000 1.insert 2.display 3.search 4.modify 5.exit 3 enter the label A label is found 1.insert 2.display 3.search 4.modify 5.exit 4 enter the label A label is found enter the address 5000 1.insert 2.display 3.search 4.modify 5.exit 5

You might also like