Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class Element {
  9. protected:
  10.     char* Content;
  11.     enum el_type {
  12.         var,
  13.         op,
  14.         val
  15.     }type;
  16. public:
  17.     void setContent(char* newContent)
  18.     {
  19.         this->Content = new char[strlen(newContent) + 1];
  20.         strcpy_s(this->Content,strlen(newContent) + 1, newContent);
  21.     }
  22.     char* getContent()
  23.     {
  24.         return this->Content;
  25.     }
  26.     void setType(el_type newType)
  27.     {
  28.         this->type = newType;
  29.     }
  30.     el_type getType()
  31.     {
  32.         return this->type;
  33.     }
  34. };
  35.  
  36. void removeSpaces(char *str)
  37. {
  38.     int count = 0;
  39.     for (int i = 0; str[i]; i++)
  40.         if (str[i] != ' ')
  41.             str[count++] = str[i];
  42.     str[count] = '\0';
  43. }
  44.  
  45. vector<vector<string>> readAllToHash(ifstream inputFile)
  46. {
  47.     vector<vector<string>> hashList;
  48.     char line[255];
  49.     while (inputFile.getline(line, 255))
  50.     {
  51.         cout << line << endl;
  52.         size_t pos = 0;
  53.         string lineTBT(line);
  54.         string word;
  55.         string delimiter = " ";
  56.         vector<string> lineList;
  57.         bool ok = false;
  58.         while (((pos = lineTBT.find(delimiter)) != string::npos) || (ok == true))
  59.         {
  60.             word = lineTBT.substr(0, pos);
  61.             cout << word << endl;
  62.             lineList.push_back(word);
  63.             lineTBT.erase(0, pos + delimiter.length());
  64.  
  65.             if (ok == true)
  66.             {
  67.                 ok = false;
  68.                 break;
  69.             }
  70.             if ((lineTBT.find(delimiter) == -1) && (ok == false))
  71.                 ok = true;
  72.         }
  73.         cout << endl;
  74.         hashList.push_back(lineList);
  75.     }
  76.     return hashList;
  77. }
  78.  
  79. vector<Element> identificator(vector<string>)
  80. {
  81.     vector<Element> identifiedVector;
  82.  
  83.  
  84.     return identifiedVector;
  85. }
  86.  
  87. int main()
  88. {
  89.     char* avNumbers = nullptr;
  90.     char* avLetters = nullptr;
  91.     char* avOperators = nullptr;
  92.     char** avInstrTemplates = nullptr;
  93.  
  94.     ifstream rulesFile("D:\\1406A\\Rules.txt");
  95.     if (!rulesFile)
  96.     {
  97.         cout << "Cannot open rules file.\n";
  98.         rulesFile.close();
  99.         return 1;
  100.     }
  101.     else
  102.     {
  103.         cout << "rules.txt :" << endl;
  104.  
  105.         char auxLine[255];
  106.         //Available Numbers
  107.         rulesFile.getline(auxLine, 255);
  108.         removeSpaces(auxLine);
  109.         avNumbers = new char[strlen(auxLine) + 1];
  110.         strcpy_s(avNumbers, strlen(auxLine) + 1, auxLine);
  111.         cout << avNumbers << endl;
  112.  
  113.         //Available Letters
  114.         rulesFile.getline(auxLine, 255);
  115.         removeSpaces(auxLine);
  116.         avLetters = new char[strlen(auxLine) + 1];
  117.         strcpy_s(avLetters, strlen(auxLine) + 1, auxLine);
  118.         cout << avLetters << endl;
  119.  
  120.         //Available Operators
  121.         rulesFile.getline(auxLine, 255);
  122.         removeSpaces(auxLine);
  123.         avOperators = new char[strlen(auxLine) + 1];
  124.         strcpy_s(avOperators, strlen(auxLine) + 1, auxLine);
  125.         cout << avOperators << endl;
  126.  
  127.         //Available Instructions Templates
  128.        
  129.  
  130.         cout << endl;
  131.     }
  132.  
  133.     ifstream inFile("D:\\1406A\\Code.txt");
  134.     if (!inFile)
  135.     {
  136.         cout << "Cannot open input file.\n";
  137.         inFile.close();
  138.         return 1;
  139.     }
  140.     else
  141.     {
  142.         cout << "Code.txt :" << endl;
  143.         //vector<vector<string>> code = readAllToHash(inFile);
  144.        
  145.         inFile.close();
  146.         return 0;
  147.     }
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement