diff --git a/README.md b/README.md index 1e6b6b9..ff79cdd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,32 @@ -# blang +``` + _ _ _ +| | / | / / +| |__| ||__ _ _ __ __ _ / / +| '_ | |/ ' | '_ \ / _' | / / +| \_|| | || | | | | /_| | /_/ + \___/_____/___| |__,_ / _ + |____/ */ +``` +# blang! +the bang language -bang language \ No newline at end of file +Public domain. 2022 DTB. + +# Examples + +## true(1) +``` +^ ; initialize state to 0 +% ; store state (0) into *stack +; stack is destroyed, state becomes the final value of *stack +; when the stack is destroyed, the program exits with the value of state +$ +``` + +## Hello world: +``` +; the <.> construct uses '<' to store the next value literally into state, +; does so, and uses '>' to output state literally +<,>< >< +>^%$ +``` diff --git a/blang.c b/blang.c new file mode 100644 index 0000000..55f7ff9 --- /dev/null +++ b/blang.c @@ -0,0 +1,42 @@ +#include +#include + +static unsigned char get = 0; +static unsigned char _stack[4]; +static unsigned char *stack = _stack; +static unsigned char *state; + +int main(){ + int c; + while((c = getchar()) != EOF){ + if(stack == (unsigned char *)0) + return (char)state; + if(get){ + state = (char *)c; + get = 0; + continue; + } + switch(c){ + case ' ': + case '\n': + case '\r': + case '\t': + case '\v': + break; + case '!': state = stack; break; + case '$': stack = state; state = (char *)*_stack; break; + case '%': *stack = (char)state; break; + case '^': state = (char *)0; break; + case '+': ++(char)state; break; + case '-': --(char)state; break; + case '>': putchar((char)state); break; + case '<': get = 1; break; + case ':': + while((c = getchar()) != '\n') + if(c == EOF) + goto fin; + break; + } + } +fin: return 1; +}