Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4.  
  5. #define null 0
  6.  
  7. int size = 0;
  8. struct symbolTabclear
  9. {
  10. char label[10];
  11. int addr;
  12. struct symbolTab *next;
  13. };
  14.  
  15. struct symbolTab *first, *last;
  16. struct symbolTab1
  17. {
  18. char labell[10];
  19. int addr1;
  20. struct symbolTab1 *next1;
  21. };
  22.  
  23. struct symbolTab1 *first1, *last1;
  24.  
  25. void display()
  26. {
  27. int i;
  28. struct symbolTab *p;
  29. p = first;
  30. printf("Label \tAddress \n");
  31. for (i=0; i<size;i++)
  32. {
  33. printf("%s\t%d\n", p->label,p->addr);
  34. p = p->next;
  35. }
  36. }
  37.  
  38. void display1()
  39. {
  40. int i;
  41. struct symbolTab1 *p;
  42. p = first1;
  43. printf("Label \tAddress\n");
  44. for (i=0;i<size;i++)
  45. {
  46. printf("%s\t%d\n", p->labell,p->addr1);
  47. p = p->next1;
  48. }
  49. }
  50.  
  51. int find(char lab[])
  52. {
  53. int i, flag=0;
  54. struct symbolTab *p;
  55. p = first;
  56. for (i=0;i<size;i++)
  57. {
  58. if (strcmp(p->label,lab) ==0 )
  59. {
  60. flag =1;
  61. }
  62. p = p->next;
  63. }
  64. return flag;
  65. }
  66.  
  67. int find1(char lab[])
  68. {
  69. int i, flag=0;
  70. struct symbolTab1 *p;
  71. p = first1;
  72. for (i=0;i<size;i++)
  73. {
  74. if (strcmp(p->labell,lab) ==0 )
  75. {
  76. flag =1;
  77. }
  78. p = p->next1;
  79. }
  80. return flag;
  81. }
  82.  
  83. void insert1()
  84. {
  85. int n1;
  86. char ll[10];
  87. printf("Enter the label: ");
  88. scanf("%s",ll);
  89. n1 = find1(ll);
  90. if (n1 == 1)
  91. {
  92. printf("cannot insert");
  93. }
  94. else
  95. {
  96. struct symbolTab1 *p;
  97. p = malloc(sizeof(struct symbolTab));
  98. strcpy(p->labell,ll);
  99. printf("Enter the address: ");
  100. scanf("%d", &p->addr1);
  101. p ->next1 = null;
  102. if (size ==0 )
  103. {
  104. first1 = p;
  105. last1 = p;
  106. }
  107. else
  108. {
  109. last1->next1 = p;
  110. last1 = p;
  111. }
  112. size++;
  113. }
  114. display1();
  115. }
  116.  
  117. void insert1()
  118. {
  119. int n1;
  120. char l[10];
  121. printf("Enter the label: ");
  122. scanf("%s",l);
  123. n1 = find(l);
  124. if (n == 1)
  125. {
  126. insert1();
  127. }
  128. else
  129. {
  130. struct symbolTab *p;
  131. p = malloc(sizeof(struct symbolTab));
  132. strcpy(p->label,l);
  133. printf("Enter the address: ");
  134. scanf("%d", &p->addr);
  135. p ->next = null;
  136. if (size ==0 )
  137. {
  138. first = p;
  139. last = p;
  140. }
  141. else
  142. {
  143. last->next = p;
  144. last = p;
  145. }
  146. size++;
  147. }
  148. display();
  149. }
  150.  
  151. void main()
  152. {
  153. int option;
  154. int y,x;
  155. char la[10];
  156. // clrscr();
  157. do
  158. {
  159. printf("\nSymbol Table Execution\n");
  160. printf("1. Insert\n");
  161. printf("2. Display\n");
  162. printf("3. Find\n");
  163. printf("4. End\n");
  164. printf("Enter your choice: ");
  165. scanf(option)
  166. {
  167. case 1:
  168. insert();
  169. break;
  170. case 2:
  171. display();
  172. display1();
  173. break;
  174. case 3:
  175. printf("Enter the label to find: ");
  176. scanf("%s",la);
  177. y = find(la);
  178. if (y == 1)
  179. {
  180. printf("The label is found in the symbol table ");
  181. }
  182. else
  183. {
  184. x = find1(la);
  185. if (x ==1)
  186. {
  187. printf("label found");
  188. }
  189. else {
  190. printf("label not found");
  191. }
  192. }
  193. break;
  194. case 4:
  195. break;
  196. } while (option < 4);
  197.  
  198. }
  199.  
  200.  
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement