Static Checks &
Constraints
Every InfantJS program is analyzed at compile time before a single line runs. Here is every rule the compiler enforces.
InfantJS uses a static analyzer that walks the AST before code generation. If any of the constraints below are violated, the compiler halts with a clear error message pointing to the exact line and column — no silent failures, no runtime surprises.
| # | Check | Example Error Caught |
|---|---|---|
| 01 | Undefined variable reference | gibberish(x) before mine x = ... |
| 02 | Variable redeclaration in same scope | mine x = 1 then mine x = 2 |
| 03 | Assignment to undeclared variable | x = 5 without a prior mine x = ... |
| 04 | Type mismatch on assignment | mine x = 1 then x = gaagaa |
| 05 | Non-boolean in peekaboo condition |
peekaboo 1 { ... } |
| 06 | Non-boolean in wawawa condition |
wawawa 1 { ... } |
| 07 | Non-number in arithmetic expression | gibberish(gaagaa * 2) |
| 08 | Non-number in flippy bounds |
flippy(gaagaa, 10) |
| 09 | Non-number in math builtins | crawl(gaagaa), climb(gaagaa), roll(gaagaa) |
| 10 | Non-positive number in nap |
nap(0), nap(-100) |
| 11 | Non-string prompt in nomnom |
nomnom(42), nomnom(gaagaa) |
| 12 | Wrong argument count at call site | playtime f() { ... } called as f(1) |
| 13 | Type mismatch in function arguments | f(x: numba) called with a boolean |
| 14 | Invalid type cast path | numba(gaagaa) — boolean → number is disallowed |
| 15 | String used with non-+ operator |
"hello" * 3, "hello" / 3 |
| 16 | Mixed-type string concatenation | "hello" + 1, "hello" + gaagaa |
| 17 | Unknown type annotation | playtime f(x: unknown) { ... } |
| 18 | Undefined function call | foo() without a prior playtime foo() |
The complete Ohm grammar that defines every syntactic form of InfantJS lives at src/infantjs.ohm in the repository.
View Grammar →