Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- #include <iomanip>
- using namespace std;
- int main() {
- setlocale(LC_CTYPE, "rus");
- cout << "Введите логическое выражение" << endl;
- string str;
- getline(cin, str);
- {
- for (int i = 0; i < str.length(); i++)
- {
- if (str[i] >= 'A' && str[i] <= 'z' && str[i + 1] != 'o' && str[i + 1] != 'a' && str[i + 1] != 'n' && str[i + 1] != 'r')
- {
- cout << str[i]<<setw(22) << " -идентификатор" << setw(40) << endl;
- }
- if (str[i] == 'x' && str[i + 1] == 'o' && str[i + 2] == 'r')
- {
- cout << "xor" << setw(22) << " -операция" << setw(40) << endl;
- i += 2;
- }
- if (str[i] == 'o' && str[i + 1] == 'r' && str[i - 1] != 'x' && i != 0)
- {
- cout << "or" << setw(22) << " -операция" << setw(40) << endl;
- i++;
- }
- if (str[i] == 'n' && str[i + 1] == 'o' && str[i + 2] == 't')
- {
- cout << "not" << setw(22) << " -операция" << setw(40) << endl;
- i += 2;
- }
- if (str[i] == 'a' && str[i + 1] == 'n' && str[i + 2] == 'd')
- {
- cout << "and" << setw(22) << " -операция" << setw(40) << endl;
- i += 2;
- }
- if (str[i] == 'f' && str[i + 1] == 'a' && str[i + 2] == 'l' && str[i + 3] == 's' && str[i + 4] == 'e')
- {
- cout << "false" << setw(22) << " -константанта" << setw(40) << endl;
- i += 4;
- }
- if (str[i] == 't' && str[i + 1] == 'r' && str[i + 2] == 'u' && str[i + 3] == 'e')
- {
- cout << "true" << setw(22) << " -константа" << setw(40) << endl;
- i += 3;
- }
- if (str[i] == ':' && str[i + 1] == '=')
- {
- cout <<":=" << setw(22) << " -знак присваивания" << setw(40) << endl;
- i++;
- }
- if (str[i] == '(' || str[i] == ')')
- {
- cout << setw(22) << str[i] << setw(40) << " -скобка" << endl;
- i++;
- }
- if (str[i] == ';')
- {
- cout << setw(22) << str[i] << setw(40) << " -знак разделения" << endl;
- i++;
- }
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement