Advertisement
UnlimitedSupply

Custom Brainfuck Complier

Jun 19th, 2022
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1. using System;
  2. class HelloWorld {
  3.   static void Main() {
  4.     int [] Cookie = new int [255];
  5.     int WhichCookie, HML, digitIn, digitInLoop;
  6.     bool BGC, FGC, isZero;
  7.     string action, action2;
  8.     action = Console.ReadLine();
  9.     BGC = false;
  10.     FGC = false;
  11.     digitIn = 0;
  12.     HML = 0;
  13.     foreach (char x in action) {
  14.         digitIn++;
  15.         if (Cookie[WhichCookie] == 0) {
  16.             isZero = true;
  17.         } else {
  18.             isZero = false;
  19.         }
  20.         switch (x) {
  21.             case '+':
  22.                 Cookie[WhichCookie]++;
  23.                 break;
  24.             case '-':
  25.                 Cookie[WhichCookie]--;
  26.                 break;
  27.             case '>':
  28.                 WhichCookie++;
  29.                 break;
  30.             case '<':
  31.                 WhichCookie--;
  32.                 break;
  33.             case '.':
  34.                 Console.Write(char.ConvertFromUtf32(Cookie[WhichCookie]));
  35.                 break;
  36.             case '[':
  37.                 if (!(isZero)) {
  38.                     action2 = action.substring(digitIn);
  39.                     do {
  40.                         digitInLoop = 0;
  41.                         foreach (char y in action2) {
  42.                             digitInLoop++;
  43.                             switch (y) {
  44.                                 case '[':
  45.                                     HML++;
  46.                                     break;
  47.                                 case ']':
  48.                                     HML--;
  49.                                     if (HML == -1) {
  50.                                         action2 = action2.substring(digitInLoop);
  51.                                     }
  52.                                     break;
  53.                                 case '+':
  54.                                     Cookie[WhichCookie]++;
  55.                                     break;
  56.                                 case '-':
  57.                                     Cookie[WhichCookie]--;
  58.                                     break;
  59.                                 case '>':
  60.                                     WhichCookie++;
  61.                                     break;
  62.                                 case '<':
  63.                                     WhichCookie--;
  64.                                     break;
  65.                                 case '.':
  66.                                     Console.Write(char.ConvertFromUtf32(Cookie[WhichCookie]));
  67.                                     break;
  68.                                 case '?':
  69.                                     Cookie[WhichCookie] += 10;
  70.                                     break;
  71.                                 case '!':
  72.                                     Cookie[WhichCookie] -= 10;
  73.                                     break;
  74.                                 case '$':
  75.                                     Cookie[WhichCookie] += 5;
  76.                                     break;
  77.                                 case '#':
  78.                                     Cookie[WhichCookie] -= 5;
  79.                                     break;
  80.                                 case '~':
  81.                                     Cookie[WhichCookie] = 0;
  82.                                     break;
  83.                                 case '/':
  84.                                     Console.Write(Cookie[WhichCookie]);
  85.                                     break;
  86.                             }
  87.                         }
  88.                     } while (!isZero);
  89.                 }
  90.                 break;
  91.             case '?':
  92.                 Cookie[WhichCookie] += 10;
  93.                 break;
  94.             case '!':
  95.                 Cookie[WhichCookie] -= 10;
  96.                 break;
  97.             case '$':
  98.                 Cookie[WhichCookie] += 5;
  99.                 break;
  100.             case '#':
  101.                 Cookie[WhichCookie] -= 5;
  102.                 break;
  103.             case '~':
  104.                 Cookie[WhichCookie] = 0;
  105.                 break;
  106.             case '/':
  107.                 Console.Write(Cookie[WhichCookie]);
  108.                 break;
  109.         }
  110.     }
  111.   }
  112. }
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement