- Integer arithmetic:
+
,-
,*
,/
- Stack manipulation:
DUP
,DROP
,SWAP
,OVER
,ROT
- Word definition:
: <word> <body> ;
- Output operations:
.
,EMIT
,CR
,." message"
- Boolean logic:
=
,<
,>
,AND
,OR
,NOT
- Conditional execution:
IF ... THEN
,IF ... ELSE ... THEN
- Stack saved to
stack.fth
after execution - Error messages for common issues:
stack-underflow
,division-by-zero
,invalid-word
, etc.
- Language: Rust (version 1.85)
- Tooling: Cargo
- Testing:
cargo test
(unit + integration tests) - Linting: Clippy (no warnings)
- Formatting:
cargo fmt
- Documentation:
cargo doc
- Platform: Unix / Linux only
❗ No crates,
.unwrap()
,.expect()
,panic!()
,exit()
orunsafe
blocks allowed.
Build the project:
cargo build --release
Run the interpreter with a .fth
file:
cargo run -- path/to/file.fth
Optionally, set a custom stack size in bytes (default: 128 KB):
cargo run -- path/to/file.fth stack-size=262144
: HELLO CR ." Hello, World!" ;
HELLO
Output:
Hello, World!
Final stack is saved to stack.fth
.
Run all unit and integration tests:
cargo test
This project is released under the MIT License. See LICENSE
for details.
This interpreter was developed as part of an individual academic exercise for the subject Taller de Programación I (1C 2025).
The goal was to replicate core features of the Forth-79 standard using only Rust's standard library, without external dependencies, and following strict memory and error-handling guidelines.
For more details, please refer to the enunciado.pdf file.