An implementation in C of the NTFJ language.
The following is copied from the NTFJ README.
NTFJ is a stack-based language that implements a few commands intrinsic to logic. The name comes from the first letters of the original four commands: NAND
, TRUE
, FALSE
, JUMP
.
|
-NAND
- pops two valuesA
andB
and pushesA NAND B
; ifA
andB
are both bits, it pushes1-(A&B)
; otherwise, it pushes255-(A&B)
.~
-FALSE
- pushes0
to the stack.#
-TRUE
- pushes1
to the stack.^
-JUMP
- popsN
, and moves the index pointer to theN
th command.*
-OUT
- popsN
, and outputs the character whose char code isN
.@
-BYTE
- pops eight valuesV1...V8
and pushes the numberV1*(2^8) + ... + V8*(2^1)
OR, ifV1 > 1
, pushes the bits in that number.(
-PEEK
- if the top value of the stack is zero, jumps to the next)
. (Nested loops are not supported as of now.))
-ENDPEEK
- marks the point at which to continue for zero values.$
-DROP
- drops the top value of the stack.:
-DUP
- duplicates the top value of the stack./
-LENGTH
- pushes the number of items in the stack.{
-ROTATE
- pops N; shifts the stack and pushes it to the front N times.}
-REV ROTATE
- pops N; pops from the stack and unshifts it N times.`
- debugging tool; logs the state of the stack to the console.
(We will denote the stack's top element as B
, and the second-to-top element as A
.)
- Negate top of stack:
:|
.- (start)
A B
. - (
:
)A B B
. - (
|
)A (B NAND B)
=A (NOT B)
.
- (start)
- Conjunction (and):
|:|
.- (start)
A B
. - (
|
)A NAND B
. - (
:|
)NOT(A NAND B)
=A AND B
.
- (start)
- Disjunction (or):
:|%:||
- Because
A OR B = (NOT A) NAND (NOT B)
.
- Because