Skip to content

Commit 92b242f

Browse files
committed
Update README with a motivations paragraph
Replace ASCII art with bullet points
1 parent 4f1852f commit 92b242f

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# ccforth
22

33
ccforth is a Forth to C compiler written in Go. It interprets
4-
compile-time Forth (immediate words, metaprogramming) and emits
4+
compile-time Forth (immediate words, meta-programming) and emits
55
flattened C11 code that is compiled with gcc or clang to produce
66
standalone executables.
77

88
- GitHub: https://github.com/ncw/ccforth
99

10+
ccforth was written to explore the idea of having an interpreter and a
11+
compiler running simultaneously to enable meta-programming heavy Forth
12+
programs to be compiled into C. This is harder than it sounds because
13+
Forth cannot be ahead-of-time compiled by parsing alone; programs
14+
routinely execute code at compile time. The project was also an
15+
experiment in how far an AI agent could progress a compiler project -
16+
most of the initial implementation was done by Claude Opus 4.6. Go was
17+
used as the implementation language as it is low enough level to
18+
express Forth properly but easier to write than C. C was used as a
19+
compiler backend as C compilers optimize well and are available
20+
everywhere.
21+
1022
## Features
1123

1224
- **Fast compiled output** — generates optimised C11, compiled with
@@ -44,28 +56,16 @@ standalone executables.
4456

4557
## How it works
4658

47-
```
48-
.fth source
49-
|
50-
v
51-
+-----------+ +-------------+ +--------------+
52-
| Scanner |-->| Interpreter |-->| C Emitter |
53-
| (lexer) | | (executes | | (generates |
54-
| | | immediate | | flattened C |
55-
| | | words, | | from word |
56-
| | | builds | | bodies) |
57-
| | | dictionary)| | |
58-
+-----------+ +-------------+ +------+-------+
59-
|
60-
self-contained output.c <------+
61-
(runtime inlined)
62-
|
63-
v
64-
gcc / clang (C11)
65-
|
66-
v
67-
standalone executable
68-
```
59+
1. **`.fth` source** is read by the **Scanner** (lexer), which
60+
tokenises it.
61+
2. The **Interpreter** executes immediate words and metaprogramming,
62+
building a dictionary of word bodies.
63+
3. The **C emitter** walks the finished dictionary and generates
64+
flattened C from the word bodies.
65+
4. The result is a self-contained **`output.c`** with the runtime
66+
inlined.
67+
5. **gcc / clang** compiles that C11 source into a **standalone
68+
executable**.
6969

7070
Forth source is processed by the **interpreter**, which executes
7171
immediate words (like `IF`, `DO`, `:`, `;`) and allows the normal

0 commit comments

Comments
 (0)