Advertisement
Mikhail-Podbolotov

Untitled

May 7th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. #include "library.h"
  5. int main()
  6. {
  7.     ifstream input("input.txt");
  8.     ofstream nonRecursiveFile("non_recursive.txt");
  9.     ofstream recursiveFile("recursive.txt");
  10.     List functionsList;
  11.     bool inFunctionName = false;
  12.     string functionName;
  13.     bool isRecursive = false;
  14.     bool inFunction = false;
  15.     string ForWhileFlag = "";
  16.     while (!input.eof()) {
  17.         string line;
  18.         getline(input, line);
  19.         if (!inFunction) {
  20.             for (char c : line) {
  21.                 if (inFunctionName && (c == ' ' or c == ':') && line.find("(") != string::npos) {
  22.                     functionName="";
  23.                 }
  24.                 if (c == '(') {
  25.                     inFunctionName = false;
  26.                 }
  27.  
  28.                 if (inFunctionName and c!='{' and c!=' ' and c!=':') {
  29.                     functionName += c;
  30.                 }
  31.                 if (!inFunctionName && (c == ' ' or c == ':') && line.find("(") != string::npos && functionName.empty()) {
  32.                     inFunctionName = true;
  33.                 }
  34.  
  35.                 if (!functionName.empty() and c == '{' or functionsList.InList(functionName)) {
  36.                     inFunction = true;
  37.                 }
  38.             }
  39.         }
  40.         // можно убрать условие но тогда будут находится различные вызовы функций из разряда functionsList.InList(){...
  41.         else if (functionName.find(";") == string::npos and functionName.find(",") == string::npos and functionName.find(".") == string::npos and functionName.find("'") == string::npos){
  42.             //cout << line << "!!!" << functionName << " " << line.find(functionName) << endl;
  43.             if (line.find("return") != string::npos) {
  44.                 if (line.find(functionName)!=string::npos) isRecursive = true;
  45.                 if (!functionName.empty()) {
  46.                     functionsList.addFunction(functionName, isRecursive);
  47.                 }
  48.             }
  49.             else {
  50.                 functionsList.addFunction(functionName, isRecursive);
  51.             }
  52.             if (functionsList.InList(functionName)) {
  53.                 inFunctionName = false;
  54.                 functionName.clear();
  55.                 isRecursive = false;
  56.                 inFunction = false;
  57.             }
  58.         }
  59.     }
  60.     functionsList.PrintR(recursiveFile);
  61.     functionsList.PrintNR(nonRecursiveFile);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement