osq expressions

osq expressions functionally manipulate data (often numbers) using functions (often mathematical operators).

Syntax

osq expressions are wrapped in curly braces and begin with a cash sign. For example:

${expression goes here}

If all that needs to be evaluated is an identifier, a shorthand can be used, which removes the curly braces:

$myvar

Expressions can appear anywhere outside of a directive or expression. Some directives allow expressions, either implicitly or explicitly.

Operators

Most osq operators are binary. All binary and teriary operators in osq expressions are infix. This is how most mathematics is written. An example:

(2) + (17*2-30) * (5)+2 - -(8/2)*4

Operator precedence

In osq, operators have operator precedence, where some operators are evaluated before others. The operator precedence table is as follows:

Operator precedence (higher precedence comes first)
OperatorsTypeAssociativity
(, )SpecialLeft-to-right
:Binary/teriaryLeft-to-right
^BinaryLeft-to-right
*, /, %BinaryLeft-to-right
+, -BinaryLeft-to-right
-, !UnaryLeft-to-right
>, <, >=, <=BinaryLeft-to-right
==, !=BinaryLeft-to-right
, (comma)BinaryLeft-to-right

Mathematical operators

The mathematical operators are: +, -, *, /, %, ^.

+ and - are the addition and subtraction operators, respectively.

* and / are the multiplication and division operators, respectively.

% is the modulus operator. C#'s modulus operator is used.

^ is the power operator.

Boolean operators

== and != are the equality and inequality operators, respectively. == returns true if the oprands are equal, and false otherwise. != returns the complement of what == returns.

>, <, >=, <= are the comparison operators.

! is the inversion operator. It inverts logic; !true becomes false, and !false becomes true. An expression can be converted into a boolean by preceeding it with !!.

Other operators

( and ) surround an expression to increase the subexpression's precedence. This is like how parentheses work in standard mathematics.

The parenthetical operators also instantiate defined functions. If a ( follows an identifier, that identifier is treated as a function and the expression inside the parentheses as the function's argument(s).

The comma operator (,) is used to create lists.

The : operator is used to construct times in milliseconds. For example:

01:23 returns 83000 ((01 * 60 + 23) * 1000)
01:23:456 returns 83456 ((01 * 60 + 23) * 1000 + 456)

Built-ins

Following is a table of all built-in functions and constants:

Functions and constants in osq by default
NameDescription
int(x)Converts x to an integer.
sqrt(x)Takes the square root of x. Equivalent to (x ^ 0.5).
rand()Returns a random number between 0 and 1.
sin(x)Trigonometric function sin. Accepts radians (0..2pi).
cos(x)Trigonometric function cos. Accepts radians (0..2pi).
tan(x)Trigonometric function tan. Accepts radians (0..2pi).
piMathematical constant pi (3.14159...).

Data types

Number

The number data type is any real number quantity. It is represented internally using the double .NET type.

Numbers behave as you'd expect them to.

There are no separate integer and real number types.

String

A string is a sequence of characters. A string is enclosed in double quotes, e.g. "Hello world".

Function

A function is a stored collection of plain text and expressions. They are formed using the #def directive.

There are no anonymous functions.

List

A list is formed by separating values with commas. For example, 0, "hi", (9 + 4) / 0.5 forms a list consisting of the number 0, the string hi, and the number 26.

Currently, the only use for lists is with the #each directive. There are no functions to deal with lists.