PT

Nº 12of 22Index

Custom language compiler

Compiler in Java: lexer, recursive-descent parser, tree-walking interpreter and a NASM x86 32-bit assembly generator

Year
2026
Status
SHIPPED
Stack
Java · Assembly x86 · NASM · Docker +1
lp-compiler
CL

Java

No public screen — generated cover

01The project

My own language with Rust-inspired syntax, implemented in Java: lexical analysis, a recursive-descent parser, an AST and two back ends. The tree-walking interpreter covers the whole language — typed variables with mutability, recursive functions with chained lexical scope, structs with nested fields, and if as an expression. The code generator emits 32-bit NASM x86, assembled and run inside a container, and covers only the integer subset: every node with no representation in raw assembly raises an explicit error instead of faking support. The grammar is formalized in EBNF in the repository.

02What was built

  1. Two back ends over the same AST: a tree-walking interpreter with the full language, and a NASM x86 32-bit generator limited to the integer subset, with an explicit error at every unsupported node

  2. Lexical scope as a chain of symbol tables: a block only creates a child scope when it is an explicit block, which preserves the caller's scope in a function's direct body

  3. Automated low-level pipeline: emit the .asm, assemble with nasm, link with gcc -m32 -nostartfiles, and run the ELF32 binary inside a Linux container

  4. Grammar formalized in EBNF with a syntax diagram, evolved over 38 commits under semantic versioning

  5. Case files covering 19 lexical, syntax and semantic error scenarios — division by zero, reassigning an immutable variable, type mismatch

03Decisions

Decision 01

Question: Why two back ends instead of one?

Answer: The interpreter covers the whole language, strings, floating point and structs included. The raw x86 assembly generator has no heap and no string runtime, so instead of emulating what does not fit, every unsupported node raises a named error — the limit is explicit in the code, not hidden behind wrong behavior.

04Stack

  • Java
  • Assembly x86
  • NASM
  • Docker
  • Bash
Next project →Nº 13

Partnership with USP — web application for speech-language pathology