This repository holds the Python & C interpreters for Rec. (Though I don't want to maintain the Python interpreter anymore.)
rec.c
is a C interpreter of Rec with a REPL and debugger. (You can compile it with a compiler that supports C99.)
rec.py
is my (abandoned) Rec interpreter in Python.
The language is summarized below:
Command | Behavior |
---|---|
123 |
Push the non-negative number onto the stack. |
/ |
Successor; increment TOS. |
\ |
Predecessor; decrement TOS. |
: |
Load; Pops x , pushes stack[~x] . |
; |
Store; Pops v and x . Assigns stack[~x] to v . |
[ ... ] |
Infinite loop; executes ... forever. |
^ |
Pops x . If x == 0 , break out of the innermost [ ... ] loop. (Or terminates program, if not in a [ ... ] loop.) |
Both interpreters here have a REPL (which you can access with no CLI arguments) and a debugger (which you may enter by adding breakpoints b
in the program).
Use Enter to step through the debugger.
You can use Ctrl-D
to exit the REPL or the debugger.
P
: Pop & print TOS as integer.R
: Read an integer from input, and push the value.p
: Pop & print TOS as a char.r
: Read a char from input, and push the ord value.s
: Prints the entire stack at the current point of execution.b
: Breakpoint; starts debugger at this part of program.
\n
: Step to next iteration.c
: Continue execution until the next breakpoint.m
: If current char is[
, hide debugging information until the matching]
.q
: Quit; Exit the debugger. (You can also use Ctrl-D to exit.)
-1
is represented by0\
, not1\
(which is0
)!;
pops 2 values from the stack!- E.g.
[1 2 3 0 1]
: when;
is called, the new TOS is3
, not0
. So this will turn the stack to[1 0 3]
.
- E.g.
:
and;
look similar (and are easily confusable), so be careful.
- Recur interpreter (written by laerling), where you can find some examples of an old version of this language.
- Rec+