Documentation Index
Fetch the complete documentation index at: https://mintlify.com/boblio-max/origin/llms.txt
Use this file to discover all available pages before exploring further.
Origin provides a rich set of operators drawn from both Python semantics and English-like readability conventions. All operators are recognized by the lexer as distinct token types — ARITH, COMP, LOGIC, SPECIAL, UNARY, and ASSIGN_OP — so there is no ambiguity between them. This page serves as a complete reference, covering every operator category, smart string concatenation, built-in functions that behave like operators, hexadecimal literals, and the full operator precedence table.
Arithmetic Operators
These operators work on int and float values. When one operand is a float, the result is promoted to float:
| Operator | Operation | Example | Result |
|---|
+ | Addition | 3 + 4 | 7 |
- | Subtraction | 10 - 3 | 7 |
* | Multiplication | 6 * 7 | 42 |
/ | Division | 10 / 4 | 2.5 |
// | Floor division | 10 // 4 | 2 |
% | Modulo (remainder) | 10 % 3 | 1 |
** | Exponentiation | 2 ** 8 | 256 |
Smart String Concatenation
The + operator has special behavior when either operand is a str. Instead of raising a TypeError, Origin automatically converts both sides to strings and concatenates them:
let label: str = "Sensor reading: " + 42
print label # → Sensor reading: 42
This is implemented directly in the interpreter’s BinOpNode handler. The generated Python is:
(str(left) + str(right)) if isinstance(left, str) or isinstance(right, str) else (left + right)
This applies at runtime any time + is used and either operand is a string.
Comparison Operators
| Operator | Meaning |
|---|
== | Loose equality |
!= | Loose inequality |
=== | Strict equality (type + value) |
!== | Strict inequality |
< | Less than |
> | Greater than |
<= | Less than or equal to |
>= | Greater than or equal to |
<> | Alias for != |
let a: int = 5
let b: int = 10
print a == 5 # → True
print a === 5 # → True (strict)
print a <> b # → True (same as !=)
print a >= b # → False
Logical Operators
Origin accepts both English keywords and C-style symbols — they compile to identical Python bytecode:
| Keyword | Symbol | Meaning | Example |
|---|
and | && | Logical AND | x > 0 and x < 100 |
or | || | Logical OR | x < 0 || x > 100 |
not | ! | Logical NOT | not flag / !flag |
let x: int = 42
let ok: bool = x > 0 && x < 100
print ok # → True
print not ok # → False
print !ok # → False
Bitwise Operators
Bitwise operators work on integer values at the binary level:
| Operator | Operation | Example |
|---|
& | Bitwise AND | 0xFF & 0x0F |
| | Bitwise OR | 0x01 | 0x10 |
^ | Bitwise XOR | 0b1010 ^ 0b1100 |
<< | Left shift | 1 << 4 |
>> | Right shift | 256 >> 3 |
let mask: int = 0xFF
let val: int = 0x3A
print val & mask # → 58
print 1 << 4 # → 16
Compound Assignment Operators
Compound operators combine an arithmetic or bitwise operation with assignment, mutating the variable in place:
| Operator | Equivalent To |
|---|
+= | x = x + value |
-= | x = x - value |
*= | x = x * value |
/= | x = x / value |
%= | x = x % value |
**= | x = x ** value |
//= | x = x // value |
&= | x = x & value |
|= | x = x | value |
let n: int = 100
n -= 25 # n = 75
n *= 2 # n = 150
n //= 7 # n = 21
Unary Operators
| Operator | Meaning | Example |
|---|
++ | Increment (prefix) | ++i |
-- | Decrement (prefix) | --i |
- | Arithmetic negation | -x |
not/! | Logical negation | not flag |
let i: int = 10
++i # 11
--i # 10
Special Operators
The following tokens are recognized by the lexer as the SPECIAL token type and are valid in expressions syntactically, but they are not yet implemented in the interpreter. Using them will raise a RuntimeError: Unknown node type at runtime.
??, ->, =>, <=>, and :: are reserved for future use. They are fully tokenized and parsed into SpecialOpNode AST nodes, but no code-generation handler exists in the interpreter yet. Do not rely on them in production scripts.
| Operator | Name | Planned Purpose |
|---|
?? | Null coalesce | Return right operand when left is none |
-> | Arrow | Pipe / callback syntax |
=> | Fat arrow | Lambda / case arm syntax |
<=> | Spaceship | Three-way comparison ordering |
:: | Scope | Scope / namespace resolution |
Built-in Functions That Act Like Operators
These are recognized as keywords by the lexer and compile to built-in function calls, but behave like unary or binary operators in expressions:
| Expression | Description |
|---|
len(x) | Returns the length of a list, string, or dict |
sqrt(x) | Returns the square root of a number |
rand_num(a, b) | Returns a random integer between a and b |
range(a, b) | Generates a sequence from a to b (exclusive) |
input("prompt") | Reads a line of user input, returns a string |
let items: list = ["a", "b", "c"]
let count: int = len(items) # → 3
let root: float = sqrt(144) # → 12.0
let roll: int = rand_num(1, 6) # → 1..6
let name: str = input("Name: ") # reads stdin
Hexadecimal Literals
Integer literals can be written in hexadecimal using the 0x prefix. The lexer matches them with the HEX token type and converts them to int at parse time:
let addr: int = 0x40 # → 64
let mask: int = 0xFF # → 255
let flag: int = 0x1F # → 31
Operator Precedence
Operators are evaluated from highest to lowest precedence. Within the same level, evaluation is left-to-right:
| Level | Category | Operators |
|---|
| 1 | Unary (highest) | ++, --, - (negation), not, ! |
| 2 | Multiplicative | *, /, //, %, ** |
| 3 | Additive | +, - |
| 4 | Comparison | ==, !=, ===, !==, <, >, <=, >=, <> |
| 5 | Logical | and / &&, or / || |
| 6 | Special (lowest) | ??, ->, =>, <=>, :: |
Use parentheses to override the default precedence at any point in an expression:
let result: int = (2 + 3) * 4 # → 20, not 14