Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- class Element {
- protected:
- char* Content;
- enum el_type {
- var,
- op,
- val
- }type;
- public:
- void setContent(char* newContent)
- {
- this->Content = new char[strlen(newContent) + 1];
- strcpy_s(this->Content,strlen(newContent) + 1, newContent);
- }
- char* getContent()
- {
- return this->Content;
- }
- void setType(el_type newType)
- {
- this->type = newType;
- }
- el_type getType()
- {
- return this->type;
- }
- };
- void removeSpaces(char *str)
- {
- int count = 0;
- for (int i = 0; str[i]; i++)
- if (str[i] != ' ')
- str[count++] = str[i];
- str[count] = '\0';
- }
- vector<vector<string>> readAllToHash(ifstream inputFile)
- {
- vector<vector<string>> hashList;
- char line[255];
- while (inputFile.getline(line, 255))
- {
- cout << line << endl;
- size_t pos = 0;
- string lineTBT(line);
- string word;
- string delimiter = " ";
- vector<string> lineList;
- bool ok = false;
- while (((pos = lineTBT.find(delimiter)) != string::npos) || (ok == true))
- {
- word = lineTBT.substr(0, pos);
- cout << word << endl;
- lineList.push_back(word);
- lineTBT.erase(0, pos + delimiter.length());
- if (ok == true)
- {
- ok = false;
- break;
- }
- if ((lineTBT.find(delimiter) == -1) && (ok == false))
- ok = true;
- }
- cout << endl;
- hashList.push_back(lineList);
- }
- return hashList;
- }
- vector<Element> identificator(vector<string>)
- {
- vector<Element> identifiedVector;
- return identifiedVector;
- }
- int main()
- {
- char* avNumbers = nullptr;
- char* avLetters = nullptr;
- char* avOperators = nullptr;
- char** avInstrTemplates = nullptr;
- ifstream rulesFile("D:\\1406A\\Rules.txt");
- if (!rulesFile)
- {
- cout << "Cannot open rules file.\n";
- rulesFile.close();
- return 1;
- }
- else
- {
- cout << "rules.txt :" << endl;
- char auxLine[255];
- //Available Numbers
- rulesFile.getline(auxLine, 255);
- removeSpaces(auxLine);
- avNumbers = new char[strlen(auxLine) + 1];
- strcpy_s(avNumbers, strlen(auxLine) + 1, auxLine);
- cout << avNumbers << endl;
- //Available Letters
- rulesFile.getline(auxLine, 255);
- removeSpaces(auxLine);
- avLetters = new char[strlen(auxLine) + 1];
- strcpy_s(avLetters, strlen(auxLine) + 1, auxLine);
- cout << avLetters << endl;
- //Available Operators
- rulesFile.getline(auxLine, 255);
- removeSpaces(auxLine);
- avOperators = new char[strlen(auxLine) + 1];
- strcpy_s(avOperators, strlen(auxLine) + 1, auxLine);
- cout << avOperators << endl;
- //Available Instructions Templates
- cout << endl;
- }
- ifstream inFile("D:\\1406A\\Code.txt");
- if (!inFile)
- {
- cout << "Cannot open input file.\n";
- inFile.close();
- return 1;
- }
- else
- {
- cout << "Code.txt :" << endl;
- //vector<vector<string>> code = readAllToHash(inFile);
- inFile.close();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement