Advertisement
Guest User

Untitled

a guest
Mar 9th, 2023
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. struct Interpreter
  6. {
  7.   char MEM[30'000];
  8.  char PC;
  9.  char SP = 0;
  10.  
  11.  void increment()
  12.  {
  13.      if (MEM[SP] < 255)
  14.     {
  15.      
  16.     MEM[SP] = MEM[SP] + 1;
  17.     }
  18.      else
  19.     MEM[SP] = 0;
  20.  }
  21.  
  22.  void Interpret(string code)
  23.  {
  24.    for(char c: code)
  25.      {
  26.     switch (c)
  27.       {
  28.       case '+':
  29.         increment();
  30.         break;
  31.       case '-':
  32.         printf("-\n");
  33.         break;
  34.       default:
  35.         break;
  36.       }
  37.        
  38.      }
  39.  }
  40. };
  41.  
  42. void increment(Interpreter& BF)
  43. // increment the memory @ stackPointer by 1 and wrap to 0 if > 255
  44. {
  45. }
  46.  
  47. int main (int argc, char* argsv[])
  48. {
  49.  string code = "+++";
  50.  Interpreter BF;
  51.  BF.Interpret(code);
  52.  printf("Now SP is %d", BF.MEM[BF.SP]);
  53.  
  54.  return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement