gists/first-interpreter
2026-01-14 00:17:24 +02:00
..
src some execute refactor 2026-01-14 00:17:24 +02:00
.gitignore update makefile and readme 2026-01-09 09:49:45 +02:00
Makefile update makefile and readme 2026-01-09 09:49:45 +02:00
program.code my first interpreter 2026-01-03 23:59:53 +02:00
readme.md add structure 2026-01-09 09:55:09 +02:00

My first interpreter

Code for a very simple interpreter.

Accompanying blogpost: https://alloca.space/blog/my-first-interpreter.html

Build and run

Requires: gcc, make

make run

Example Program

sum = 0
counter = 10

while counter {
    sum = add(sum, counter)
    counter = add(counter, negate(1))
}

print(sum)

Structure

  • main.c - entry point. Reads user input and calls the interpreter
  • run.c - glue code. invokes the interpreter stages.
  • ast.h - AST definitions
  • lex.h - Tokens definitions
  • lex.c - Stage 1 - Lexing: Text -> Tokens
  • parsing.c - Stage 2 - Parsing: Tokens -> Ast
  • execute.c - Stage 3 - Execute: Ast -> Output