VolkanaDEV

Language Reference

The language keywords, grammar, condition operators, and comments.

Keywords

The keywords the compiler recognises today:

KeywordPurpose
circuitDeclare a program body
organDeclare an organ: fields plus methods
strainDeclare a typed variant
cellDeclare a function, a method inside an organ or a free function
letDeclare a variable. The type is inferred
newConstruct an organ instance
selfThe instance a method was called on
if / elseBranching
whileLoops. This is the loop form in use today
whenRun a block if a condition holds
emit / return / outputGive a value back from a cell or the program
signalSend a value to the screen
true / false / nilLiteral 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:

OperatorMeaning
<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.