#include #include #include using namespace std; int main() { int pila[100]; int tope = 0; string instr; cout << "#include " << endl; cout << "int main() {" << endl; cout << "int pila[100] = { 0 }, tope = 0, x1, x2;" << endl; while (cin >> instr) { if (instr == "PUSH") { int val; cin >> val; cout << "pila[tope] = " << val << ";" << endl; cout << "tope += 1;" << endl; } else if (instr == "ADD") { cout << "x1 = pila[tope - 1];" << endl; cout << "x2 = pila[tope - 2];" << endl; cout << "tope -= 2;" << endl; cout << "pila[tope] = x1 + x2;" << endl; cout << "tope += 1;" << endl; } else if (instr == "PRINT") { cout << "x1 = pila[tope - 1];" << endl; cout << "tope -= 1;" << endl; cout << "printf(\"%d\\n\", x1);" << endl; } else if (instr == "DUP") { cout << "x1 = pila[tope - 1];" << endl; cout << "pila[tope] = x1;" << endl; cout << "tope += 1;" << endl; } else { cerr << "mala instruccion" << endl; abort(); } } cout << "}" << endl; }