Programming Puzzle Language.
This is a stack based sequential programming language. A language lacking in syntactic sugar.
Currently Interpreted with perl. Candidate for translation to C or assembly.
1push 1 onto the current stackXpush X (see Registers) onto the current stack12push 1, then push 2 onto stack12+the '+' adds the top 2 items, pushes result12+?the '?' pops the top and prints the result1!prints '1' without a line-feed#99?prints '99', numbers > 9 require '#' prefix5Rcreates the range 5,4,3,2,1 onto stack5_creates the range 4,3,2,1,0 onto stack1m?'m' unary negation5n5Ocreates the range 5,4,3,2,1,0,-1,-2,-3,-4,-5 on stack12W!?'W' swaps the top two stack elements, prints 1,21D+?'D' duplicates top stack element, prints 23r?'r' unary square rootSreplace the stack with its sumPreplace the stack with its product5RP?gives 120, 1 * 2 * 3 * 4 * 5a,b,cset to alternate stacks, 'a' is the default stackCbcartesian product of current stack with 'b', also Ca,Cc5Rb3_Ca(!?)outputs 15 elements of (1..5) x (0..2)
A,X,Y,Z are specialized registers
- 'A' manages stack interactions
- 'Z' is a counter
- 'X', 'Y' are general purpose
1=push 1, then pop 1 into A1=xsame, but then set X to the value of A12!?prints...2 112=x=XA!?swaps the top two stack elements, the hard way (see W)push 1,push 2,pop 2 into A,X <- A,pop 1 into A, (stack is now empty)push X (2),push A (1),pop and print 1,2
0=zset z to 0iincrement zddecrement zppop and add to z
(pushes PC and stack frame pointer to loop stack)if stack is empty,- pop loop stack, no-op, continue past loop structure
- otherwise:
- pop PC and stack frame pointer from loop stack, this jumps back to the character right after the '('
{pop value off stack, if non-zero (true)- continue execution, into 'then' portion, immediatly follows.
- otherwise
- if zero, skip to the '|' or the '}' and continue there
- Note that nesting is allowed
|if we naturally arrive here, skip to the next unmatched '}'}no-op on execution, only used as a reference for '{', '|'(?)loops printing each stack element until stack is empty{?|?}true,false actions, in this case print on both true and false{?}true action, pull item off stack, if true, pull another and print it
5R(?)print 1,2,3,4,5 note that '?' consumes a stack element1{#10|0}?print 100{#10|0}?print 03_(=bA{1|0})bSmap 2,1,0 (stack a) to 1,1,0 (stack b), and then sum stack b Note that interpreting the ')' puts the stack frame back to 'a', which was the stack frame at the '('
candy -e 'inline-short-form-candy' # only short form candy
candy -f filename.candy # only long form candy
OR
candy filename.candy # only long form candy
candy -e 'short-form' -L # convert to long form
candy -d file.candy # produce debug output
candy -i 1,2,100 # parameters are placed onto the stack before execution
candy -I "text input" # ordinals are placed onto the stack before execution
candy --help # see all options
candy -e '"hello, world\n"(;)'
hello, world
looped Hello, World:
candy -i 5 -e 'R(pb"hello, world\n"(;))'
hello, world
hello, world
hello, world
hello, world
hello, world
candy -i 5 -e '~TbAT1C(sWs+Aeh)Z'
candy -i 0,25 -e 'O(0=z~pcA~TbAT2C(sWs+Aeh)Z?)'
candy -i 12 -e '~xR(XW%nh)Z'
see div.candy in this distribution
- between operator
- incr Y
- zip
- search stack
- heap (?)
- queue operations
- sleep
- smoother stack transitions (ie. nextStack, prevStack)
- reserved stack for program input
- dedup (?)
- counter operations for Y as well
| OP | Long Op | details |
|---|---|---|
? |
println | |
p |
||
; |
printChr | |
: |
getc | read a character from STDIN |
~ |
peekA | |
= |
popA | |
A |
pushA | |
X |
pushX | |
Y |
pushY | |
Z |
pushZ | |
0..9 |
digit0-9 | |
N |
digit 10 | |
# |
number | used to declare numbers > 9 |
x |
XGetsA | |
y |
YGetsA | |
z |
ZGetsA | |
i |
incrZ | |
d |
decrZ | |
h |
popAddZ | |
j |
jumpSub | |
g |
goto | |
. |
retSub | |
@1 |
label | |
D |
dupl | |
m |
negate | |
H |
random | Heisen-value |
r |
root | |
s |
sqr | |
L |
floor | |
! |
not | |
e |
equal | |
< |
less than | |
> |
greater than | |
w |
between | 132w is true; inclusive |
+ - * / % |
add,sub,mult,div,mod | |
B |
bin | convert to binary string |
I |
int | convert to integer string |
W |
swap | |
O |
rangeP | range using a pair off the stack |
_ |
range0 | range starting at 0 |
R |
range1 | range starting at 1 |
T |
range2 | two sided range -v to +v |
S |
sum | |
P |
prod | |
o |
sort stack | _o_rdering |
F |
find | search stack, return 0 or 1 (unimplemente) |
& |
stackSz | push size of stack onto stack |
C |
cart | cartesian product |
|
zip | zip lists (unimplemented) |
a |
stack0 | |
b |
stack1 | |
c |
stack2 | |
K |
getSP | push current stack frame id onto stack |
k |
setSP | pull next frame id from stack |
{ |
if | |
| ` | ` | else |
} |
endif | |
( |
while | |
) |
endwhile | |
|
noOp | includes space, tab and linefeed |
flpqtuw |
future | |
EGHJMQUV |
future | |
$^[]\', |
future |