# YesNt Language Reference YesNt is a line-based scripting language. Every non-empty, non-comment line is one statement. Execution proceeds top-to-bottom unless a control-flow statement changes the line counter. --- ## Table of contents 1. [Basic rules](#basic-rules) 2. [Comments](#comments) 3. [String literals](#string-literals) 4. [Variables](#variables) 5. [Console I/O](#console-io) 6. [Arithmetic](#arithmetic) 7. [Conditions](#conditions) 8. [Control flow](#control-flow) 9. [Functions](#functions) 10. [Lists](#lists) 11. [Processing](#processing) 12. [System](#system) 13. [Predefined tokens](#predefined-tokens) 14. [Termination](#termination) --- ## Basic rules - Lines are trimmed of leading and trailing whitespace before execution. - Blank lines are silently skipped. - Lines starting with `#` are comments and are silently skipped. - Variable interpolation uses `${name}` and is evaluated before the statement runs. - Special characters inside string literals are encoded internally and decoded on output - this is transparent to scripts. --- ## Comments ```ynt # This is a comment. print_line Hello # inline comments are NOT supported - everything after print_line is the argument ``` Only whole-line comments (lines whose first non-whitespace character is `#`) are supported. --- ## String literals Double-quoted strings protect their content from keyword matching and allow escape sequences. ```ynt print_line "Hello, world!" print_line "Line one\nLine two" print_line "She said \"hi\"" ``` | Escape | Meaning | | ------ | -------------------- | | `\n` | Newline | | `\r` | Carriage return | | `\t` | Horizontal tab | | `\b` | Backspace | | `\f` | Form feed | | `\a` | Alert (bell) | | `\v` | Vertical tab | | `\"` | Literal double-quote | | `\\` | Literal backslash | Variable interpolation (`${name}`) is **not** evaluated inside string literals - the braces and content are passed through verbatim. ```ynt var x = world print_line "${x}" # prints the literal text: ${x} print_line "hello " ${x} # prints: hello world (interpolation outside the literal) ``` --- ## Variables ### Local variables - `var` ``` var = ``` Defines or updates a variable scoped to the current function (or the top level if called outside a function). The value is everything after `=`, trimmed. ```ynt var count = 0 var greeting = Hello, world! ``` Variable names may only contain letters and digits (`[a-zA-Z0-9]`). ### Global variables - `global` ``` global = ``` Defines or updates a variable that is visible across all function scopes and background tasks. ```ynt global total = 100 ``` ### Reading a variable - `${name}` `${name}` is an inline token that is replaced with the variable's value before the statement executes. It can appear anywhere in a line and multiple occurrences are replaced left to right. Local variables are checked first; if not found, the global table is checked. ```ynt var a = 5 var b = 10 print_line ${a} plus ${b} ``` ### Deleting a variable - `delete` ``` delete ``` Removes the variable. Local scope is checked first; if not found, the global table is used. Raises an error if the variable does not exist in either scope. ```ynt var temp = scratch delete temp ``` --- ## Console I/O ### Print with newline - `print_line` ``` print_line print_line ``` Writes `` followed by a newline. With no argument, writes a blank line. ```ynt print_line Hello! print_line print_line Done. ``` ### Print without newline - `print` ``` print ``` Writes `` without a trailing newline. ```ynt print Enter your name: var name = %read_line print_line Hello, ${name}! ``` ### Read a line of input - `%read_line` `%read_line` is an inline token that is replaced with one line of text read from standard input. ```ynt var answer = %read_line print_line You typed: ${answer} ``` ### Read a single key - `%read_key` `%read_key` is an inline token that is replaced with the single character pressed by the user (no Enter required). ```ynt print Press any key... var key = %read_key print_line You pressed: ${key} ``` ### Clear the console - `clear` ``` clear ``` Clears the console window. --- ## Arithmetic Arithmetic is a **postfix** modifier applied at the end of a line with the `calc` keyword. ``` calc ``` Any numeric sub-expression matching the pattern `number op number [op number …]` is evaluated and replaced with the result. Supported operators (highest to lowest precedence): | Operator | Operation | | -------- | ----------------------------- | | `(…)` | Parentheses (evaluated first) | | `^` | Exponentiation | | `%` | Modulo | | `/` | Division | | `*` | Multiplication | | `-` | Subtraction | | `+` | Addition (lowest precedence) | Adjacent sign characters (`++`, `--`, `-+`, `+-`) are normalised before evaluation. ```ynt var x = 3 var y = 4 var sum = ${x} + ${y} calc # 7 var expr = 2 + 3 * 4 calc # 14 (* before +) var parens = (2 + 3) * 4 calc # 20 var power = 2 ^ 10 calc # 1024 var remainder = 17 % 5 calc # 2 ``` --- ## Conditions Conditions are used in `if` and `while` statements. A condition is a string of the form: ``` ``` | Operator | Meaning | | -------- | --------------------------------------------- | | `==` | Equal (string comparison, case-sensitive) | | `!=` | Not equal (string comparison, case-sensitive) | | `<` | Less than (numeric) | | `>` | Greater than (numeric) | | `<=` | Less than or equal (numeric) | | `>=` | Greater than or equal (numeric) | Numeric comparisons (`<`, `>`, `<=`, `>=`) parse both sides with culture-invariant decimal rules (`.` or `,` as decimal separator). A bare value of `True` or `False` (case-insensitive) is also a valid condition. ```ynt var x = 10 if ${x} > 5: print_line x is greater than 5 end_if ``` --- ## Control flow ### If / else / end_if ``` if : else: end_if ``` `else:` is optional. `if` / `else:` / `end_if` blocks can be nested. ```ynt var score = 75 if ${score} >= 60: print_line Pass else: print_line Fail end_if ``` ### While loop ``` while : end_while ``` The condition is checked before each iteration. `while` / `end_while` blocks can be nested. ```ynt var i = 1 while ${i} <= 5: print_line ${i} var i = ${i} + 1 calc end_while ``` ### Labels and goto ``` label : goto ``` `label` marks a target. `goto` performs an unconditional jump to that label. At the top level, labels are file-scoped — you can jump to any label in the file. Inside a function, labels are restricted to the current function; you cannot jump to a label outside the calling function. ```ynt label loop: print_line tick goto loop ``` ### Conditional goto ``` if goto