Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> //*
- #include <conio.h>
- #include <fstream> //Чтение и сохранение данных
- #include <iostream> //Работа с данными
- #include <string> //работа со строками //back
- using namespace std;
- int main(void)
- {
- string str; //создание переменной типа string
- ifstream file("dank.txt"); //создание объекта класса
- int num_break = 0, num_while = 0, num_switch = 0, num_for = 0, num_open = 0, num_close = 0;
- int str_break = 0, str_switch = 0, str_for = 0, num_str = 0;
- int fl_break[50], str_open = 0, str_close = 0, str_while = 0;
- int pos_open[50], pos_close[50], pos_break[50], pos_while[50], pos_for[50], pos_switch[50], kol_while = 0, kol_for = 0, kol_switch = 0;
- while (getline(file, str)) //cout << str << endl; //getline - чтение строки из текста
- {
- num_str++;
- if (str.find('"') > str.length())
- if (str.rfind('"') > str.length())
- {
- int o = 0, c = 0, fl_1 = 0, fl_2 = 0;
- if (str.find("while") < str.length())
- {
- if (str.find("(") < str.length())
- {
- o = str.find("(");
- if (str.find(")") < str.length())
- {
- c = str.find(")");
- if (o < c)
- {
- pos_while[num_str] = str.find("while");
- str_while = num_str;
- kol_while++;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie while " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie while " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie while " << endl;
- }
- else
- pos_while[num_str] = -1;
- if (str.find("for") < str.length())
- {
- if (str.find("(") < str.length())
- {
- o = str.find("(");
- if (str.find(")") < str.length())
- {
- c = str.find(")");
- if (o < c)
- {
- if (str.find(";") < str.length())
- {
- fl_1 = str.find(";");
- if (str.find_first_of(";", str.find(";") + 1) < str.length())
- {
- fl_2 = str.find_first_of(";", str.find(";") + 1);
- if (o < fl_1 && fl_1 < fl_2 && fl_2 < c)
- {
- pos_for[num_str] = str.find("for");
- str_for = num_str;
- kol_for++;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie for " << endl;
- }
- }
- }
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie for " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie for " << endl;
- }
- else
- pos_for[num_str] = -1;
- if (str.find("switch") < str.length())
- {
- if (str.find("(") < str.length())
- {
- o = str.find("(");
- if (str.find(")") < str.length())
- {
- c = str.find(")");
- if (o < c)
- {
- pos_switch[num_str] = str.find("switch");
- str_switch = num_str;
- kol_switch++;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie switch " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie switch " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie switch " << endl;
- }
- else
- pos_switch[num_str] = -1;
- if (str.find("break") < str.length())
- {
- fl_1 = str.find("break");
- if (str.find_first_of(";", str.find("break") + 1) < str.length())
- {
- fl_2 = str.find_first_of(";", str.find("break") + 1);
- if (fl_1 > fl_2)
- cout << "error[" << num_str << "]: nekorrektnoe napisanie break " << endl;
- }
- else
- cout << "error[" << num_str << "]: nekorrektnoe napisanie break " << endl;
- }
- if ((kol_while > 0 || kol_for > 0 || kol_switch > 0) && (str.find("{") < str.length() || str.find("}") < str.length()) && (pos_while[str_while] <= (str.find("{") && pos_while[str_while] <= (str.find("}")))) && (pos_for[str_for] <= (str.find("{") && pos_for[str_for] <= (str.find("}")))) && (pos_switch[str_switch] <= (str.find("{") && pos_switch[str_switch] <= (str.find("}")))))
- {
- do
- {
- if (str.find("{") < str.length())
- {
- num_open++;
- pos_open[num_str] = str.find("{");
- if (str.find("}") > str.length())
- break;
- }
- else
- {
- pos_open[num_str] = -1;
- }
- if (str.find("}") < str.length())
- {
- num_close++;
- pos_close[num_str] = str.find("}");
- if (kol_while > 0 && str_while > str_for > str_switch)
- kol_while--;
- if (kol_for > 0 && str_for > str_while > str_switch)
- kol_for--;
- if (kol_switch > 0 && str_switch > str_for > str_while)
- kol_switch--;
- }
- else
- {
- pos_close[num_str] = -1;
- }
- num_str++;
- } while (getline(file, str));
- }
- }
- }
- file.close();
- ifstream br("dank.txt");
- num_str = 0;
- while (getline(br, str))
- {
- num_str++;
- if (str.find('"') > str.length())
- if (str.rfind('"') > str.length())
- if (str.find("break") < str.length())
- {
- do
- {
- if (str.rfind(';') < str.length())
- {
- pos_break[num_str] = str.find("break");
- break;
- }
- else
- pos_break[num_str] = -1;
- num_str++;
- } while (getline(file, str));
- }
- }
- br.close();
- int s = num_str, fl_3 = 0, fl_4=0;
- int kol_open = 0, kol_close = 0;
- for (num_str = 1; num_str <= s; num_str++)
- {
- if (pos_break[num_str] > -1)
- {
- str_break = num_str;
- }
- if (pos_while[num_str] > -1)
- {
- str_while = num_str;
- }
- if (pos_for[num_str] > -1)
- {
- str_for = num_str;
- }
- if (pos_switch[num_str] > -1)
- {
- str_switch = num_str;
- }
- if (pos_open[num_str] > -1)
- {
- kol_open++;
- if (str_open == 0)
- str_open = num_str;
- }
- if (pos_close[num_str] > -1)
- {
- kol_close++;
- str_close = num_str;
- }
- }
- cout << "kol_open " << kol_open << endl;
- cout << "kol_close " << kol_close << endl;
- if (kol_open != kol_close)
- {
- cout << "error [-]: ne hvataet figurnih skobok dla raboti break" << endl;
- }
- for (num_str = 1; num_str <= s; num_str++)
- {
- if (pos_break[num_str] > -1)
- {
- if (str_open != 0 && str_close != 0)
- {
- fl_4 = 1;
- }
- if (str_while == 0 && str_for == 0 && str_switch == 0)
- {
- fl_4 = 1;
- }
- else
- {
- if (num_str < str_while)
- fl_4 = 1;
- if (num_str < str_for)
- fl_4 = 1;
- if (num_str < str_switch)
- fl_4 = 1;
- }
- if ((num_str < str_open || num_str > str_close) && fl_4 == 1)
- {
- cout << "error [" << num_str << "]: break vne cikla" << endl;
- }
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement