Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #define null 0
- int size = 0;
- struct symbolTabclear
- {
- char label[10];
- int addr;
- struct symbolTab *next;
- };
- struct symbolTab *first, *last;
- struct symbolTab1
- {
- char labell[10];
- int addr1;
- struct symbolTab1 *next1;
- };
- struct symbolTab1 *first1, *last1;
- void display()
- {
- int i;
- struct symbolTab *p;
- p = first;
- printf("Label \tAddress \n");
- for (i=0; i<size;i++)
- {
- printf("%s\t%d\n", p->label,p->addr);
- p = p->next;
- }
- }
- void display1()
- {
- int i;
- struct symbolTab1 *p;
- p = first1;
- printf("Label \tAddress\n");
- for (i=0;i<size;i++)
- {
- printf("%s\t%d\n", p->labell,p->addr1);
- p = p->next1;
- }
- }
- int find(char lab[])
- {
- int i, flag=0;
- struct symbolTab *p;
- p = first;
- for (i=0;i<size;i++)
- {
- if (strcmp(p->label,lab) ==0 )
- {
- flag =1;
- }
- p = p->next;
- }
- return flag;
- }
- int find1(char lab[])
- {
- int i, flag=0;
- struct symbolTab1 *p;
- p = first1;
- for (i=0;i<size;i++)
- {
- if (strcmp(p->labell,lab) ==0 )
- {
- flag =1;
- }
- p = p->next1;
- }
- return flag;
- }
- void insert1()
- {
- int n1;
- char ll[10];
- printf("Enter the label: ");
- scanf("%s",ll);
- n1 = find1(ll);
- if (n1 == 1)
- {
- printf("cannot insert");
- }
- else
- {
- struct symbolTab1 *p;
- p = malloc(sizeof(struct symbolTab));
- strcpy(p->labell,ll);
- printf("Enter the address: ");
- scanf("%d", &p->addr1);
- p ->next1 = null;
- if (size ==0 )
- {
- first1 = p;
- last1 = p;
- }
- else
- {
- last1->next1 = p;
- last1 = p;
- }
- size++;
- }
- display1();
- }
- void insert1()
- {
- int n1;
- char l[10];
- printf("Enter the label: ");
- scanf("%s",l);
- n1 = find(l);
- if (n == 1)
- {
- insert1();
- }
- else
- {
- struct symbolTab *p;
- p = malloc(sizeof(struct symbolTab));
- strcpy(p->label,l);
- printf("Enter the address: ");
- scanf("%d", &p->addr);
- p ->next = null;
- if (size ==0 )
- {
- first = p;
- last = p;
- }
- else
- {
- last->next = p;
- last = p;
- }
- size++;
- }
- display();
- }
- void main()
- {
- int option;
- int y,x;
- char la[10];
- // clrscr();
- do
- {
- printf("\nSymbol Table Execution\n");
- printf("1. Insert\n");
- printf("2. Display\n");
- printf("3. Find\n");
- printf("4. End\n");
- printf("Enter your choice: ");
- scanf(option)
- {
- case 1:
- insert();
- break;
- case 2:
- display();
- display1();
- break;
- case 3:
- printf("Enter the label to find: ");
- scanf("%s",la);
- y = find(la);
- if (y == 1)
- {
- printf("The label is found in the symbol table ");
- }
- else
- {
- x = find1(la);
- if (x ==1)
- {
- printf("label found");
- }
- else {
- printf("label not found");
- }
- }
- break;
- case 4:
- break;
- } while (option < 4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement