EvoX Genesis
EvoX Genesis turns a high-level software objective into a persistent recursive software world: finite-lived agents recursively develop software, while only accepted consequences persist across develop
翻译准备中
尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
在项目文件夹中运行 /nomorevibe verify,即可验证所有权并自行管理介绍。
一分钟完成验证C to Lisp to Forth compiler. Built as a third-year university project.
翻译准备中
取自仓库 README
正在加载完整 README。
查看完整 README ↗
A C to Lisp to Forth compiler that runs in your browser
C to Forth is a two-stage compiler that turns C into Lisp and then Forth, running both in the browser and checking them against clisp, gforth and gcc
It was born as a third-year university project 🎓
flowchart TB
A["C Source"]:::nodeStyle1 --> B["Lexer"]:::nodeStyle2
B --> C["Parser"]:::nodeStyle2
C --> D["Lisp Emitter"]:::nodeStyle3
D --> E["Lisp Code"]:::nodeStyle4
E --> F["S-expression Reader"]:::nodeStyle3
F --> G["Forth Emitter"]:::nodeStyle3
G --> H["Forth Code"]:::nodeStyle4
E --> I["Lisp Interpreter"]:::nodeStyle5
H --> J["Forth Interpreter"]:::nodeStyle5
I --> K{"Same Output?"}:::decisionStyle
J --> K
classDef nodeStyle1 fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
classDef nodeStyle2 fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
classDef nodeStyle3 fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
classDef nodeStyle4 fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
classDef nodeStyle5 fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
classDef decisionStyle fill:#555555,color:#ffffff,stroke:#000000,stroke-width:2px,font-weight: bold;
c-to-forth/
├── .gitattributes # Git Attributes Configuration
├── .gitignore # Git Ignore Rules
├── biome.json # Lint & Format Configuration
├── index.html # Playground Page
├── LICENSE # Project License
├── package.json # Scripts & Dependencies
├── README.md # You are here! ⬅️
├── tsconfig.json # TypeScript Configuration
├── vite.config.ts # Build & Test Configuration
│
├── .github/workflows/
│ ├── ci.yml # Lint & Test Pipeline
│ └── pages.yml # GitHub Pages Deployment
│
├── assets/ # Visual Assets
│ ├── logo.svg # Project Logo
│ └── playground.png # Playground Screenshot
│
├── examples/ # Example C Programs
│
├── public/
│ └── favicon.svg # Playground Icon
│
├── src/
│ ├── compiler/
│ │ ├── lexer.ts # C Tokens
│ │ ├── parser.ts # C Syntax Tree
│ │ ├── lisp.ts # C to Lisp Translation
│ │ ├── sexpr.ts # S-expression Reader & Printer
│ │ ├── forth.ts # Lisp to Forth Translation
│ │ └── reserved.ts # Common Lisp & Gforth Names
│ │
│ ├── runtime/
│ │ ├── lisp.ts # Lisp Interpreter
│ │ └── forth.ts # Forth Interpreter
│ │
│ └── web/ # Playground Editor & Styles
│
└── tests/
├── expected/ # Verified Lisp, Forth & Outputs
├── fixtures/course/ # Original Course Test Programs
├── fixtures/lisp/ # Hand-Written Lisp Programs
├── fixtures/forth/ # Hand-Written Forth Programs
└── *.test.ts # Unit, Golden & Toolchain Tests
Clone the repository
git clone https://github.com/cristiangilsanz/c-to-forth.git
cd c-to-forth
Install the dependencies
npm install
npm run dev
npm test
npm run lint
sudo apt-get install clisp gforth gcc
dist/:npm run build
| C | Lisp | Forth |
|---|---|---|
int x = 5; | (setq x 5) | 5 value x |
int v[] = {1, 2, 3}; | (setq v (vector 1 2 3)) | create v 1 , 2 , 3 , |
x += v[i]; | (incf x (aref v i)) | x v i cells + @ + to x |
printf("%d\n", x); | (format t "~d~%" x) | x 0 .r cr |
if (a < b) ... else ... | (if (< a b) ... ...) | a b < if ... else ... then |
for (int i = 0; i < n; i++) | (dotimes (i n) ...) | n 0 max 0 ?do ... loop |
while (n > 0) ... | (loop while (> n 0) do ...) | begin n 0 > while ... repeat |
switch (d) { case 1: ... } | (case d (1 ...)) | d case 1 of ... endof endcase |
int f(int n) { ... } | (defun f (n) ...) | : f to f.n ... ; |
a / b and a % b | (truncate a b) and (rem a b) | a b quot and a b rem |
| Feature | Details |
|---|---|
| Types | int, char, short, long and bool as integers, arrays with initializers |
| Statements | if, else, while, do while, for, switch, break, continue and return |
| Operators | Arithmetic, comparisons, logic, bitwise, shifts, ?:, assignments, ++, -- and casts |
| Functions | Prototypes, recursion, mutual recursion and array parameters |
| Output | puts, putchar and printf with %d, %c, %s, %% and field widths |
| Extras | Hex, octal and character literals, # lines are skipped and //@ lines go into the Lisp |
| Stage | Details |
|---|---|
| Lisp Interpreter | Numbers, characters, strings, lists, vectors, closures, loop, format and special variables |
| Lisp to Forth | defun, let, cond, case, dotimes, loop with sum and count, block and vectors |
| Forth Interpreter | Colon definitions, do loops, case, defer, value, create, strings and number bases |
The following tips help you get the most out of C to Forth:
- Write a recursive function and see Forth save its locals.
- Edit the Lisp pane and watch the Forth follow.
- Share your code with Copy link.
This project was created together with Paola Herráez Bravo in our third year of university 🤝.
Thanks to the GNU CLISP and Gforth teams for the reference implementations every output is checked against ✨.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with 💖 for the Compiler Community