Summary

Formula interpreter 3.0

 

Getting started

Core idea is to let define users rules either directly (e.g. via editable Grid)
OR via specialized EXCELS thare are used to specify rules (talk with or WernerS about it).

It allows testing a solution and makes calculations and results visible.

Define a table for the formula interpreter.

For the formula interpreter you need a table with the following columns:

  • Identifier
  • Variable
  • Formula
  • Value

    This table can origin from several other tables which will be merged or from an Editable Grid from the [TIS]Board.
    Example:

    Here we have defined three variables (Length, Depth and Height) which should be multiplied (Rows 4, 5 and 6).
    Additionally several columns representing indices can be defined.

Insert the operation, choose the suitable columns, define names for the description column and the error column and define the formatting of the number values.

 

PLEASE NOTE:

  • Column INDEX must be an Integer Column
  • Column GLOBAL (from Version 3.1. on) must be boolean 

 

Indices are used like this: [L215](1), or if there are several indices [L215](2,2) 

Calculation

As soon as the formula field is defined, the formula interpreter tries to solve the formula and overwrite the value filed.
The formula itself can hold the names of one or several variable names and/or numbers.
The following formula inputs can be made:

  • Variables are defined by square brackets: [variable name]
  • if-then formulas are defined like that: IF ([V1] == [V2], 1, 2)
  • AND and OR is defined like in the formula operator: && and  ||
  • MIN([V1], [V2]) for minimum value
  • MAX([V1], [V2]) for minimum value
  • ABS([V1]) for absolute values
  • ROUND([V1]) for rounding to an integer; see also MidpointRounding.AwayFromZero (MSDN)
  • ROUND([V1], x) for rounding to an defined number of decimals (x).
  • MOD([V2], 3) for Modulo calculations

Result


As mentioned before, the value fields in rows holding a formula were calculated.
Two additional columns were generated. The description column gives information about the calculation steps. The error column shows errors within the calculations. In the example the variable Height2 does not exist.

Example: ...

Situation

...

Settings

...

Result

...

Project-File

...

Grammer in EBNF (further definitions in XFormulas.g3)
/* converted on Wed Jan 20, 2016, 15:17 (UTC+01) by antlr_3-to-w3c v0.35.1152 which is Copyright (c) 2011-2015 by Gunther Rademacher <grd@gmx.net> */
 
xformula ::= xformula_expression EOF
xformula_expression
::= xformula_logicalandexpr
xformula_logicalandexpr
::= xformula_logicalorexpr ( '&&' xformula_logicalorexpr )*
xformula_logicalorexpr
::= xformula_compareexpr ( '||' xformula_compareexpr )*
xformula_compareexpr
::= xformula_sumexpr ( ( '==' | '!=' | '>' | '>=' | '<' | '<=' ) xformula_sumexpr )*
xformula_sumexpr
::= xformula_prodexpr ( ( '+' | '-' ) xformula_prodexpr )*
xformula_prodexpr
::= xformulaexpr ( ( '*' | '/' ) xformulaexpr )*
sign ::= '+'
| '-'
primary_expression
::= numeric_constant
parameter
::= xformula_expression
| xformulaexpr
| '(' xformula_expression ')'
xifunc ::= '#' XIFUNCIDENTIFIER '(' parameter* ( ',' parameter )* ')' '#'
function ::= FUNCTIONIDENTIFER '(' parameter ( ',' parameter )* ')'
vardef ::= VARIDENTIFIER ( '(' parameter ( ',' parameter )* ')' )*
compareop
::= '=='
| '!='
| '>'
| '>='
| '<'
| '<='
op ::= '+'
| '-'
| '/'
| '*'
numeric_constant
::= INTEGER
| DOUBLE
xformulaexpr
::= vardef
| function
| '-'* primary_expression
| op
| compareop
| xifunc
| CHARACTER_LITERAL
| STRING_LITERAL
| '(' xformula_expression ')'
 
<?TOKENS?>
 
BOOLEAN ::= 'true'
| 'false'
| 'True'
| 'False'
ESCAPELDELIM
::= '\' '['
ESCAPERDELIM
::= '\' ']'
INTEGER ::= DIGIT+ INTEGER_TYPE_SUFFIX?
DOUBLE ::= ( DIGIT* '.' )? DIGIT+ REAL_TYPE_SUFFIX?
INTEGER_TYPE_SUFFIX
::= 'I'
| 'i'
REAL_TYPE_SUFFIX
::= 'F'
| 'f'
VARIDENTIFIER
::= '[' ( ESCAPEDELIM | [^[#x5D] )+ ']'
FUNCTIONIDENTIFER
::= ( UPPER | LOWER ) ( UPPER | LOWER | DIGIT )*
XIFUNCIDENTIFIER0
::= '#' XIFUNCIDENTIFIER
XIFUNCIDENTIFIER
::= 'XI.TIS' UPPER LETTERS*
ESCAPEDELIM
::= ESCAPELDELIM
| ESCAPERDELIM
LOWER ::= [a-z]
UPPER ::= [A-Z]
SPECIALS ::= [ -@#x80-#xFF]
LETTER ::= LOWER
| UPPER
| SPECIALS
LETTERS ::= LOWER
| UPPER
DIGIT ::= [0-9]
ESCAPESEQUENCE
::= '\' ( 'b' | 't' | 'n' | 'r' | '"' | "'" | '\' )
CHARACTER_LITERAL
::= "'" ( ESCAPESEQUENCE | [^'\] )* "'"
STRING_LITERAL
::= '"' ( ESCAPESEQUENCE | [^"\] )* '"'
WS ::= [ #x9#xA#xD]+
COMMENT? ::= '/*' .* '*/'
EOF ::= $

Want to learn more?

Settings

Formula interpreter 3.0

Columns of input table

Parameter

Examples

Example 1: ...

...

Calculation method

Settings

Result

...

 

 

Troubleshooting

Problem

Frequent Cause

Solutions

...

 

...

Related topics