Pico
Pico is a two symbol language by User:Salpynx inspired by Picofuck, BF instruction minimalization, and the concept of Simple translation. It is meant to simulate bf and a range of bf-like languages, with only two symbols.
It operates and is defined in terms of a series of wikipedia:finite state transducers.
Overview
The language Pico consists of two symbols: [
and ]
.
The following tables define finite state transducers which map input : output symbols from one language to another.
State | Input | Output | Transition |
---|---|---|---|
0 | ε | T, P, C = {}, 0, 0 def pico(*a): global T, P, C r, T[P], P, C = (lambda x: (*x, x[0] != 0) if len(x) > 2 else (None, *(max(0, v) for v in x), 0))(([ lambda a,v: ((2 * C - 1) * (not len(a)) or (len(a) < 2 and a[0] + a[0]//abs(a[0])) or (a, 0)[a[0] < 0], v, P), lambda a,v: (1 - v if a[1] == 1 else v + 2 * a[1] - 5, P), lambda a,v: (v, P - 1), lambda a,v: (v, P + 1), lambda a,v: (v, print([bool, int, chr][a[1] - 1](v), end='') or P), lambda a,v: ([bool, int, lambda s: s and ord(s[0]) or 0][a[1] - 1](input('>')), P) ][((len(a) < 2) or (max(1, 0 - a[0]))) - 1](a, T.get(P, 0)))) if r != 0: return r while (bool(T.get(P, 0)) == a[1][r] - 1 and ([pico(-c, a) for c,a in a[1][2:]] or 1)): r = 1 |
1 |
1 | [ |
pico( |
1 |
1 | ] |
), |
1 |
State | Input | Output | Transition |
---|---|---|---|
0 | - |
[[[]][[]]] |
0 |
0 | + |
[[[]][[[]]]] |
0 |
0 | < |
[[[[]]][]] |
0 |
0 | > |
[[[[[]]]][]] |
0 |
0 | . |
[[[[[[]]]]][[[]]]] |
0 |
0 | , |
[[[[[[[]]]]]][[[]]]] |
0 |
0 | [ |
[[][[[]][[]] |
0 |
0 | ] |
]] |
0 |
Like the bf transducer except replace this input: | |||
---|---|---|---|
State | Input | Output | Transition |
0 | [ |
[[][[][[]] |
0 |
State | Input | Output | Transition |
---|---|---|---|
0 | + |
[[[]][]] |
0 |
0 | < |
[[[[]]][]] |
0 |
0 | > |
[[[[[]]]][]] |
0 |
0 | ( |
[[][[[]][] |
0 |
0 | ) |
]] |
0 |
Examples
Hello World!
Running a bf Hello World! through the bf:Pico transducer converts
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
into
[[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[][[[]][[]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[][[[]][[]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[[[]]][]][[[[]]][]][[[[]]][]][[[]][[]]]]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[]]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[][[[]][[]][[[[]]][]]]][[[[]]][]][[[]][[]]]]][[[[[]]]][]][[[[[]]]][]][[[[[[]]]]][[[]]]][[[[[]]]][]][[[]][[]]][[[]][[]]][[[]][[]]][[[[[[]]]]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[[]]]]][[[]]]][[[[[[]]]]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[[]]]]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[[[[]]]]][[[]]]][[[[]]][]][[[]][[]]][[[[[[]]]]][[[]]]][[[[]]][]][[[[[[]]]]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[[]]]]][[[]]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[[[[]]]]][[[]]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[]][[]]][[[[[[]]]]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[[[]]]]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[[[[]]]]][[[]]]]
Feeding this Pico code through the Pico:Python transducer we get:
T, P, C = {}, 0, 0 def pico(*a): global T, P, C r, T[P], P, C = (lambda x: (*x, x[0] != 0) if len(x) > 2 else (None, *(max(0, v) for v in x), 0))(([ lambda a,v: ((2 * C - 1) * (not len(a)) or (len(a) < 2 and a[0] + a[0]//abs(a[0])) or (a, 0)[a[0] < 0], v, P), lambda a,v: (1 - v if a[1] == 1 else v + 2 * a[1] - 5, P), lambda a,v: (v, P - 1), lambda a,v: (v, P + 1), lambda a,v: (v, print([bool, int, chr][a[1] - 1](v), end='') or P), lambda a,v: ([bool, int, lambda s: s and ord(s[0]) or 0][a[1] - 1](input('>')), P) ][((len(a) < 2) or (max(1, 0 - a[0]))) - 1](a, T.get(P, 0)))) if r != 0: return r while (bool(T.get(P, 0)) == a[1][r] - 1 and ([pico(-c, a) for c,a in a[1][2:]] or 1)): r = 1 pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(),pico(pico(pico(),),pico(pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(),pico(pico(pico(),),pico(pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(),),pico(pico(),),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(),pico(pico(pico(),),pico(pico(),),pico(pico(pico(pico(),),),pico(),),),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(),),pico(pico(),),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(),),),pico(),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(),),pico(pico(),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(),),),),pico(),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(),),pico(pico(pico(),),),),pico(pico(pico(pico(pico(pico(),),),),),pico(pico(pico(),),),),
Which outputs
Hello World!
as expected. This demonstrates that the bf, Pico, and Python code resulting from these transducers are all functionally equivalent.
Cat
[[[[[[[]]]]]][[[]]]][[][[[]][[]][[[[[[]]]]][[[]]]][[[[[[[]]]]]][[[]]]]]]
Unfortunately, being specified using Python and its built in input()
function which accepts a string at a time, each input character must be followed by a newline character to be recognised, otherwise only the first character of the string will be stored. This may be modified in future, but will likely require a Python import
.
bf interpreter
Converting Daniel B. Cristofani's Dbfi self-interpreter into pico:
dbfi.pico:
[[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[][[[]][[]][[][[[]][[]][[[]][[]]]]][[[[[]]]][]][[[[[]]]][]][[][[[]][[]][[[]][[]]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[][[[]][[]][[[[]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[[]]][]][[[]][[]]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[][[[]][[]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[]]][]][[[[]]][]][[[]][[]]]]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[[[]]]]]][[[]]]][[[[]]][]][[[]][[[]]]][[[]][[[]]]][[][[[]][[]][[][[[]][[]][[[[[]]]][]][[][[[]][[]] [[[]][[]]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[[]][[]]]]][[[[]]][]][[][[[]][[]][[[[]]][]]]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]]]][[[[[]]]][]][[][[[]][[]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[]]][[][[[]][[]][[][[[]][[]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[]]]]][[[[[]]]][]]]][[[[]]][]][[][[[]][[]][[][[[]][[]][[][[[]][[]][[[]][[]]]]][[[[]]][]]]][[[]][[[]]]][[[]][[[]]]][[[[]]][]][[[]][[]]][[][[[]][[]][[[[]]][]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[][[[]][[]][[[[]]][]][[[]][[]]][[[[[]]]][]][[[]][[]]]]][[[[[]]]][]][[[[[]]]][]]]][[[[[]]]][]][[[[[]]]][]]]]]][[[[]]][]][[[[]]][]] ]][[[[]]][]]]][[[[]]][]][[][[[]][[]][[][[[]][[]][[[[]]][]]]][[[[[]]]][]][[][[[]][[]][[][[[]][[]][[[[[]]]][]]]][[[[[]]]][]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]]]][[[]][[[]]]][[][[[]][[]][[[[]]][]][[[[]]][]]]][[[[]]][]][[][[[]][[]][[[[]]][]]]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[]]]]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]]]][[[]][[[]]]][[][[[]][[]][[[]][[]]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[[[]]][]][[[[]]][]][[][[[]][[]][[][[[]][[]][[[[]]][]][[[[]]][]]]][[[[]]][]][[][[[]][[]][[[[]]][]]]][[[]][[[]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[[[]]][]][[[]][[]]][[][[[]][[]][[[[[]]]][]][[[]][[]]][[[]][[]]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[[[]]][]][[[]][[]]][[][[[]][[]][[[[[]]]][]] [[[]][[[]]]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[[[]]][]][[[]][[]]]]]]]]][[[[[]]]][]][[][[[]][[]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[]]]]][[[[]]][]]]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[]]][[[]][[]]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]]]][[[[[]]]][]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]]]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[][[[]][[]][[][[[]][[]][[[[]]][]]]][[[[]]][]]]][[[[[]]]][]][[][[[]][[]][[][[[]][[]][[[[]]][]][[[[]]][]]]][[[[]]][]][[][[[]][[]][[[[]]][]]]][[[]][[[]]]][[][[[]][[]][[[]][[]]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[]]][[][[[]][[]][[[[]]][]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[]][[[]]]][[[]][[[]]]][[[[[]]]][]][[[]][[]]] [[][[[]][[]][[[[]]][]][[[]][[]]][[[[[]]]][]][[][[[]][[]][[[[]]][]][[[[]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[]]]]]]]]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[]][[[]]]][[[[]]][]][[[]][[]]]]][[[[[]]]][]]]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]]]][[[[[]]]][]]]][[[[[]]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]]]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[]][[]]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[[]]]]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]] [[[[[]]]][]][[[]][[]]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[[[[[]]]]]][[[]]]][[[[[]]]][]][[[[[]]]][]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[[[]]]][]][[[]][[[]]]][[[[[]]]][]]]][[[[]]][]][[[[]]][]][[][[[]][[]][[[]][[[]]]][[[[]]][]][[[[]]][]]]][[[[]]][]]]]
We can test it using the shell script interpreter with program and input separated by a !
, and every character followed by a newline:
./pico.sh dbfi.pico < <(echo -e ',[.,]!'"It's a cat program"'!\n' | fold -w1 )
Results in:
>>>>>>>I>t>'>s> >a> >c>a>t> >p>r>o>g>r>a>m>!>
Where each >
is a request for a single input character. The bf code can be modified to demonstrate the code is really being interpreted:
./pico.sh dbfi.pico < <(echo -e ',[.-]+[..,]!'"It's a cat program"'!\n' | fold -w1 )
>>>>>>>>>>>>>IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! � >tt>''>ss> >aa> >cc>aa>tt> >pp>rr>oo>gg>rr>aa>mm>!!>
Interpreter
#!/bin/bash # Pico Interpreter. Requires Python. python <(cat << EOF T, P, C = {}, 0, 0 def pico(*a): global T, P, C r, T[P], P, C = (lambda x: (*x, x[0] != 0) if len(x) > 2 else (None, *(max(0, v) for v in x), 0))(([ lambda a,v: ((2 * C - 1) * (not len(a)) or (len(a) < 2 and a[0] + a[0]//abs(a[0])) or (a, 0)[a[0] < 0], v, P), lambda a,v: (1 - v if a[1] == 1 else v + 2 * a[1] - 5, P), lambda a,v: (v, P - 1), lambda a,v: (v, P + 1), lambda a,v: (v, print([bool, int, chr][a[1] - 1](v), end='') or P), lambda a,v: ([bool, int, lambda s: s and ord(s[0]) or 0][a[1] - 1](input('>')), P) ][((len(a) < 2) or (max(1, 0 - a[0]))) - 1](a, T.get(P, 0)))) if r != 0: return r while (bool(T.get(P, 0)) == a[1][r] - 1 and ([pico(-c, a) for c,a in a[1][2:]] or 1)): r = 1 $(sed "s/[^][]//g;s/\[/pico\(/g;s/]/),/g" ${1:-/dev/stdin}) EOF )