A Forth language interpreter implemented in Javascript.
Clone this repo and run npm install
.
Start the interpreter: npm start
Start the interpreter with debugging turned on: npm run debug
Test the interpreter: npm test
.s
- print the stack
+
- add two numbers, ex:1 2 +
=> [3]-
- subtract last num on stack from the second to last num on stack, ex:5 1 -
=> [4]*
- multiply two numbers, ex:7 * 3
=> [21]/
- divide second to last num on stack by the last num on stack, ex:10 5 /
=> [2]
.
- pop from the top of the stackdup
- duplicate top num on stack, ex:3 dup
=> [3, 3]
: definitionName ...;
- define a new operation, ex:: increment 1 +;
if then
- if statement, ex:if 1 then
if else then
- if/else statement, ex:if 1 else 2 then
emit
- output num on top of stack as ascii characters
mod
- modulus
drop
- drop top num from stackswap
- swap the top two nums on the stack
=
- boolean, -1 for true and 0 for false<
- less than>
- greater thanand
- and (bitwise)or
- or (bitwise)invert
- ! (bitwise)do loop
- for loop
variable
- store a variable in memoryconstant
- store an immutable variable in memory
- Improve error handling to prevent crashes when user enters an invalid sequence of words
Pull requests are welcome. Please make sure tests pass before submitting a PR.