The Formula Node syntax is similar to the syntax used in text-based programming languages. Remember to end assignments with a semicolon (;) as in C. Use scope rules to declare variables in Formula Nodes. Also, keep in mind the allowed functions and the allowed operators and their precedence in the Formula Node.

Note You can use Formula Node most effectively if you are familiar with the C programming language. LabVIEW Help assumes you are familiar with C and does not contain any topics related to programming in C. Refer to The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie or Teach Yourself C by Herbert Schildt for more information.

The Formula Node syntax is summarized below using Backus-Naur Form (BNF notation). The summary includes non-terminal symbols: compound-statement, identifier, conditional-expression, number, array-size, floating-point-type, integer-type, left-hand-side, assignment-operator, and function. Symbols in red bold monospace are terminal symbols given exactly as they should be reproduced. The symbol # denotes any number of the term following it.

statement-list:
BNF notation showing statement and statement-list syntax.

statement:
BNF syntax for statements including assignment, compound-statement, control-statement, conditional-statement, iterative-statement, switch-statement, variable-declaration.

assignment:
BNF syntax for assignments including expression and left-hand-side assignment-operator.

expression:
BNF syntax for expressions including expression binary-operator, unary-operator, expression unary-operator, expression ? expression : expression, ( expression ), identifier, constant, function-name (argument-list).

left-hand-side:
BNF syntax for left-hand-side including identifier and identifier array-subscription.

array-subscription:
BNF syntax for array-subscriptions including [assignment] and [assignment] array-subscription.

assignment-operator: one of the following
BNF syntax for assignment-operators including =, +=, -=, *=, /=, >>=, <<=, &=,^=, |=, %= and **=.

binary-operator: one of the following
BNF syntax for binary-operators including +, -, *, /, ^, !=, ==, >, <, >=, <=, &&, ||, &, |, % and **.

unary-operator: one of the following
BNF syntax for unary-operators including +, -, !, ++, – and ~.

argument-list:
BNF syntax for argument-lists including expression, and expression , argument-list.

constant:
BNF syntax for constant including pi and number

compound-statement:
BNF syntax for compound-statements including {statement-list}.

The following table provides the Formula Node syntax for control, conditional, iterative, and switch statements.

Statement Type Construct Grammar Description/Example
Control Statement Break Statement
BNF syntax for break in red text.

Use the break keyword to exit the nearest Do, For, or While Loop or switch statement in the Formula Node.
Continue Statement
BNF syntax for continue in red text.

Use the continue keyword to transfer control to the next iteration of the nearest Do, For, or While Loop in the Formula Node.
Conditional Statement
BNF syntax for conditional-statements including if-statement and if-else-statement.

if (y==x && a[2][3]<a[0][1]) { 
    int32 temp;
    temp = a[2][3];
    a[2][3] = y;
    y=temp;
    }
else
    x=y;
If Statement
BNF syntax for an if-statement inlcuding if (assignment) statement.

If-Else Statement
BNF syntax for an if-else-statement inlcuding if-statement else statement.

Iterative Statement
BNF syntax for iterative-statements inlcuding do-statement, for-statement and while-statement.

Do Loops
BNF syntax for do loops including do statement while ( assignment ).

do {
    int32 temp;
    temp = --a[2]+y;
    y=y-1;
    }
while (y!=x && a[2]>=a[0]);
For Loops
BNF syntax for loops including for ( [assignment] ; [assignment] ; [assignment] ) statement.

for (y=5; y<x; y*=2) {
    int32 temp;
    temp = --a[2]+y;
    x-=temp;
    }
While Loops
BNF syntax for while loops including while ( assignment ) statement.

while (y!=x && a[2]>=a[0]) {
    int32 temp;
    temp = --a[2]+y;
    y=y-1;
    }
Switch Statement
BNF syntax for switch-statements including switch ( assignment ) { case-statement-list }.

switch(month){
    case 2: days = evenyear? 29: 28; break;
    case 4:case 6:case9: days = 30; break;
    default: days = 31; break;
    }
Case Statement List
BNF syntax for case-statement lists including case-statement and case-statement-list case-statement.

Case Statement
BNF syntax for case-statements including case number : statement-list and default : statement-list.

variable-declaration:
BNF syntax for variable-declarations including type-specifier identifier, type-specifier identifier array-index-list and type-specific identifier = assignment.

array-index-list:
BNF syntax for array-index-lists including [integer-constant], [integer-constant]array-index-list.

type-specifier:
BNF syntax for type-specifiers floating-point-type and integer-type.

floating-point-type:
BNF syntax for floating-point-types including float, float32 and float64

integer-type:
BNF syntax for integer-types including int, int8, int16, int32, uInt8, uInt16 and uInt32.

non-digit: one of the following
BNF syntax for non-digits including _, a~z and A~Z.

digit: one of the following
BNF syntax for digits including 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

nonzero-digit: one of the following
BNF syntax for nonzero-digits including 1, 2, 3, 4, 5, 6, 7, 8, 9.

binary-digit: one of the following
BNF syntax for binary-digits including 0, 1.

octal-digit: one of the following
BNF syntax for octal-digits including 0, 1, 2, 3, 4, 5, 6, 7.

hex-digit: one of the following
BNF syntax for hex-digits including 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a,b, c, d, e, f, A, B, C, D, E, F.

identifier:
BNF syntax for identifiers including non-digit [non-first-character].

non-first-character:
BNF syntax for non-first-characters including non-digit [non-first-character] and digit [non-first-character].

number:
BNF syntax for numbers including integer-constant, float-constant.

integer-constant:
BNF syntax for integer-constants including decimal-constant, binary-constant, octal-constant and hex-constant.

decimal-constant:
BNF syntax for decimal-constants including nonzero-digit #digit.

binary-constant:
BNF syntax for binary-constants including 0b #binary-digit and 0B #binary-digit.

octal-constant:
BNF syntax for octal-constants including 0 #octal-digit.

hex-constant:
BNF syntax for hex-constants including 0x #hex-digit and 0X #hex-digit.

float-constant:
BNF syntax for float-constants including fraction exponent-part, decimal-constant exponent-part.

fraction:
BNF syntax for fractions including #digit . digit #digit.

exponent-part:
BNF syntax for exponent-parts including e [sign] #digit and E [sign] #digit.

sign: one of the following
BNF syntax for signs including + and -.

comment:
BNF syntax for comments including //comment and /*comment*/.