Advertisement
Guest User

Untitled

a guest
May 4th, 2023
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void main()
  4. {
  5. char str[100]; /* Declares a string of size 100 */
  6. int l = 0;
  7. int z = 1;
  8. int i;
  9. printf("\n\nLEXICAL ANALYZER :\n");
  10. printf("------------------------------------------------------\n");
  11. printf("Input the equation : ");
  12. fgets(str, sizeof str, stdin);
  13. printf("TOKENS : \n");
  14. int c = strlen(str);
  15. for (l=0;l<c-1;l++)
  16. {
  17. if (str[l] == 'a' || str[l] == 'b' || str[l] == 'c' || str[l] == 'e' ||str[l] == 'f' ||str[l] == 'g' ||str[l] == 'h' ||str[l] == 'i' ||str[l] == 'j' ||str[l] == 'k' ||str[l] == 'd' ||str[l] == 'm')
  18. {
  19. printf("%c is ", str[l]);
  20. printf("ID%d\n",z);
  21. //l++;
  22. z++;
  23. }
  24. else if (str[l] == '*'){
  25. printf("%c is ", str[l]);
  26. printf("multiplication\n");
  27. //l++;
  28. }
  29. else if (str[l] == '+'){
  30. printf("%c is ", str[l]);
  31. printf("addition\n");
  32. //l++;
  33. }
  34. else if (str[l] == '/'){
  35. printf("%c is ", str[l]);
  36. printf("division\n");
  37. //l++;
  38. }
  39. else if (str[l] == ':'){
  40. printf("%c%c is ", str[l],str[l+1]);
  41. printf("AOP\n");
  42. l++;
  43. }
  44. else if (str[l] == '-'){
  45. printf("%c is ", str[l]);
  46. printf("subtraction\n");
  47. //l++;
  48. }
  49. else if (str[l] == '*'){
  50. printf("%c is ", str[l]);
  51. printf("exponent\n");
  52. // l++;
  53. }
  54. else{
  55. printf("%c is ", str[l]);
  56. printf("Constant\n");
  57. //l++;
  58. }
  59. }
  60. printf("\n");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement