Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/felipenugo/cantor-interpreter/llms.txt

Use this file to discover all available pages before exploring further.

Cantor Interpreter implements a small, mathematically-grounded programming language built around Cantor’s pairing function. Every program takes one or more natural numbers as input, encodes them into a single integer using the Cantor pairing function, and returns a natural number. Functions are built by composing a small set of combinators — comp, pair, compair, mu, and primrec — on top of seven built-in primitives.

Installation

Install Python dependencies and generate the ANTLR4 parser in minutes.

Quickstart

Write and run your first Cantor program with a working example.

Language Reference

Understand the grammar, combinators, imports, and extended mode.

Standard Library

Explore the seven built-in functions and Cantor pairing helpers.

What is the Cantor language?

The Cantor language is a minimalist, Turing-complete programming model where all computation is expressed as function composition over natural numbers. There are no variables, no loops, and no data structures — only functions that transform a single natural number into another. Multiple inputs are passed by encoding them with Cantor’s pairing function before execution begins. The language ships with five combinators:
CombinatorDescription
comp f gFunction composition: f(g(x))
pair f gReturns the Cantor pair <f(x), g(x)>
compair f g hShorthand for f(<g(x), h(x)>) — requires extended
mu fMinimization: first k where f(<x, k>) ≠ 0
primrec f g hPrimitive recursion from 0 to x — requires extended
1

Install dependencies

Install Python 3.12, Java 11+, and the ANTLR runtime via pip install -r requirements.txt.
2

Build the parser

Run make to generate the ANTLR4 lexer, parser, and visitor from src/cantor.g4.
3

Run a program

Execute any .cantor file: echo "3 2" | python3 cantor.py tests/programs/phase1-core/suma.cantor
4

Explore examples

Browse the tests/programs/ directory for programs covering arithmetic, boolean logic, division, factorial, and Fibonacci.

Key features

ANTLR4 Grammar

The full language is defined in a single cantor.g4 grammar file, generating the lexer, parser, and visitor automatically.

Cantor Pairing

Multi-argument functions are encoded via Cantor’s elegant bijection between ℕ² and ℕ.

Import System

Compose programs across multiple .cantor files with the import directive.

Test Suite

End-to-end tests using .cantor + .inp + .out triples across six program phases.

Build docs developers (and LLMs) love