CMSI 3802 Compiler Project

Funk keeps programs on beat.

Funk is a small statically checked language that compiles to JavaScript. It uses music words where they fit, like groove for functions and riff for records, but the main goal is still clarity.

The Story

Funk started from the idea that a beginner-friendly language can still have useful static checks. It should catch off-key mistakes before the program runs, especially bad names, wrong types, broken function calls, and unsafe field access.

The language is intentionally small. It has enough features to write real examples, but the compiler is still readable: parse the source, analyze it, optimize it a little, and generate JavaScript.

The vibe is record-store poster more than spaceship dashboard. A few silly words make it memorable, while the compiler still behaves like a normal course project.

What Funk Checks

Static types for numbers, booleans, strings, arrays, optionals, and riffs.

Scope checks so undeclared names and same-scope redeclarations are caught.

Function calls must match their groove signatures.

Returns, breaks, array indexing, and field access are checked before generation.

The encore; easter egg wraps generated code so the whole program runs twice.

Small Grooves

Hello

groove main() -> void {
  play("Funk is on the one.");
}

main();

Riffs

riff Track {
  title: string;
  beats: [number];
}

let opener: Track = new Track {
  title: "Flashlight",
  beats: [1, 2, 3, 4]
};

Optionals

riff Song {
  title: string;
  guest: maybe string;
}

groove hasGuest(song: Song) -> boolean {
  return song.guest != none;
}

Loops

groove total(beats: [number]) -> number {
  let sum: number = 0;
  for beat in beats {
    sum = sum + beat;
  }
  return sum;
}

Control Flow

groove countDown(start: number) -> void {
  let count: number = start;
  while count > 0 {
    count = count - 1;
  }
  play("drop");
}

Encore

encore;

groove shout() -> void {
  play("one more time");
}

shout();

Developer

James McCrystal built Funk as a compiler project for Languages and Automata II. The fun part was making the language small enough to finish, but checked enough to feel like a real compiler.