First Program

A Karkain program is a .kark file compiled and run through the karkain CLI.

Hello, World!

Create hello.kark:

println("Hello, Karkain!")

Build and run it:

$ karkain run hello.kark
Hello, Karkain!

That is the complete loop. Every Karkain program starts from here.

What just happened

  1. karkain run hello.kark invokes the Go front end (or kcc, depending on configuration) to parse the source.

  2. The parser produces an AST.

  3. The semantic resolver resolves builtins and scope.

  4. The C emitter produces a .c file.

  5. GCC or Clang compiles the C to a native executable.

  6. The executable runs and prints Hello, Karkain! to stdout.

You do not need to understand any of these steps to use Karkain. The CLI handles everything; the pipeline is described in detail in Pipeline Stages.

A second program

Create count.kark:

func count_to(n) {
    let i = 1
    while(i <= n) {
        println(i)
        i = i + 1
    }
}

count_to(5)

Run it:

$ karkain run count.kark
1
2
3
4
5

Key points:

  • Functions are declared with func name(params) { body }.

  • let declares a local variable.

  • while(cond) { ... } is the loop form (parentheses required).

  • println(value) prints to stdout.

  • There is no main function; the top-level scope is the entry point.

What’s next

  • Build — compile to a native executable.

  • Run — compile and execute in one step.

  • Test — write and run tests.

  • Project Layout — organize a real project.