Skip to content

Grammar And Language Status

Nilakan is a small language with Python-like tokens, not a Python implementation. Similar spelling does not imply that a Python construct is supported. This page records the accepted surface grammar and the important parser/static-check restrictions in the current release.

Open the generated railroad diagrams for the complete parser productions. The docs build generates these diagrams directly from Chevrotain’s serialized grammar and bundles its rendering assets locally. The reference therefore follows the parser without a second grammar to maintain. Token names refer to the lexical forms in Lexical Structure.

Diagrams describe recognition, including recovery productions. They cannot express the gates that require statement boundaries, AST validation, or static restrictions; the rules below still apply. Newlines and indentation delimit a block; a block may instead contain simple statements on the header line separated by semicolons.

Parsing is only the first layer. Imports are only allowed at top level, and a dotted call statement or a .NAME without a call must name a member of an imported module; see Modules And Imports. init, while, primed targets, return, nested definitions, and pragma have placement rules described under Statements and Commit Loops. In particular, a Nilakan while is always a commit loop; there is no separate imperative while statement. pragma acc_prime: sequential must be the first statement inside the target loop body. Other recognized accumulation modes currently fail with NLK3013 because their evaluators and verification checks are not implemented.

See the expression rules in the diagrams for precedence, from catchExpression through primaryExpression.

The parser can recover a comparison-shaped token sequence containing multiple comparison operators, but static AST construction rejects chained comparisons with NLK1005. Write left < middle and middle < right.

Calls support positional and named arguments, with positional arguments first. A direct call suffix is accepted only as part of a NAME primary; it is not a general postfix, so (str)(1) is invalid. After a primary, the parser accepts only method calls, module attributes, and subscripts. Parenthesized expressions, lists, sets, dicts, tuples, calls, and returns accept a trailing comma. Subscripts support indexes and start:end slices; slice steps are unsupported.

The recognized scalar names are num, bool, str, and err. Container forms are list[T], set[T], dict[K, V], and fixed tuples such as tuple[num, str]. See Type Contracts for validation rules. The parser also accepts empty type arguments such as list[]. An empty argument list is the same unconstrained container contract as the bare form list.

Deliberately Unsupported Or Not Yet Implemented

Section titled “Deliberately Unsupported Or Not Yet Implemented”
Construct Status and replacement
for, break, continue Unsupported. Express iteration as commit-loop state.
class Unsupported. Use functions and container values.
relative imports, import * Unsupported. Imports name modules relative to the importing file’s folder.
lambda, comprehensions, generators Unsupported. Use named functions and explicit commit loops.
None, null values, bytes Unsupported. Some Python defaults that require None are therefore unavailable.
try/except, raise Unsupported spelling. Nilakan uses error values, prefix try, and infix catch.
chained comparisons Rejected with NLK1005; join explicit comparisons with and.
augmented assignment (+=) Unsupported. Write a normal assignment or primed assignment.
exponentiation (**) Unsupported.
exponent/hex/octal/binary number literals Unsupported; use decimal integers or fractions.
slice steps (a:b:c) Rejected with NLK1005.
nested function definitions Parsed for recovery but rejected statically.
branch-local return Allowed in ordinary functions; all continuing function paths must return. Forbidden in commit loops.
direct and mutual recursion Allowed; non-terminating calls are stopped by the configured call-depth limit.
general mutation methods Methods are pure and return a new value. Raw list/dict index assignment is available in limited statement positions.
effectful calls in expressions Rejected. Call print and transitively effectful user functions as statements.

“Unsupported” means programs must not rely on the construct. It is not a promise that the construct will be added or keep Python semantics if it is added later.

Every runnable nlk code fence in the documentation is a complete executable program. An adjacent hidden MDX nlk-test comment specifies its expected output. The optional run field supplies calls for examples that only define functions or bindings. The documentation suite runs these programs in process and compares their output; a new fence without an expectation fails the suite. A fence whose title begins with Intentional failure states and tests the expected diagnostic code written in its title. Fences titled Fragment or Expression forms are syntax illustrations that explicitly require the surrounding context named in the title. This convention prevents pseudo-code from being mistaken for a runnable lesson.