https://github.com/githubprankster/forward
The (Extremely) Minimal Forth Interpreter in C.
https://github.com/githubprankster/forward
c challenge forth interpreter minimal
Last synced: 11 months ago
JSON representation
The (Extremely) Minimal Forth Interpreter in C.
- Host: GitHub
- URL: https://github.com/githubprankster/forward
- Owner: GithubPrankster
- License: mit
- Created: 2020-05-29T17:48:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T23:56:48.000Z (about 6 years ago)
- Last Synced: 2025-07-14T22:43:33.725Z (12 months ago)
- Topics: c, challenge, forth, interpreter, minimal
- Language: C
- Size: 5.86 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Forth Oriented Rational Wacky Arithmetic Reason Determinator
An interpreter of the bare essentials of Forth in 150~ lines.
Supported are the usual arithmetic operations, a few stack/print ones and the heart of Forth, names. Support for arrays and branching has yet to be figured out.
### Compiling & Time
`gcc -Ofast -march=native -mtune=native -s -static -static-libgcc forward.c -o forward`
Compilation on a AMD FX-8350 yielded a time of:
```
real 0m0.163s
user 0m0.118s
sys 0m0.045s
```
### Example
```forth
: STAR 42 EMIT ;
: LINE STAR STAR STAR STAR STAR ;
LINE CR STAR CR LINE CR STAR CR STAR CR
```
This shall give you a nice F.
### Implementation of Names
I made a structure which contains the name itself and what follows after until `;`. Then whenever the evaluator finds a letter, it checks against the currently stored names, and if a match is found, *it evaluates the name's buffer*. The fact this process is recursive highlights one of the powers of Forth. Currently however, replacement of pre-defined names is not implemented. Be careful making names that are already pre-defined in the interpreter. Or not, that's your call.