Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. /*
  2. * main.cpp
  3. *
  4. * Created on: Feb 23, 2017
  5. * Author: student
  6. */
  7.  
  8.  
  9. #include <iostream>
  10. #include <fstream>
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15.  
  16. std::ofstream outfile ("test.cpp");
  17. std::ifstream infile("input.txt");
  18.  
  19.  
  20. if(infile.is_open())
  21. {
  22. string myArray[100];
  23.  
  24. for(int i = 0; i < 100; ++i)
  25. {
  26. infile >> myArray[i];
  27. }
  28. outfile << "#include <iostream>\n#include <fstream>\nusing namespace std;\n int main() {\n" ;
  29. for(int j = 0; j < 100; ++j)
  30. {
  31.  
  32. if (myArray[j]== "Var ")
  33. {
  34.  
  35. outfile << "\nint ";
  36. }
  37. else
  38. if(myArray[j]==",")
  39. {
  40. outfile<<",";
  41.  
  42. }
  43. else
  44.  
  45.  
  46. if (myArray[j]== "a")
  47. {
  48. outfile << "<Identificator>::=";
  49. }
  50. else if(myArray[j]== "b")
  51. {
  52. outfile << "<Identificator>::=";
  53. }
  54. else if(myArray[j]== "c")
  55. {
  56. outfile << "<Identificator>::=\n";
  57.  
  58.  
  59. }
  60.  
  61. else if(myArray[j]== "d")
  62. {
  63. outfile << "<Identificator>::=\n";
  64. }
  65. else if((myArray[j]=="+")||(myArray[j]=="-"))
  66. {
  67. outfile<<"<Operatie>::=""+""|""-"" ";
  68. }
  69. else if(myArray[j]=="-")
  70. {
  71. outfile<<"<Operatie>";
  72. }
  73.  
  74. else if (myArray[j]== "Input")
  75. {
  76. outfile << "cin >> ";
  77. }
  78. else if (myArray[j]== "Output")
  79. {
  80. outfile << "cout << ";
  81. }
  82. else
  83. {
  84. outfile << myArray[j] ;
  85. }
  86. }
  87. }
  88.  
  89. outfile << "return 0; }" << std::endl;
  90. cout << "Done !" << endl;
  91. infile.close();
  92. outfile.close();
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement