Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int parse_pascal(int num_cod, int kol_enter)
- {
- string good_string, good, znak_str;
- bool comments = false, var_mark = false, commas = false, space = false;
- for (int i = 0; i < kol_enter; i++)
- {
- good_string = good = "";
- int point = 0, length = s[num_cod][i].size();
- while (point <= length)
- {
- //comments
- if (point < length - 1 && s[num_cod][i][point] == '/' && s[num_cod][i][point + 1] == '/')
- break;
- if (s[num_cod][i][point] == '{')
- comments = true;
- if (s[num_cod][i][point] == '}')
- comments = false;
- //commas
- if (s[num_cod][i][point] == 39)
- commas = abs(commas - 1);
- if (comments || commas)
- {
- point++;
- continue;
- }
- //---go---
- if (isalpha(s[num_cod][i][point]) || isdigit(s[num_cod][i][point]))
- good += s[num_cod][i][point];
- else
- {
- //var_mark
- if (good == "var")
- var_mark = true;
- if (!var_mark || good == "var")
- {
- point++;
- good = "";
- continue;
- }
- //input/output
- if (good == "readln" || good == "read" || good == "writeln" || good == "write")
- {
- while (point < length && s[num_cod][i][point - 1] != ';')
- point++;
- good = "";
- }
- //new_word
- if (good == "")
- {
- point++;
- continue;
- }
- if (strt.count(good))
- good_string += strt[good];
- else
- {
- if (!isalpha(good[1]))
- good_string += good + ' ';
- else
- if (key_word.count(good))
- good_string += good + ' ';
- else
- good_string += "o ";
- }
- good = "";
- }
- znak_str = s[num_cod][i][point];
- if (znak.count(znak_str))
- good_string += znak_str + " ";
- point++;
- }
- //end
- space = false;
- for (int j = 0; j < good_string.size(); j++)
- if (good_string[j] != ' ')
- space = true;
- if (!space)
- {
- for(int j = i; j < kol_enter; j++)
- s[num_cod][j] = s[num_cod][j + 1];
- kol_enter--;
- i--;
- }
- else
- s[num_cod][i] = good_string;
- }
- return kol_enter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement