How Bloom Works
A journey from text to pixels on screen
When you write Bloom code and run it, a lot happens behind the scenes. This guide explains the entire journey your code takes, from the moment you type it to the moment shapes appear on your canvas.
- The Lexer — Breaking code into tokens
- The Parser — Building the syntax tree
- The Interpreter — Running your code
- The Bytecode VM — High-performance execution
The Big Picture
Programming languages are like translators. They take something humans can read and turn it into something a computer can execute. Bloom does this in four main stages:
Lexical Analysis
The Lexer reads your code character by character and groups them into meaningful chunks called tokens. It's like breaking a sentence into words.
circle(100, 50, 30)
becomes
IDENTIFIER "circle" LPAREN NUMBER 100 COMMA NUMBER 50 COMMA NUMBER 30 RPAREN
Parsing
The Parser takes those tokens and figures out how they relate to each other, building a tree structure called an Abstract Syntax Tree (AST).
Interpretation
The Interpreter walks through the AST and executes each node. When it sees a function call to circle, it draws a circle on the canvas.
Why This Matters
Understanding how a language works helps you:
- Debug better — Know where errors come from
- Write cleaner code — Understand what the language expects
- Build your own tools — Syntax highlighters, linters, etc.
- Learn other languages faster — The concepts transfer
Two Execution Modes
Bloom has two ways to run your code:
The interpreter is the default because it provides better error messages for learners. The bytecode VM is available for performance-critical code.