Download Game! Currently 107 players and visitors. Last logged in:DivDeinoPasigulaMunkki

Blitzer's Blog >> 71980

Back to blogs index
Posted: 03 Sep 2026 20:45 [ permalink ]
As long as we keep the AST program fully generic and language-agnostic, we can
later make great use of it for a great many projects.

==
We must remember not to bind it too tightly for JS only. 

One VERY important end-use is, to be able to use the AST tree as a
documentation source, and eventually allowing us to re-design AST flows and
optimize them, in a universal scale of vie, and design entire meshes, their
processes and interconnections.

==


user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/while.cB
[1] Loading tests/while.c...
[2] Executing reference binary (tests/while)...
[3] Compiling LPC to JS via port...
B B B B B B B B B B B B B B B B tokens[i].post = 1; i--;
B B B B B B B B B B B B B B B B B B B B B B B B^

TypeError: Cannot set properties of undefined (setting 'post')
B B at GDCompiler.resolve_precedences (/home/user/Downloads/Remote/LPC/GEM/harn
ess.js:122:48)
B B at GDCompiler.tokenize_data (/home/user/Downloads/Remote/LPC/GEM/harness.js
:277:63)
B B at GDCompiler.compile (/home/user/Downloads/Remote/LPC/GEM/harness.js:364:3
2)
B B at runSideBySideTest (/home/user/Downloads/Remote/LPC/GEM/harness.js:505:31
)
B B at Object.<anonymous> (/home/user/Downloads/Remote/LPC/GEM/harness.js:529:1
)
B B at Module._compile (node:internal/modules/cjs/loader:1871:14)
B B at Object..js (node:internal/modules/cjs/loader:2002:10)
B B at Module.load (node:internal/modules/cjs/loader:1594:32)
B B at Module._load (node:internal/modules/cjs/loader:1396:12)
B B at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)

Node.js v24.18.1

user@elli:~/Downloads/Remote/LPC/GEM$ ls -l harness.js
-rw-r--r-- 1 user user 23827 SepB 3 20:41 harness.js
user@elli:~/Downloads/Remote/LPC/GEM$ wc harness.js
B 529B 2545 23827 harness.js
user@elli:~/Downloads/Remote/LPC/GEM$B
user@elli:~/Downloads/Remote/LPC/GEM$B

==

Your vision for the architecture is completely correct. Keeping the AST pure,
generic, and language-agnostic is the ultimate goal. A robust AST acts as a
universal intermediate representation (IR) that you can use to generate C,
emit JavaScript, build automated documentation, analyze control flows, or
eventuallyas you mentionedtranspile directly down to x86/ASM opcodes. The
backend code generators should be nothing more than "viewers" consuming this
generic tree.

The error you hit is a classic array mutation trap!

What Went Wrong
When you evaluate an expression like i++, the token array looks like this: [
{type: 'variable', source: 'i'}, {type: 'operator', operator: '++'} ].

When the resolver hit the ++, it ran tokens.splice(i - 1, 1) to yank the i
variable out of the array and attach it to the ++ token. But doing this
shifted all the remaining elements left by one. The ++ token, which used to be
at tokens[1], suddenly became tokens[0]. When the code then tried to write
tokens[i].post = 1 (where i was still 1), it crashed because tokens[1] no
longer existed!

The Fix
We need to grab a reference to the operator token before we start slicing
elements out of the array around it.