Marlin Programming Language

A lightweight, statically-typed systems programming language built from scratch featuring a lexer, parser, compiler, and virtual machine.

Lexer → Parser → Abstract Syntax Tree (AST)

The front-end of the Marlin compiler follows a traditional three-stage design, converting raw source code into a structured program representation.

  • Lexer: Converts a character stream into an enumeration of token types- (identifiers, literals, operators, etc.)
  • Parser: Consumes the token stream to produce an Abstract Syntax Tree (AST), representing the syntactic structure of the program

Compiler and Linker

The compiler transforms the AST into executable assembly that can be run on a virtual machine implementing the instruction set

  • Implements a visitor-based traversal to generate assembly instructions from AST nodes
  • Maintains separate memory segments for code and data to support linking and relocation

Language Features

  • Arithmetic expressions, boolean operators, operator precedence
  • Expression-oriented syntax: if statements, loops, and assignments can return values
  • While loops, for loops, and expression loops that return a value upon exit
  • Arrays, pointers, and structs
  • Nested type resolution for hierarchical data structures

Instruction Set

  • Compact, RISC-style instruction set
  • Integer and double-precision arithmetic: ADD, SUB, MULT, DIV, AND, OR, XOR, etc (immediate and register formats)
  • LD/ST instructions for memory accesses with PC-relative and base + offset addressing modes
  • Push/Pop operations to atomically push and pop data from the stack
  • Conditional branches (JMP), function calls (CALL), and returns (RET)
  • PUTC and GETC for character I/O operations
← Back to all projects