Agentic Compiler is a tiny typed programming language compiler. It lexes, parses, type-checks, lowers to a three-address intermediate representation, emits readable Python code, and can execute either backend.
This is not an agent-plan artifact generator. It is a real compiler pipeline for a small language.
- Lexer with comments, strings, integers, booleans, identifiers, and operators
- Recursive descent parser with Pratt-style expression precedence
- AST dataclasses for statements and expressions
- Static checks for variables, mutability, function calls, lists, returns, loops, and operators
- Three-address IR backend with temporaries, labels,
goto, and conditional jumps - Three-address IR runner for simple WHILE3ADDR-style programs
- Python code generator with safe integer division and forward function references
- CLI:
check,compile,run,ir,run-ir,tokens,ast,repl - Public API:
tokenize,parse_source,check_source,compile_source,run_source,emit_ir_source,run_ir_source - Tested with pytest, ruff, strict mypy, package build, and GitHub Actions
pip install -e .[dev]Create main.ag:
fn fact(n: Int) -> Int {
if n <= 1 {
return 1
} else {
return n * fact(n - 1)
}
}
print(fact(5))
Run it:
agentic-compile run main.ag
# 120Compile it to Python:
agentic-compile compile main.ag --out main.py
python main.pyEmit three-address IR:
agentic-compile ir main.agExample IR for let x: Int = (1 + 2) * 3 print(x):
t0 = 1 + 2
x = t0 * 3
print x
let creates an immutable binding. var creates a mutable binding.
let answer: Int = 42
var total: Int = 0
total = total + answer
Supported types:
IntBoolStringVoidfor functions that do not return a valueList[T], for exampleList[Int]
Empty lists require an annotation:
let xs: List[Int] = []
Functions are checked before top-level code is emitted, so forward references work.
print(add(2, 3))
fn add(a: Int, b: Int) -> Int {
return a + b
}
var total: Int = 0
for i in range(0, 6) {
if i == 4 { break }
if i % 2 == 0 { continue }
total = total + i
}
if total == 4 {
print("four")
} else if total == 1 {
print("one")
} else {
print("other")
}
var xs: List[Int] = [1, 2, 3]
xs[1] = 20
print(xs[1])
print(value)as a statementlen(list)returnsIntstr(value)returnsStringrange(stop),range(start, stop),range(start, stop, step)returnList[Int]
agentic-compile check main.ag
agentic-compile compile main.ag --out main.py
agentic-compile run main.ag
agentic-compile ir main.ag
agentic-compile run-ir main.ag
agentic-compile tokens main.ag
agentic-compile ast main.ag
agentic-compile replfrom agentic_compiler import compile_source, emit_ir_source, run_source
compiled = compile_source('print(1 + 2)')
print(compiled.python_source)
print(emit_ir_source('let x: Int = (1 + 2) * 3 print(x)'))
result = run_source('print(1 + 2)')
assert result.stdout == '3\n'python -m pytest -q
python -m ruff check .
python -m mypy src/agentic_compiler --strict
python -m buildAlpha, but the pipeline is real: source text becomes tokens, AST, checked semantics, three-address IR, generated Python, and executable output.