"Just open a subscription and you'll have it done in a couple of evenings," a colleague told developer Rodion Gorkovenko (RodionGork) when he decided to build a small scripting language for his text game. The advice made sense, but he chose not to use LLM code generation. Instead of two evenings of prompting, it took a week of hand-coding—and produced ez-code, a transpiler that turns one source file into JavaScript, Perl, PHP, and Python. And compiles itself.
Why write a custom language for a text game
It started with a practical problem. Rodion builds a small text-based game for students (a MiniMUD of sorts) and runs its multiplayer server on ordinary shared hosting. The project originally ran on Perl (after an earlier try on PHP) because shared hosts include those interpreters out of the box with zero ops overhead.
Eventually, he wanted a lightweight single-player version right in the browser. Students could open a local sandbox, write their own rooms and quests, and share stories without needing a central server. Simple in theory, except browsers only run JavaScript while the server code was already in Perl.
Four obvious paths sat in front of him, each hitting an ugly wall:
- Compile Perl to JavaScript or WebAssembly. Possible, but messy—and the output bundles weigh tens of megabytes, which is absurd for a tiny text game.
- Rewrite the server in Node.js so one language runs everywhere. That meant ditching cheap shared hosting, renting a VPS, and managing server ops he didn't want.
- Maintain two parallel branches in Perl and JS. Even with modern AI tools, keeping logic in sync across two repos is tedious and begs for subtle drift.
- Write a direct Perl-to-JavaScript converter. Tempting at first, until you hit Perl's type sigils and array/hash semantics versus JS's scoping and type coercion.
Out of that came a fifth idea: design a small, "averaged" C-like language structured from day one to map cleanly to both Perl and JavaScript. At first Rodion hoped regex replacements would do—the syntaxes looked close enough. One attempt proved how fast regexes collapse on nested expressions. So he wrote a real parser that builds an AST (abstract syntax tree—a tree of operations and blocks rather than raw text). Once the pipeline worked for Perl and JS, adding a PHP generator took two days, and Python fell into place as an experiment soon after.
Live prototype: browser playground and four CLI artifacts
You can try the transpiler in your browser with zero setup via the online playground on GitHub Pages. Because the compiler is rewritten in ez-code itself and compiles to JavaScript, translation runs locally right in the page. It uses Ace Editor with custom syntax highlighting and three built-in examples: Collatz, Primes, and Abracadabra.
Pick an example, choose a target language, click Translate!, and the generated JS, Perl, PHP, or Python code appears below. Clicking Run (JS) transpiles to JavaScript and executes it right in the browser.
For local terminal use, the repo root ships four single-file artifacts: ez-code.pl, ez-code.php, ez-code.py, and browser-targeted ez-code.js. The first three are standalone and only need their host interpreter:
# Transpile a program and run it immediately via Python
./ez-code.py tests/collatz.ez -run
# Save output to a file (target language detected from extension)
./ez-code.pl tests/collatz.ez collatz.js
# Print the intermediate AST as JSON
./ez-code.pl tests/collatz.ez -ast
# Pipe generated JS to stdout and run in Node.js
./ez-code.pl tests/collatz.ez -js | node
Notice the -ast flag: it dumps the internal syntax tree as plain JSON. During development, that's the transpiler's X-ray—you can see how the parser grouped parentheses or nested loops before any target generator touches it.
Sizes of single-file transpiler builds
All four builds weigh roughly the same—smaller than a typical web image. One caveat for ez-code.js: it's built without CLI glue for the web playground, so running it in Node.js from a terminal requires a short wrapper script.
Minimal grammar and why regexes lost to an AST
Why does translating code with regular expressions fail almost immediately? Imagine translating a cooking recipe from Russian to Japanese by swapping words with a dictionary. Step order and grammar fall apart. It's far more reliable to extract a structured outline first—ingredients, steps, conditions—and then write fresh instructions in the target language.
In compilers, that outline is the AST. The parser strips whitespace, comments, and syntax noise to build a clean tree of nodes: function declaration, loop, comparison, assignment. Each code generator then walks the tree and emits valid JS, Perl, PHP, or Python.
Pen-and-ink sketch on textured paper: source code is stripped of syntax noise into a clean AST tree, branching into four streams for JS, Perl, PHP, and Python.
To keep the parser down to a few hundred lines, ez-code uses a blunt, predictable syntax. A program is a flat list of statements, each fitting one of three patterns:
- starts with a keyword (
def,fn,if,elsif,else,while,for,break,cont,ret); - starts with a variable name (optionally indexed), followed by an assignment (
=,+=,-=,.=) and an expression; - starts with a name followed immediately by
(, meaning a standalone function call.
Statements end with semicolons, except conditional blocks and function declarations. Else-if uses Perl's elsif. There is no classic three-part for (i = 0; i < n; i++) loop—for only iterates over array elements or hash keys, largely to keep Python translation simple. Whenever you need a counter, you use while.
# Counting steps in the Collatz conjecture (sequence A006577)
fn collatz(n) {
def cnt = 0;
while (n > 1) {
# Standard ternary operator is supported
n = (n % 2 != 0) ? n * 3 + 1 : n / 2;
cnt += 1;
}
ret cnt;
}
def i = 1;
while (i <= 20) {
writeln(i, " -> ", collatz(i));
i += 1;
}
The C-like syntax is readable at a glance without a manual. Variables use def, functions use fn, returns use ret, and continue shortens to cont. The trade-off for this minimalism is having no classes, modules, or syntactic sugar—yet it proved more than enough for both game logic and the transpiler itself.
Four languages, four quirks: the hardest cross-compilation traps
On paper, all four targets look like cousins: dynamic typing, lists, dictionaries, functions. Run real code through the generator, though, and each runtime's quirks surface fast. It illustrates a universal rule of cross-transpilation: without static types in your source language, you either pull hints from the pickiest target into your syntax or hide differences behind helper functions.
The first wall was Perl's sigils: $ for scalars, @ for arrays, and % for hashes (key-value maps). Without types, ez-code's parser doesn't know if x holds a number or a list. The clever workaround: in generated Perl, all arrays and hashes are stored as scalar references ([] and {}). Every variable starts with a single $, and element access uses $$. Early versions required $ in ez-code source too, though it was later made optional—the compiler now inserts the right number of $ signs for Perl and PHP.
Indexing, however, couldn't be hidden. Perl uses different brackets for array indexing versus hash key lookup. ez-code brought that distinction straight into its own syntax so every generator knows what structure it's touching:
# Square brackets for lists, curly braces for hashes
def arr = [3, 1, 4, "pi"];
def hash = {"number": 314, "name": "pi", "arr": [1, 2, 3]};
writeln(hash{"arr"}[2]);
# String concatenation uses dot, like Perl and PHP
fn mulstr(s, n) {
def res = "";
while (!(n == 0)) {
res .= s;
n -= 1;
}
ret res;
}
Splitting arr[i] and hash{"key"} removes ambiguity across all four targets: Perl gets the exact brackets and dereferencing it needs, while JS, PHP, and Python emit standard square brackets.
Strings and types came next. Perl compares numbers with == and strings with eq. Since an untyped parser can't guess what a and b hold, ez-code provides eq(a, b) and scmp(a, b). If you only target JS, PHP, and Python, == works fine—but for Perl compatibility, stick to the helper.
Python brought its own headache: stricter typing. JS, Perl, and PHP quietly coerce numbers when concatenating strings, whereas Python throws TypeError. So the . concatenation operator automatically wraps both sides in str(...) when targeting Python. Quotes needed care too: double quotes process escapes, while single quotes act closer to raw strings and convert to raw literals for JS and Python when needed.
The sneakiest bugs came from PHP. First, PHP passes arrays to functions by value (copying them), whereas JS, Python, and reference-based Perl pass by reference. Porting the compiler to PHP caused subtle, silent breakage—like extra semicolons appearing after blocks in generated code. Second, PHP and Python require explicit global declarations inside functions, while JS and Perl expose globals automatically.
| Language quirk | JavaScript | Perl | PHP | Python |
|---|---|---|---|---|
| Variable sigils | None | $ ([]/{} refs) | $ before name | None |
| Array / hash access | arr[i] / obj[k] | $$arr[i] / $$h{k} | $arr[$i] / $h[$k] | arr[i] / d[k] |
Concatenation . | + | . | . | str(a) + str(b) |
| Global variables | Visible directly | Visible directly | Auto-global | Auto-global |
| Array passing | By reference | By scalar reference | By value (copy) | By reference |
At first, Rodion planned to make programmers write global by hand even when JS and Perl ignored it. Instead, the code generator learned to detect outer-scope variables and emit global declarations automatically for PHP and Python.
funclib.ez: a universal travel adapter for four runtimes
Syntax alone won't make a program behave identically across four runtimes. How do you get an array's length? JS uses .length, Python uses len(), PHP calls count(), and Perl writes scalar @{$arr}. The same applies to regex matching, substrings, and pushing to a list.
Rather than cluttering ez-code with runtime branches, all core operations live in src/funclib.ez. Think of it as a universal travel adapter: you plug in the same prongs on one side, and the right pins pop out on the other. During compilation, the transpiler prepends lightweight target implementations into the output file.
funclib.ez covers everyday essentials without runtime bloat:
- Strings and regexes:
eq,scmp,slen(length),ss(substring),match,split,subst(search and replace). - Arrays:
len,push,pop,shift,unshift,slice,sort,join,isarray. - Hashes:
keysandhaskey. - I/O and control:
writeln,readln,halt(exit with code/message), andcallname(call function by string name).
Shortly after the initial early-December 2026 release, new commits added multiple assignment (multivar), case helpers (upper, lower), hash key deletion (delkey), tojson, and writelne.
# Snippet of the Perl library table in src/funclib.ez
# Entry format: [ez_name, target_implementation, alias]
push(lb, ['eq', 'sub streq{$_[0] eq $_[1];}', 'streq']);
push(lb, ['haskey', 'sub haskey{defined $_[1]->{$_[0]};}', '']);
push(lb, ['len', 'sub len{scalar @{$_[0]};}', '']);
push(lb, ['push', 'sub apush{push @{$_[0]}, $_[1];}', 'apush']);
Names like writeln, readln, ss, and slen look a bit old-school, reminiscent of Pascal. That's deliberate: they were picked to avoid colliding with built-in functions or keywords in any of the four target languages.
There is also a handy escape hatch: if a function isn't in funclib.ez and isn't declared in the current file, its call passes straight through to the target code unchanged. That lets you call native functions like int(...) or platform wrappers outside ez-code without ceremony.
Self-hosting in a week, sparring with Claude, and honest limits
The best part of the story is bootstrapping—making the compiler compile itself (self-hosting). It sounds like Baron Munchausen pulling himself out of a swamp by his own hair, yet the process is simple. You build wooden scaffolding first (an initial transpiler in another language), lay brick walls around it (rewrite the compiler in the new language), compile the new code with the old one, and tear down the scaffolding.
According to the GitHub commit log, the whole journey took under three weeks and 71 commits. On November 13–15, a tiny Perl prototype landed—it only parsed integers and double-quoted strings, lacked for loops, and only accepted empty hash literals. By November 15 it emitted working JavaScript, PHP followed on the 16th, and Python worked by the 18th–19th.
Once the basics held, Rodion took the ~500-line Perl prototype and spent three days (November 20–23) rewriting the core in ez-code itself: ez2ast.ez (parser), ast2out.ez (code generator), and funclib.ez. By November 29, standalone single-file builds worked for all targets.
Line breakdown of the self-hosted compiler in src/
The entire compiler fits in under a thousand lines across four files. Most of the code sits in the parser and code generator, while CLI argument handling in main.ez stays tiny.
Building new versions is transparent. build.sh checks for stray tabs first, runs all four src/ files through the existing ./ez-code.pl, and glues the output to a short platform stub (a small target-language wrapper that reads files from disk and runs generated code via eval or exec):
# Build standalone ez-code.py using the working ez-code.pl
# -lib bundles library helpers; -bare omits duplicate headers
./ez-code.pl src/funclib.ez -py -lib
./ez-code.pl src/ez2ast.ez -py -bare
./ez-code.pl src/ast2out.ez -py -bare
./ez-code.pl src/main.ez -py -bare
# The script then prepends/appends the stubs/main.py wrapper
The Python stub (stubs/main.py) is under 20 lines. It defines readinput and autorun, which main.ez calls directly thanks to the pass-through rule for unknown functions:
# Minimal platform wrapper for the Python CLI build
def readinput(name):
try:
with open(name, 'r') as f:
return f.read()
except Exception as e:
return ''
def autorun(code):
try:
exec(code, {})
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
exit(1)
res = main(sys.argv[1:], 'py')
if res != '':
with open(outfile, 'w') as f:
f.write(res)
There's a fun hazard in this loop: because ez-code has no static type checking, one typo in the generator can emit a broken compiler that can't rebuild itself anymore. Two lifelines kept things safe: git checkout for instant rollbacks and -ast to inspect the parse tree. Meanwhile, run-tests.sh runs 17 test programs in tests/*.ez across all four targets and diffs their output against expected files (Python even got its own numbers.py.txt due to number formatting quirks).
The LLM angle is interesting too. Rodion skipped AI code generation for two reasons: explaining grammar rules in prompts often takes longer than tweaking a parser directly, and he wanted the pure programming fun (having previously built only an Arduino BASIC interpreter and a custom Lisp). Still, he used Claude as a sparring partner. After finishing a tricky piece locally, he asked Claude to solve the same task from an earlier commit and compared notes. Sometimes the model wrote nearly identical code, sometimes it invented scary hacks like suppressing function-redefinition warnings—and it was Claude that sparked the idea of auto-generating global statements for PHP and Python, which Rodion later implemented his own way.
ez-code is a pre-alpha educational hobby prototype, not a production tool. There is no LICENSE file in the repo yet, so it has no formal open-source license for commercial use without the author's permission. There is no static type checking either: quote, type, or PHP array-copy bugs only surface when running in the target language. Classes, modules, and C-style three-part for loops are missing, and the JS build targets the browser playground (stubs/main.js is empty).
After a week of compiler hacking, the author jokes about a character from a classic children's book who spent a year and a half inventing a chatter-machine and then tried to bolt a vacuum cleaner onto it. Even so, self-hosting proved the language handles real logic cleanly—so the next step is rewriting MiniMUD in ez-code and running it on both the server and the browser.

![Node.JS [ru]](/api/digests/it_development/daily/20261203/assets/sources/we-use-js.jpg?v=a34b354044601fabb4912e246b967631d5d917ecb113e7fb59f759303d2059ee)
