Repository navigation
Language Syntax
Frank edited this page Jan 25, 2026
·
12 revisions
CupidScript uses a C-like surface syntax.
Supported comment forms:
// line comment
/* block comment */Comments are skipped by the lexer alongside whitespace.
- Start: letter or
_ - Continue: letters, digits,
_
Decimal and hexadecimal integers with optional underscores:
0
12345
1_000_000
0xFF
0xFF_FF_FF- Decimal:
0-9digits - Hexadecimal:
0xor0Xfollowed by hex digits (0-9,a-f,A-F) - Underscores
_can appear anywhere in the number (ignored)
Floating-point literals with decimal point:
3.14
2.5
0.001
1.5e-3
2.0E+10- Must contain a decimal point:
. - Optional exponent:
eorEfollowed by optional+/-and digits - Scientific notation:
1.5e-3equals0.0015
Double-quoted strings:
"hello"
"with \n escapes"
"quote: \""
"backslash: \\"Escape handling (in runtime unescape):
-
\n,\t,\r,\",\\ - Any unknown escape
\xbecomes literalx
[]
[1, 2, 3]
["a", "b", "c"]Trailing commas are allowed:
[1, 2, 3,]
[]{}
{"name": "Frank", "age": 30}
{"key": value_expr}Trailing commas are allowed:
{"a": 1, "b": 2,}
{}Keys must be string expressions (can be any expression that evaluates to a string).
( ) [ ] { } , ; .
Assignment:
=-
+=,-=,*=,/=(compound assignment)
Arithmetic:
+ - * / %
Unary:
! -
Comparison:
== != < <= > >=
Boolean:
&& ||
Range:
-
..(exclusive range, e.g.,0..5→[0,1,2,3,4]) -
..=(inclusive range, e.g.,0..=5→[0,1,2,3,4,5])
- Primary: literals, identifiers, parenthesized
(expr), list literals[...], map literals{...} - Postfix: calls
f(...), indexinga[b], field accessa.b(field access works after any expression, e.g.(expr).field) - Unary:
!expr,-expr - Multiplicative:
* / % - Additive:
+ - - Range:
start..end,start..=end - Comparison:
< <= > >= - Equality:
== != - AND:
&& - OR:
|| - Ternary:
cond ? then : else
CupidScript supports switch as a statement:
switch (x) {
case 1 { print("one"); }
case 2 { print("two"); }
default { print("other"); }
}Notes:
- Cases are compared using the same equality rules as
==for basic types. - Non-fallthrough: only the first matching case runs.
Syntax:
try {
// body
} catch (e) {
// handler
} finally {
// cleanup
}Notes:
-
catchis required;finallyis optional. -
finallyexecutes after thetry/catchregardless ofreturnorthrow.