公式节点语法与文本编程语言的语法相似,与C语言一样,赋值结束后使用分号(;)。使用作用域规则在公式节点中声明变量。此外,请记住公式节点中允许的函数允许的运算符及其优先级

备注 如您了解C编程语言,可最有效的使用公式节点。LabVIEW帮助中未涉及关于C编程的相关主题。如需了解关于C编程语言的详细信息,可参考Brian W. Kernighan和Dennis M. Ritchie 编著的The C Programming Language或Herbert Schildt编著的Teach Yourself C

根据Backus-Naur范式(BNF表示法),公式节点语法总结如下。该总结涵盖了下列非终结符号:复合语句、标识符、条件表达式、数字、数组大小、浮点型、整型、左式、赋值运算符和函数。红色等宽粗体部分应全部复制。#表示其所属中心词的数量。

statement-list:
显示语句和语句列表语法的BNF符号。

statement:
语句的BNF语法包括赋值、复合语句、控制语句、条件语句、迭代语句、开关语句、变量声明。赋值复合语句控制语句条件语句迭代语句开关语句变量声明

assignment:
赋值(包括表达式和左侧赋值运算符)的BNF语法。

expression:
表达式的BNF语法,包括表达式 binary-operator, unary-operator, expression unary-operator, expression ? expression : expression, ( expression ), identifier, constant, function-name (argument-list)。

left-hand-side:
左侧的BNF语法,包括标识符和标识符数组下标。

array-subscription:
数组订阅的BNF语法,包括[赋值]和[赋值]数组订阅。

assignment-operator: one of the following
赋值运算符的BNF语法包括=、+=、-=、*=、/=、>>=、<<=、&=、^=、|=、%=和**=。

binary-operator: one of the following
一元运算符的BNF语法包括+、-、*、/、^、!=、==、>、<、>=、<=、&&、||、&、|、%和**。

unary-operator: one of the following
一元运算符的BNF语法包括+、-、!、++、–和~。

argument-list:
参数列表的BNF语法,包括表达式和表达式,参数列表。

constant:
常量(包括pi和数字)的BNF语法

compound-statement:
复合语句(包括{语句列表})的BNF语法。

下表是控制、条件、循环和switch语句在公式节点中的语法。

语句类型 结构 语法 说明/范例
控制语句 Break语句
红色文本中用于中断的BNF语法。

break关键词用于在“公式节点”从最近的Do、For,或While循环以及switch语句中退出。
Continue语句
以红色文本继续的BNF语法。

continue关键词用于在“公式节点”中将控制权传递给最近的Do、For,或While循环的下一次迭代。
条件语句
条件语句(包括if-语句和if-else-语句)的BNF语法。

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语句
包含if(赋值)语句的if语句的BNF语法。

If-Else语句
if-else语句的BNF语法包括if-statement else语句。

循环语句
迭代语句的BNF语法,包括do-语句、for-语句和while-语句。

Do循环
do循环的BNF语法包括do语句while ( assignment )。

do {
    int32 temp;
    temp = --a[2]+y;
    y=y-1;
    }
while (y!=x && a[2]>=a[0]);
For循环
循环的BNF语法包括for ( [assignment] ; [assignment] ; [assignment] )语句。

for (y=5; y<x; y*=2) {
    int32 temp;
    temp = --a[2]+y;
    x-=temp;
    }
While循环
While循环的BNF语法,包括while ( assignment )语句。

while (y!=x && a[2]>=a[0]) {
    int32 temp;
    temp = --a[2]+y;
    y=y-1;
    }
Switch语句
switch语句的BNF语法包括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语句列表
条件语句列表的BNF语法,包括条件语句和条件语句列表条件语句。

Case语句
条件语句的BNF语法包括case number : statement-list和default : statement-list。

variable-declaration:
变量声明的BNF语法包括类型说明符标识符、类型说明符标识符数组-索引-列表和类型特定标识符=赋值。

array-index-list:
数组索引列表的BNF语法包括[整型常量]、[整型常量]数组索引列表。

type-specifier:
类型说明符浮点型和整型BNF语法。

floating-point-type:
浮点型(包括float、float32和float64)的BNF语法

integer-type:
整数类型的BNF语法,包括int、int8、int16、int32、uInt8、uInt16和uInt32。

non-digit: one of the following
_、a~z和A~Z等非数字的BNF语法。

digit: one of the following
数字的BNF语法,包括0, 1, 2, 3, 4, 5, 6, 7, 8, 9。

nonzero-digit: one of the following
非零数字的BNF语法,包括1、2、3、4、5、6、7、8、9。

binary-digit: one of the following
二进制数(包括0、1)的BNF语法。

octal-digit: one of the following
八进制的BNF语法,包括0, 1, 2, 3, 4, 5, 6, 7。

hex-digit: one of the following
十六进制的BNF语法,包括0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a,b, c, d, e, f, A, B, C, D, E, F。

identifier:
标识符(包括非数字[非第一个字符])的BNF语法。

non-first-character:
非第一个字符(包括非数字[非第一个字符]和数字[非第一个字符])的BNF语法。

number:
整数常量、浮点常量等数值的BNF语法。

integer-constant:
整数常量的BNF语法,包括十进制常量、二进制常量、八进制常量和十六进制常量。

decimal-constant:
十进制常量(包括非零位#数字)的BNF语法。

binary-constant:
二进制常量的BNF语法,包括0b #二进制数和0B #二进制数。

octal-constant:
八进制常量的BNF语法,包括0 #八进制数。

hex-constant:
十六进制常量的BNF语法,包括0x #十六进制数和0X #十六进制数。

float-constant:
浮点常量的BNF语法,包括分数指数部分、十进制常量指数部分。

fraction:
分数的BNF语法,包括#digit . digit #digit。

exponent-part:
指数部分的BNF语法,包括e [sign] #digit和E [sign] #digit。

sign: one of the following
符号(包括+和-)的BNF语法。

comment:
注释的BNF语法包括//comment和/*comment*/。