Excerpt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MCS Software provides a formula language in used by various imports and exports throughout our suite of applications. This formula language is intended to produce a single output value from available input values. The language is not white-space, line-break, or case sensitive. Using an informal BNF, the language can be described in the following way:
<formula> :: = <statement> [ <statement> [ <statement> ... ] ]
<statement> ::= RETURN <expression> | IF <expression> THEN <statement> [ ELSE <statement> ] | BEGIN <statement> [ <statement> [ <statement> ... ] ] END | WHILE <expression> <statement> | VAR <variablename> [ = <expression> ] | SET <variablename> = <expression> | TRY <statement> CATCH <statement> | THROW <expression> | FOREACH <variablename> IN <expression> <statement> | BREAK | TRACE <expression> | GLOBAL <variablename> [ = <expression> ]
<expression> :== <literal> | <constant> | <variablename> | <fieldname> | <functionname> ( <expression> [ , <expression> [ , <expresion> ... ] ] <expression> <binary_operator> <expression> | <unary_operator> <expression> | ( <expression> )
<literal> :== [ - ] [ 0-9*] [ . 0-9* ] "string literal" | true | false | null <constant> := @@identifierName <variablename> :== @identifierName <fieldname> :== [ fieldName ] <functionname> :== one of the following functions
|
...
<binary_operator> :== one of the following operators
<unary_operator> :== one of the following operators
Comments Comments may be added anywhere in within a formula body using C/C++ style comment notations
Execution Each statement within a formula is executed until a RETURN statement is encountered. The expression supplied to the first executed RETURN statement is the result of the formula. If no RETURN statement is executed, the result of the formula is NULL. Each statement type is described below: RETURN <expression>Stops execution of the formula and returns <expression> as the result For example:
IF <expression> THEN <statement1> [ ELSE <statement2> ]if <expression> is true then execute statement 1. If the optional ELSE portion is present, then statement2 is executed if <expression> is not true For example:
BEGIN <statement> [ <statement> [ <statement> ... ] ] ENDCombines multiple statements into a single statement. This is useful if you need a conditional execution of more than one statement. For example:
WHILE <expression> <statement>Executes a statement in a pre-test loop. If <expression> is true, then statement is executed and the test repeated until <expression> returns false For example:
VAR <variablename> [ = <expression> ]Declares a variable and optionally initializes it to a value For example:
SET <variablename> = <expression>Sets a previously declared variable to a new value For example:
TRY <statement1> CATCH <statement2>Execute statement1. If an error occurs while executing statement1, statement1 is immediately aborted and statement2 is executed For example:
THROW <expression>Raises an error / exception For example:
FOREACH <variable> IN <expression> <statement>Iterates through an array and executes a statement for each item in the array For example:
BREAKBreaks out of the current innermost WHILE or FOREACH loop. For example:
TRACE <expression>Writes the value of <expression> to the trace log. This is useful for debugging a formula. When using the 'Test' button to test a formula, the trace log is displayed along with the results. Trace events are logged to log4net as DEBUG events for all formula evaluations, whether test or production. For example:
GLOBAL <variablename> [ = <expression> ]Declares a global variable and optionally initializes it to a value. Global variable persist their values within the same formula body over multiple records. They are not shared between different formulas. The initial value is only used to initialize the global variable. It does not reset the value every time the statement executes. Use SET to change or reset the value of a global variable. For example (running summary operations):
Or (accessing previous records):
|
...
|