Skip to content

Language Guide

Test User edited this page Mar 28, 2026 · 2 revisions

Language Guide

Reference

Language Reference

This document defines the currently supported KodPix syntax.

Program Structure

  • Top-level functions
  • Class blocks (entrypoint bridge through Main.main)

Function Declarations

Supported forms:

function int add(int a, int b) {
    return a + b;
}
function main(a: int, b: int) -> int {
    return a + b;
}

Parameters

  • Preferred: type name
  • Compatibility: name: type

Types

  • int, float, string, boolean, char, void

Statements

  • Variable declaration: type name = expr;
  • Return: return expr;
  • Branching: if (...) { ... } else { ... }
  • Looping: while (...) { ... }, for (...; ...; ...) { ... }

Operators

  • Arithmetic: + - * / %
  • Comparison: == != < <= > >= === !==
  • Logical: && || !
  • Increment: i++, i--

Entry Point

Supported entry forms:

function int main() {
    return 0;
}
class Main {
    public void main() {
        return;
    }
}

Notes

  • Semicolons are required.
  • Conditions are intended to be boolean-strict.

Cookbook

Cookbook

Practical patterns for common KodPix tasks.

Add Two Numbers

function int add(int a, int b) {
    return a + b;
}

Runnable variant:

function int main() {
    int a = 7;
    int b = 5;
    int sum = a + b;
    return sum;
}

Quick run:

./scripts/run_kdx.sh examples/add_two_vars.kdx

Increment Counter

function int main() {
    int i = 1;
    i++;
    i++;
    return i;
}

Conditional Return

function int main() {
    int x = 0;
    if (x == 0) {
        return 0;
    }
    return 1;
}

While Loop

function int main() {
    int x = 0;
    while (x < 3) {
        x++;
    }
    return x;
}

Class Main Entrypoint

class Main {
    public void main() {
        println("hello");
        return;
    }
}

Clone this wiki locally