Formula
Formula Grammar
Basic Elements
Our formula grammar consists of several basic elements:
- Strings: Text surrounded by single or double quotes, such as ‘Hello’ or “World”.
- Numbers:
- Integers: Pure numbers like 123 or -456.
- Decimals: Numbers with decimal points like 12.34 or -45.67.
- Boolean Values: These include
TRUE
andFALSE
, representing true and false states. - Field References: Used to reference values from specific fields. They can be written as direct identifier names or surrounded by curly braces, such as
{age}
.
Operators
Operators in formulas are used to connect or compare values:
-
Mathematical Operations:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modulo (%)
-
Comparison Operations:
- Greater than (>)
- Less than (<)
- Greater than or equal to (>=)
- Less than or equal to (<=)
- Equal to (=)
- Not equal to (!=)
-
Logical Operations:
- Logical AND (&&)
- Logical OR (||)
- Bitwise AND (&)
Function Calls
You can call functions within formulas. A function call consists of a function name, a pair of parentheses, and parameters inside the parentheses. Parameters are separated by commas.
For example: sum(1, 2, 3)
calls a function named sum
with three parameters: 1, 2, and 3.
Other Structures
- Parentheses: You can use parentheses to change operation precedence, such as
(1 + 2) * 3
. - Comments: To improve formula readability or provide additional context for other users, you can add comments. Block comments are enclosed by
/*
and*/
, while line comments start with//
. - Whitespace: In formulas, whitespace, line breaks, and comments are typically ignored, but they can help improve formula readability.