Skip to content

Instantly share code, notes, and snippets.

@uael
Created July 15, 2017 09:46
Show Gist options
  • Save uael/b1af7daa2e6f3a55020aa4f253ea65df to your computer and use it in GitHub Desktop.
Save uael/b1af7daa2e6f3a55020aa4f253ea65df to your computer and use it in GitHub Desktop.
#include <unistd.h>
int main(int ac, char **av) {
char brank, *ptr, *input, optab[4096] = {0};
if (ac <= 1) {
write(1, "\n", 1);
return 0;
}
ptr = optab;
input = av[1];
while (*input) switch (*input) {
case '>': ++ptr;
goto next;
case '<': --ptr;
goto next;
case '+': ++*ptr;
goto next;
case '-': --*ptr;
goto next;
case '.': write(1, ptr, 1);
goto next;
case '[':
goto next;
case ']': brank = 1;
if (*ptr) do switch (*--input) {
case '[':
--brank;
break;
case ']':
++brank;
default:
break;
} while (brank > 0);
goto next;
next:
default:
++input;
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment