Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. int parse_pascal(int num_cod, int kol_enter)
  2. {
  3. string good_string, good, znak_str;
  4. bool comments = false, var_mark = false, commas = false, space = false;
  5. for (int i = 0; i < kol_enter; i++)
  6. {
  7. good_string = good = "";
  8. int point = 0, length = s[num_cod][i].size();
  9. while (point <= length)
  10. {
  11. //comments
  12. if (point < length - 1 && s[num_cod][i][point] == '/' && s[num_cod][i][point + 1] == '/')
  13. break;
  14. if (s[num_cod][i][point] == '{')
  15. comments = true;
  16. if (s[num_cod][i][point] == '}')
  17. comments = false;
  18. //commas
  19. if (s[num_cod][i][point] == 39)
  20. commas = abs(commas - 1);
  21. if (comments || commas)
  22. {
  23. point++;
  24. continue;
  25. }
  26. //---go---
  27. if (isalpha(s[num_cod][i][point]) || isdigit(s[num_cod][i][point]))
  28. good += s[num_cod][i][point];
  29. else
  30. {
  31. //var_mark
  32. if (good == "var")
  33. var_mark = true;
  34. if (!var_mark || good == "var")
  35. {
  36. point++;
  37. good = "";
  38. continue;
  39. }
  40. //input/output
  41. if (good == "readln" || good == "read" || good == "writeln" || good == "write")
  42. {
  43. while (point < length && s[num_cod][i][point - 1] != ';')
  44. point++;
  45. good = "";
  46. }
  47. //new_word
  48. if (good == "")
  49. {
  50. point++;
  51. continue;
  52. }
  53. if (strt.count(good))
  54. good_string += strt[good];
  55. else
  56. {
  57. if (!isalpha(good[1]))
  58. good_string += good + ' ';
  59. else
  60. if (key_word.count(good))
  61. good_string += good + ' ';
  62. else
  63. good_string += "o ";
  64. }
  65. good = "";
  66. }
  67. znak_str = s[num_cod][i][point];
  68. if (znak.count(znak_str))
  69. good_string += znak_str + " ";
  70.  
  71. point++;
  72. }
  73. //end
  74. space = false;
  75. for (int j = 0; j < good_string.size(); j++)
  76. if (good_string[j] != ' ')
  77. space = true;
  78. if (!space)
  79. {
  80. for(int j = i; j < kol_enter; j++)
  81. s[num_cod][j] = s[num_cod][j + 1];
  82. kol_enter--;
  83. i--;
  84. }
  85. else
  86. s[num_cod][i] = good_string;
  87. }
  88. return kol_enter;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement