initial import

This commit is contained in:
dtb 2022-12-08 23:45:46 -05:00
parent 6f946cd66e
commit 50e5067215
2 changed files with 73 additions and 2 deletions

View File

@ -1,3 +1,32 @@
# blang
```
_ _ _
| | / | / /
| |__| ||__ _ _ __ __ _ / /
| '_ | |/ ' | '_ \ / _' | / /
| \_|| | || | | | | /_| | /_/
\___/_____/___| |__,_ / _
|____/ */
```
# blang!
the bang language
bang language
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
<H><e><l><l><o><,>< ><w><o><r><l><d><!><
>^%$
```

42
blang.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
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;
}