Literals and Expressions
Literals
A literal is a fixed value written directly into the source code.
In cksp, literals can be of the following types:
Integer literal
Integer literals are whole numbers without a decimal point.
Integer literals can also be written in hexadecimal or binary form:
Hexadecimal literals start with 0x and use digits 0–9 and letters A–F:
Binary literals can be written in two orientations:
-
With a trailing
b: bits are interpreted least-significant-bit (LSB) right
-
With a leading
b: bits are interpreted least-significant-bit (LSB) left
Real (floating point) literal
Real literals represent numbers with a fractional part, indicated by a decimal point.
Real literals can also be expressed in scientific notation, allowing compact representation of very large or very small values.Scientific notation uses the letter e or E to represent powers of ten.
The syntax follows this pattern:
The exponent can be positive or negative, with or without a sign.
The following examples are all valid:
You may use uppercase E interchangeably with lowercase e:
Precision and Type Inference
All literals written in scientific notation are inferred as real values. They support the same precision and arithmetic operations as normal floating-point literals.
String literal
String literals are sequences of characters enclosed in double quotes (" ) or single quotes (').
String Literal Escape Sequences
String literals can contain escape sequences such as \" for quotes or \n for newlines.
Boolean literal
Boolean literals represent truth values and can be either true or false.
Expressions
An expression is any valid combination of literals, variables, operators, and function calls that produces a value. They can not stand alone; they must be part of a larger statement, e.g. as an l-value in assignments or as arguments in function calls.
Expressions in CKSP follow KSP semantics and support a wide range of operations.
Arithmetic Operators
The following operators can be used with integer and real values:
In addition, CKSP supports:
Increment and decrement functions are also available for integers:
Real-Specific Functions
Trigonometric functions:
Bitwise Operators
For integer values:
Bit shifting:
String Concatenation
Strings can be concatenated using the & operator:
Concatenation is evaluated left to right and can be combined with other expressions:
Logical Operators
Logical operators work only in expressions using boolean types or values:
Examples:
Type Conversion
Certain functions and operators require specific types. When mixing integers and reals, explicit type conversion can avoid errors:
f-Strings (Formatted Strings)
CKSP supports formatted strings, also known as f-strings, for embedding variables or expressions directly into a string literal.
You can also embed expressions:
Function calls are allowed as well: