For detailed insight into the development of Phase, read my blog post.
- Supports functions, conditionals, loops (
while), tuple destructuring. - 5 primitive types (
str,int,float,bool, andvoid). - 21 error types with detailed diagnostics including visual markers and diff-style fix suggestions.
- Implemented fully in C17.
flowchart LR
A(Source Code) --> B(Lexer)
B --> C(Parser)
C --> D(Type Checker)
D --> E(Bytecode Generator)
E --> F(Virtual Machine)
Phase compiles programs into bytecode, executed by a handwritten stack-based VM supporting 25 opcodes.
So this source code:
entry {
out("Hello world!")
}Will compile into this bytecode:
00 00 00 ; OP_PUSH_CONST 0
01 ; OP_PRINT
18 ; OP_HALT- CMake 3.20+
- Compiler that supports C17
-
Clone the repo:
git clone https://github.com/williamalexakis/phase.git cd phase -
Run the automated build script:
Quick Build
./build.sh
Run with
--debugfor the Debug Build or--runto immediately run after building.Or build it manually:
mkdir build cd build cmake .. cmake --build .
| Command | Description |
|---|---|
phase --help |
Display available commands and flags |
phase <file.phase> --tokens |
Display token stream |
phase <file.phase> --ast |
Display AST |
phase <file.phase> --loud |
Display a success message when programs finish |
entry {
out("Hello world!")
}entry {
let (var1, var2): str = ("Hello", "World")
let var3: bool = true
let var4: int = 1
let var5: float = 1.0
}func add(num1: int, num2: int): void {
out(num1 + num2)
}
entry {
add(5, 5)
}entry {
let score: int = 9
if score >= 10 {
out("Excellent")
} else if score > 5 {
out("Good")
} else {
out("Bad")
}
}entry {
let counter: int = 0
while counter < 11 {
out(counter)
counter += 1
}
}- Lexer
- Parser
- Bytecode generator
- VM execution loop
- Token and AST diagnostics
- Floats and booleans
- Error manager
- Declaration keywords & annotations
- Functions
- Conditionals
- Basic loops
Phase is released under the MIT License.
See the LICENSE for full details.



