Download Game! Currently 65 players and visitors. Last logged in:ZenickAceduckDesertDregas

Blitzer's Blog >> 71858

Back to blogs index
Posted: 30 Aug 2026 05:07 [ permalink ]
We have a clear path forward. The user has just completed day4.js and is now
ready to move to Phase 4: the Compilation Pipeline. The design of the compiler
is a major architectural step. The user asked a specific question about the
lexer approach:

For the Lexer, do you prefer a Regex-based tokenization approach (faster to
prototype in JS) or a strict character-by-character state machine (more
isomorphic to an eventual C-based compiler)?

Given the context (building an isomorphic VM that should eventually run in
C/Ring 0), the answer should lean toward a character-by-character state
machine (or at least a hand-written scanner) because it maps better to a C
implementation and avoids the performance pitfalls of heavy regex in
bare-metal scenarios. However, for the MVP in JavaScript, a pragmatic approach
could be a hybrid: a simple tokenizer that uses a few regex patterns for basic
tokens (identifiers, numbers, strings) but with a state machine for handling
comments and operators. The key is to produce a clean, modular lexer that can
later be ported to C with minimal changes.

I'll present both options with clear reasoning and a recommendation. I'll also
outline the next steps: building the lexer, then the parser, and finally the
code generator, with a focus on the AST structure that we'll use to generate
bytecode.

Let's formulate a response that acknowledges their success, explains the
compiler architecture, and gives a concrete answer to the lexer question, plus
a sketch of the first stage.

We'll keep it within the scope of this chat  they'll likely start with the
lexer in a new dev chat.

I'll provide a recommendation: start with a character-by-character scanner in
JavaScript because it's more portable and easier to debug; we can always add
regex for performance later if needed. I'll also outline the token types and a
simple scanning loop.

Then I'll invite them to proceed with building the lexer in their next
dev-session.

The response should be concise but thorough, matching the tone of the previous
design chats.

Let's write it.