Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- int x = 0;
- string grammar [25];
- char ntl [25];
- int ntlindex = 0;
- string line;
- ifstream file;
- file.open("CFG.txt");
- ofstream output;
- output.open("TEST.txt");
- if (file.is_open())
- {
- while (file.good())
- {
- getline (file,line);
- grammar[x] = line;
- //cout << line << endl;
- x++;
- }
- file.close();
- }
- /*
- cout << endl;
- cout << endl << endl;
- for (int i = 0; i < x; i++)
- {
- cout << grammar[i] << endl;
- }
- cout << endl;
- cout << endl;
- for (int i = 4; i < x; i++)
- cout << grammar[i] << endl;
- */cout << endl << endl;
- for (int i = 4; i < x; i++)
- {
- for (int j = 5; j < grammar[i].length(); j++)
- {
- cout << grammar[i][j];
- if (grammar[i][j] == '$')
- {
- ntl[ntlindex]=grammar[i][0];
- ntlindex++;
- }
- if (grammar[i][j] == '|')
- {
- grammar[i][j] = '!';
- }
- }
- cout << endl;
- }
- cout << endl << endl;
- /*for (int a = 4; a < x; a++)
- {
- for (int b = 5; b < grammar[a].length(); b++)
- {
- for (int c = 0; c < 25 && ntl[c] != 'Ì'; c++)
- {
- if (grammar[a][b] == ntl[c])
- b++;
- }
- cout << grammar[a][b];
- }
- cout << endl;
- }*/
- /*for (int i = 0; i < 25 && ntl[i] != 'Ì' ; i++)
- {
- cout << ntl[i] << endl;
- }*/
- for (int i = 4; i < x; i++)
- {
- //cout << "i is " << i << endl;
- for (int j = 5; j < grammar[i].length(); j++)
- {
- int yes = 0;
- //cout << "J is " << j << endl;
- for (int k = 0; (k < 25) && (ntl[k] != 'Ì'); k++)
- {
- //cout << "k is " << k << endl;
- if (grammar[i][j] == ntl[k] && j < grammar[i].length())
- {
- yes = 1;
- //cout << "j is equal to " << j << endl;
- int temp = j;
- j++;
- for (j ; !(grammar[i][j] == '!') && (j < grammar[i].length()); j++)
- {
- cout << grammar[i][j];
- output << grammar[i][i];
- }
- cout << '|';
- output << '|';
- //cout << " j is equal to " << j << endl;
- j--;
- for (j; !(grammar[i][j] == ' ') && !(grammar[i][j] == '!'); j--)
- {
- cout << "";
- output << "";
- }
- j++;
- //cout << "j is equal to" << j << endl;
- for (j; j <= temp; j++)
- {
- cout << grammar[i][j];
- output << grammar[i][j];
- }
- //cout << "j is equal to" << j << endl;
- }
- cout << grammar[i][j];
- output << grammar[i][j];
- if (grammar[i][j] == '!' && yes == 1)
- {
- for (int b = 5; b < grammar[i].length(); b++)
- {
- for (int c = 0; c < 25 && ntl[c] != 'Ì'; c++)
- {
- if (grammar[i][b] == ntl[c])
- b++;
- }
- cout << grammar[i][b];
- output << grammar[i][b];
- }
- }
- }
- }
- cout << endl;
- output << endl;
- }
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement