/bf.c
Created
July 15, 2017 09:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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