# ENET 0.1 language contract

ENET by JTWAYNE is a free MIT-licensed interpreted language prototype. This contract describes the executable implementation, not promised future compatibility. Its canonical interpreter is shared with SKIENET's browser classroom; the standalone runner supplies only file reading and printed output.

## Statement grammar

```text
program       := statement*
statement     := comment | declaration | assignment | output | import-marker
               | conditional | repetition | function | return
comment       := "//" text-to-end-of-line
declaration   := "let" identifier "=" expression
assignment    := "set" identifier "=" expression
output        := "say" expression
import-marker := "use jtwayne.code"
conditional   := "if" expression "{" newline statement* "}"
repetition    := "repeat" expression "{" newline statement* "}"
function      := "fn" identifier "(" parameters? ")" "{" newline statement* "}"
return        := "return" expression
parameters    := identifier ("," identifier)*
identifier    := [A-Za-z_][A-Za-z0-9_]*
```

One statement occupies one line. Empty lines are ignored. Opening braces belong at the end of block headers; closing braces occupy their own line. Inline comments, semicolons, `else`, `while`, `for`, assignment expressions and arbitrary imports are not supported.

## Expressions and values

Expressions are parsed by jsep 1.6 and evaluated by ENET's allowlisted AST walker. Supported values are finite numbers, quoted strings, booleans, null and arrays. Calls target a named ENET function or builtin only. Computed indexing of text/arrays is supported with a nonnegative integer in bounds; properties, objects and host methods are rejected.

Arithmetic operators: `+ - * / %`. Comparisons: `== != === !== < <= > >=`. Boolean operators: `! && ||` with short-circuiting. Unary `+` and `-` require numbers. Equality is strict even when written `==`; arrays compare by identity. `+` joins text when either operand is a string. Other arithmetic requires numbers. Conditions use the host's JavaScript truthiness; `&&` and `||` can return operand values rather than booleans. Text length/indexing counts UTF-16 code units, not user-perceived grapheme clusters.

## Bindings and functions

`let` declares in the current scope; `set` updates the nearest enclosing declaration. Duplicate names in the same scope and builtin-name declarations are rejected. Repetition creates a fresh child scope per iteration; `if` uses its enclosing scope. Functions capture their definition scope, use local parameters, require exact arity and return null if no return executes. Functions are not first-class values. Builtin calls resolve before local names, so avoid builtin names for parameters too.

## Builtins

| Name | Arguments | Result |
| --- | --- | --- |
| len | text or array | UTF-16 length or item count |
| upper, lower | one value | host string conversion and case transformation |
| str | one value | host string conversion |
| number | one value | finite host numeric conversion; not strict input validation |
| abs, round, sqrt | one number | numeric result; non-finite results rejected |
| min, max | two numbers | smaller/larger number |

`say` serializes arrays as JSON; `str(array)` uses host string conversion, so these outputs differ. `use jtwayne.code` is accepted as a marker; builtins are already available and no module is loaded.

## Execution contract

Maximum source: 50,000 characters; expression: 4,000 characters; execution: 10,000 steps; block depth: 32; call depth: 32; expression evaluation depth: 64; a text value: 20,000 characters; array: 1,000 items; output: 1,000 lines and 50,000 characters. The website also stops disposable workers after two seconds. Nested arrays do not yet have comprehensive aggregate memory accounting; these limits are not a security certification.

ENET programs have no file, network, shell, browser or hardware access. The Node CLI reads only the explicitly supplied source path. Source remains unexecuted text until the user deliberately runs it in the interpreter. Native compilation, GUI frameworks, cross-language bridges, package loading and AI calls are future work, not ENET 0.1 capabilities.

## Learning source

`classroom-examples/` holds the 24 classroom programs. `book-examples/` holds the book's additional exercises and console projects; `book-examples/manifest.json` records exact expected output. Run `npm test` after installing dependencies to verify the language and book programs. The MIT grant covers this starter's source and bundled documentation/examples, not private member programs or paid SKIENET software.