Skip to content

Syntax Overview

Vex syntax is designed to be familiar to developers coming from C, Rust, Go, or TypeScript while introducing unique features for parallelism and safety.

Basic Structure

Comments

vex
// Single-line comment

/* 
   Multi-line comment 
*/

/// Documentation comment (generates docs)
fn documented_function() {
    // ...
}

Statements and Semicolons

Vex uses automatic semicolon insertion (ASI) similar to Go. Semicolons are optional at line endings:

vex
let x = 10      // Semicolon inserted automatically
let y = 20      // Semicolon inserted automatically

// Explicit semicolons for multiple statements on one line
let a = 1; let b = 2

Blocks

Blocks are delimited by curly braces {}:

vex
{
    let x = 10
    let y = 20
    x + y  // Last expression is the block's value
}

Identifiers

Valid identifiers:

  • Start with a letter or underscore
  • Contain letters, digits, or underscores
  • Case-sensitive
vex
let myVariable = 10
let _private = 20
let camelCase = 30
let snake_case = 40
let Type123 = 50

Reserved Keywords

fn       let      let!     const    struct   enum     contract
if       else     elif     for      while    loop
match    return   break    continue defer    go       async
await    import   export   from     as       type     where
true     false    nil      self     unsafe   extern   public
private  readonly

impl

impl is not part of the current user-facing Vex surface syntax. Older notes or experimental examples may still mention it, but stable examples should use struct X: Contract plus external receiver methods.

Literals

Numeric Literals

vex
// Integers
let decimal = 42
let hex = 0xFF
let octal = 0o77
let binary = 0b1010

// Unsuffixed integer literals default to i64
let default_int = 42

// With type suffix
let byte: u8 = 255u8
let big: i64 = 1000000i64
let huge: i128 = 999999999999i128

// Floats
let pi = 3.14159
let scientific = 1.5e10
let small = 2.0e-5

// Imaginary (for complex numbers)
let imag = 5i
let complex_imag = 3.14i

String Literals

vex
// Regular strings
let hello = "Hello, World!"

// Escape sequences
let escaped = "Line 1\nLine 2\tTabbed"

// Formatted strings (f-strings)
let name = "Vex"
let greeting = f"Hello, {name}!"

// Multi-line strings
let multi = "Line 1
Line 2
Line 3"

// Compile-Time Template Engine (Backticks)
// Zero-overhead static string rendering with {{ expression }}
let active = true
let template = `
    <div>
        <h2>Welcome, {{ name }}!</h2>
        <p>Status: {{ active ? "Online" : "Offline" }}</p>
    </div>
`

Boolean and Nil

vex
let yes = true       // bool
let no = false       // bool

// nil represents a NULL pointer (primarily for FFI)
// For high-level code, use Option<T> instead.
let nothing = nil

Output Intrinsics

For core language examples, prefer the builtin output intrinsics:

vex
$print("hello")
$println("world")
$println(f"name = {name}")

Some library layers may expose helper wrappers like println, but $print / $println are the stable builtin forms used throughout compiler and stdlib tests.

Array Literals

vex
let numbers: [i32; 5] = [1, 2, 3, 4, 5]
let zeros: [f64; 3] = [0.0, 0.0, 0.0]
let mixed = [1, 2, 3]  // Type inferred as [i32; 3]

Tuple Literals

vex
let pair = (10, "hello")
let triple: (i32, f64, bool) = (1, 2.5, true)

// Access by index
let first = pair.0   // 10
let second = pair.1  // "hello"

Operators

Arithmetic Operators

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Moduloa % b
**Powera ** b

Comparison Operators

OperatorDescriptionExample
==Equala == b
!=Not equala != b
<Less thana < b
<=Less or equala <= b
>Greater thana > b
>=Greater or equala >= b

Logical Operators

OperatorDescriptionExample
&&Logical ANDa && b
||Logical ORa || b
!Logical NOT!a

Bitwise Operators

OperatorDescriptionExample
&Bitwise ANDa & b
|Bitwise ORa | b
^Bitwise XORa ^ b
~Bitwise NOT~a
<<Left shifta << n
>>Right shifta >> n

SIMD & Vector Operators

OperatorDescriptionExample
<<<Rotate lefta <<< n
>>>Rotate righta >>> n
<?Element-wise mina <? b
>?Element-wise maxa >? b
*+Fused multiply-adda *+ b
+|Saturating adda +| b
-|Saturating suba -| b

Assignment Operators

vex
let! x = 10

x = 20        // Simple assignment
x += 5        // Add and assign
x -= 3        // Subtract and assign
x *= 2        // Multiply and assign
x /= 4        // Divide and assign
x %= 3        // Modulo and assign
x &= 0xFF     // Bitwise AND and assign
x |= 0x0F     // Bitwise OR and assign
x ^= 0xAA     // Bitwise XOR and assign
x <<= 2       // Left shift and assign
x >>= 1       // Right shift and assign

Other Operators

OperatorDescriptionExample
? :Ternary conditionala > b ? a : b
?Error propagationresult?
??Nil coalescinga ?? default
|>Pipelinex |> fn1 |> fn2
..Range (exclusive)0..10
..=Range (inclusive)0..=10
.Member accessobj.field

Expressions vs Statements

In Vex, most constructs are expressions that return values:

vex
// if is an expression
let max = if a > b { a } else { b }

// match is an expression
let name = match value {
    1 => "one",
    2 => "two",
    _ => "other"
}

// Blocks are expressions (return last value)
let result = {
    let x = compute()
    let y = transform(x)
    x + y  // This is the block's value
}

Next Steps

Released under the MIT License.