initial import
This commit is contained in:
parent
6f946cd66e
commit
50e5067215
33
README.md
33
README.md
@ -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
42
blang.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user