Language Reference
The language keywords, grammar, condition operators, and comments.
Keywords
The keywords the compiler recognises today:
| Keyword | Purpose |
|---|---|
| circuit | Declare a program body |
| organ | Declare an organ: fields plus methods |
| strain | Declare a typed variant |
| cell | Declare a function, a method inside an organ or a free function |
| let | Declare a variable. The type is inferred |
| new | Construct an organ instance |
| self | The instance a method was called on |
| if / else | Branching |
| while | Loops. This is the loop form in use today |
| when | Run a block if a condition holds |
| emit / return / output | Give a value back from a cell or the program |
| signal | Send a value to the screen |
| true / false / nil | Literal values |
Grammar
program := circuit*
circuit := "circuit" IDENT ";"
organ := "organ" IDENT "{" field* cell* "}"
strain := "strain" IDENT "{" field* cell* "}"
field := IDENT ":" type ";"
cell := "cell" IDENT "(" params? ")" "->" type "{" statement* "}"
statement:= "let" IDENT "=" expr ";"
| IDENT "=" expr ";"
| "while" condition "{" statement* "}"
| "if" condition "{" statement* "}" ("else" "{" statement* "}")?
| "when" condition "{" statement* "}"
| "emit" expr ";"
| "return" expr ";"
| "output" expr ";"
| expr ";"Organs compile into the grid with their fields as declared state and their methods as wiring. See the organ example on the Getting Started page.
Condition Operators
Sanguis supports five comparison operators:
| Operator | Meaning |
|---|---|
| < | Less than |
| > | Greater than |
| == | Equal to |
| <= | Less than or equal to |
| >= | Greater than or equal to |
Operands are a variable and a number, or two variables:
if x < 5.0 // variable vs number if x > y // variable vs variable if x == 0.0 // variable vs number (equality) if x >= 3.0 // variable vs number (greater or equal) if x <= 10.0 // variable vs number (less or equal)
Arithmetic
Arithmetic works anywhere an expression does:
let sum = a + b; // addition let diff = a - b; // subtraction let prod = a * b; // multiplication let quot = a / b; // division, 0.0 when b is 0.0 let next = pos + 1.0; // increment emit a + b;
Only +, -, *, and / are supported. Division by zero returns 0.0. Arithmetic is evaluated left to right, and operands can be numbers, variables, or builtin results.
Comments
// Comments start with // and run to end of line.
Comments are ignored by the parser. Use them freely.
Builtins
A builtin is a function the engine provides. Builtins are not keywords, and you call them from inside any cell without declaring them. The full list, grouped by what each one does, is on the Builtins page of this manual.