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:
statement ;
statement ; statement-list
statement:
assignment
compound-statement
control-statement
conditional-statement
iterative-statement
switch-statement
variable-declaration
assignment:
expression
left-hand-side assignment-operator assignment
expression:
expression binary-operator expression
unary-operator expression
expression unary-operator
expression ? expression : expression
( expression )
identifier
constant
function-name ( argument-list )
left-hand-side:
identifier
identifier array-subscription
array-subscription:
[assignment]
[assignment] array-subscription
assignment-operator: one of
= += –= *= /= >>= <<= &= ^= |= %= **=
binary-operator: one of
+ – * / ^ != == > < >= <= && || & | % **
unary-operator: one of
+ – ! ++ –– ~
argument-list:
expression
expression , argument-list
constant:
pi
number
compound-statement:
{ 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 | break | Use the break keyword to exit the nearest Do, For, or While Loop or switch statement in the Formula Node. |
Continue Statement | continue | 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 | conditional-statement: if-statement 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 | if-statement: if ( assignment ) statement | ||
If-Else Statement | if-else-statement: if-statement else statement | ||
Iterative Statement | iterative-statement: do-statement for-statement while-statement |
||
Do Loops | do statement while ( assignment ) | do {
int32 temp; temp = --a[2]+y; y=y-1; } while (y!=x && a[2]>=a[0]); | |
For Loops | for ( [assignment] ; [assignment] ; [assignment] ) statement | for (y=5; y<x; y*=2) {
int32 temp; temp = --a[2]+y; x-=temp; } | |
While Loops | while ( assignment ) statement | while (y!=x && a[2]>=a[0]) {
int32 temp; temp = --a[2]+y; y=y-1; } | |
Switch Statement | 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 | case-statement-list: case-statement case-statement-list case-statement | ||
Case Statement | case-statement: case number : statement-list default : statement-list |
variable-declaration:
type-specifier identifier
type-specifier identifier array-index-list
type-spec identifier = assignment
array-index-list:
[integer-constant]
[integer-constant]array-index-list
type-specifier:
floating-point-type
integer-type
floating-point-type:
float
float32
float64
integer-type:
int
int8
int16
int32
uInt8
uInt16
uInt32
non-digit: one of
_ a~z A~Z
digit: one of
0 1 2 3 4 5 6 7 8 9
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
binary-digit: one of
0 1
octal-digit: one of
0 1 2 3 4 5 6 7
hex-digit: one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
identifier:
non-digit [non-first-character]
non-first-character:
non-digit [non-first-character]
digit [non-first-character]
number:
integer-constant
float-constant
integer-constant:
decimal-constant
binary-constant
octal-constant
hex-constant
decimal-constant:
nonzero-digit #digit
binary-constant:
0b #binary-digit
0B #binary-digit
octal-constant:
0 #octal-digit
hex-constant:
0x #hex-digit
0X #hex-digit
float-constant:
fraction exponent-part
decimal-constant exponent-part
fraction:
#digit . digit #digit
exponent-part:
e [sign] #digit
E [sign] #digit
sign: one of
+ -
comment:
//comment
/* comment */