A complete Scheme programming language interpreter built from scratch in C. This interpreter can parse, evaluate, and execute Scheme code with support for functions, variables, arithmetic, and list operations.
It can execute the following constructs:
- Lambda functions
- In-place lambda function calls
- define
- Arithmetic + - * / operations
- Logical operations and and or
- if/else
- List functions: car, cdr, cons, map, append
- List description without execution: ‘(1 2 3)
- Execution functions: apply, eval
- Recursive function execution
- Helper functions: null?, length
- equal?
- load
gcc -o scheme interpreter.c
./schemeThe interpreter handles memory allocation and cleanup automatically.
The interpreter processes code in three stages:
- Tokenization: Breaks input into pieces (numbers, symbols, parentheses)
- Parsing: Builds a tree structure from tokens
- Evaluation: Executes the parsed code
Run the included test suite:
> (load "tests.scm")The test file demonstrates all supported features with working examples.
- Language: Pure C (no external dependencies)
- Memory: Dynamic allocation with cleanup
- Lambda functions and closures
- Recursive function calls
- Proper list handling
- String parsing with escape sequences
- Multiple number types (int, float, rational)
- File loading and execution
The main interpreter file contains:
- Token handling (
TokenList,tokenize_input) - Data types (
datastruct with union for different types) - Environment management (
Env,lookup,add_elements_to_environment) - Parser (
parse_func,parse) - Evaluator (
evalfunction) - Built-in functions (
cons_builtin,car_builtin, etc.)