0 Members and 1 Guest are viewing this topic.
#include <iostream>#include <string>#include <stdlib.h>#include <windows.h>using namespace std;int loopstart = 0;int main(){ cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n"; string prgm; signed int mem = 0; bool loop = false; while (true) { cout << ">>> "; cin >> prgm; for (int i=0;i < prgm.length();i++) { char data = prgm[i]; switch (data) { case '0': Sleep(0.1); break; case '1': if (prgm[i+1]=='n') cout << mem; else cout << (char)mem; break; case '2': mem++; break; case '3': mem--; break; case '4': char inp; mem = 0; cin >> inp; mem = (int)inp; break; case '5': cout << "\n"; break; case '6': mem = rand() % 256 + 1; break; case '7': loop = false; loopstart = i; break; case '8': mem = 0; break; case '9': if (loop==true) { i++; loop = false; } else { i = loopstart; loop = true; } break; case 'q': return 0; break; case 'n': break; default: cout << "\nUnknown command...\n"; } } cout << "\nProgram finished.\n"; }}
Haha nice!Calc version soon?
7 - Ignores everything until the next 7. (Could allow for comments?)9 - Repeats the command before it once.
#include <iostream>#include <string>#include <stdlib.h>#include <windows.h>using namespace std;int loopstart = 0;int main(){ cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n"; string prgm; signed int mem = 0; int pos = 0; char data; bool ignore = false; bool repeat = false; while (true) { cout << ">>> "; cin >> prgm; for (int i=0;i < prgm.length();i++) { data = prgm[i]; if (ignore==true) { if (data=='7') { ignore = false; } } else { switch (data) { case '0': Sleep(100); break; case '1': if (prgm[i+1]=='n') cout << mem; else cout << (char)mem; break; case '2': mem++; break; case '3': mem--; break; case '4': char inp; mem = 0; cin >> inp; mem = (int)inp; break; case '5': cout << "\n"; break; case '6': mem = rand() % 256 + 1; break; case '7': ignore = true; break; case '8': mem = 0; break; case '9': if (repeat==false) { i--; repeat = true; } else if (repeat==true) { repeat = false; } break; case 'q': return 0; break; case 'n': break; case 'x': goto end; break; default: break; } } } end: cout << "\nProgram finished.\n"; }}
#include <iostream>#include <string>#include <stdlib.h>#include <windows.h>using namespace std;int loopstart = 0;int main(){ cout << "Spyrodecimal Interpreter\nBy Spyro543 -- Type 'q' to exit\n------------------------\n"; string prgm; signed int mem = 0; int pos = 0; char data; signed int a = 0; signed int b = 0; signed int c = 0; signed int d = 0; signed int e = 0; signed int f = 0; char var; while (true) { cout << ">>> "; cin >> prgm; for (int i=0;i < prgm.length();i++) { data = prgm[i]; switch (data) { case '0': Sleep(100); break; case '1': cout << (char)mem; break; case '2': mem++; break; case '3': mem--; break; case '4': char inp; mem = 0; cin >> inp; mem = (int)inp; break; case '5': cout << "\n"; break; case '6': mem = rand() % 256 + 1; break; case '7': i -= mem; break; case '8': mem = 0; break; case '9': i += mem; break; case 'q': return 0; break; case 'n': cout << mem; break; case 'x': goto end; break; case 'r': var = prgm[i+1]; if (var=='a') mem = a; else if (var=='b') mem = b; else if (var=='c') mem = c; else if (var=='d') mem = d; else if (var=='e') mem = e; else if (var=='f') mem = f; break; case 's': var = prgm[i+1]; if (var=='a') a = mem; else if (var=='b') b = mem; else if (var=='c') c = mem; else if (var=='d') d = mem; else if (var=='e') e = mem; else if (var=='f') f = mem; break; default: break; } } end: cout << "\nProgram finished.\n"; }}
#include <iostream>#include <conio.h>#include <string.h>#include <string>#include <windows.h>#include <time.h>using namespace std;int main(void){ int memory[2048]; int label[256]; int reg; int deep; bool ignore = false; bool debug = false; char tmp; srand((unsigned)time(NULL)); while(true) { string program; cout << endl << ">>>"; cin >> program; memset(memory,0,2048*sizeof(int)); memset(label,0,256*sizeof(int)); reg = 0; deep = 0; for (int i=0; i < program.length(); i++) { if(program[i] == 'l') { label[program[i+1]] = i+1; if(debug) cout << "Label " << program[i+1] << " at " << i+1 << endl; } } for (int i=0; i < program.length(); i++) { if(ignore && program[i] != ';') continue; else ignore = false; if(debug) cout << "op=" << program[i] << ", pos=" << i << ", reg=" << reg << " (" << (char)reg << ")" << endl; switch(program[i]) { case 'd': debug = !debug; if(debug) cout << "\tdebug=" << debug << endl; break; case 'n': cout << endl; break; case 'i': if(debug) cout << "\tinput "; cin >> tmp; reg = tmp; break; case 'p': if(debug) cout << "\tprint " << (char)reg << endl; else cout << (char)reg; break; case 'I': if(debug) cout << "\tinput "; cin >> reg; break; case 'P': if(debug) cout << "\tprint " << reg << endl; else cout << reg; break; case 'k': reg = getch(); break; case 't': reg = rand(); if(debug) cout << "\trand=" << (int)reg << endl; break; case 'j': if(debug) cout << "\tlabel=" << program[i+1] << ", pos=" << label[program[i+1]] << endl; i = label[program[i+1]]; break; case 's': memory[program[i+1]] = reg; i++; if(debug) cout << "\tmemory(" << program[i] << ")=" << reg << endl; break; case 'r': reg = memory[program[i+1]]; i++; if(debug) cout << "\tmemory(" << program[i] << ")=" << reg << endl; break; case 'S': memory[memory[program[i+1]]] = reg; i++; break; case 'R': //cout << program[i+1] << "," << memory[program[i+1]] << "," << memory[memory[program[i+1]]] << endl; reg = memory[memory[program[i+1]]]; i++; break; case '1': reg++; break; case '2': reg--; break; case '+': if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", add=" << reg + memory[program[i+1]] << endl; reg = reg + memory[program[i+1]]; i++; break; case '-': if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", subtract=" << reg - memory[program[i+1]] << endl; reg = reg - memory[program[i+1]]; i++; break; case '/': if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", divide=" << reg / memory[program[i+1]] << endl; reg = reg / memory[program[i+1]]; i++; break; case '*': if(debug) cout << "\treg=" << reg << ", memory(" << program[i+1] << ")=" << memory[program[i+1]] << ", multiply=" << reg * memory[program[i+1]] << endl; reg = reg * memory[program[i+1]]; i++; break; case 'x': reg = 0; break; case '=': reg = program[i+1]; i++; break; case '?': if(program[i+1] == '=') { if(reg == memory[program[i+2]]) ignore = false; else ignore = true; } else if(program[i+1] == '!') { if(reg != memory[program[i+2]]) ignore = false; else ignore = true; } else if(program[i+1] == '>') { if(reg > memory[program[i+2]]) ignore = false; else ignore = true; } else if(program[i+1] == '<') { if(reg < memory[program[i+2]]) ignore = false; else ignore = true; } if(debug) cout << "\tif reg " << program[i+1] << " memory(" << program[i+2] << ") --> " << ignore << endl; i += 2; break; default: break; } } }}