公式节点语法
- 更新时间2026-02-27
- 阅读时长7分钟
公式节点语法与文本编程语言的语法相似,与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:


statement:


assignment:


expression:


left-hand-side:


array-subscription:
![数组订阅的BNF语法,包括[赋值]和[赋值]数组订阅。](https://docs-be.ni.com/bundle/labview/page/GUID-98C0CF6B-E10F-451D-A59B-B26C797CE89C-a5.png?_LANG=zhcn)
![数组订阅的BNF语法,包括[赋值]和[赋值]数组订阅。](https://docs-be.ni.com/bundle/labview/page/GUID-98C0CF6B-E10F-451D-A59B-B26C797CE89C-a5.png?_LANG=zhcn)
assignment-operator: one of the following


binary-operator: one of the following


unary-operator: one of the following


argument-list:


constant:


compound-statement:


下表是控制、条件、循环和switch语句在公式节点中的语法。
| 语句类型 | 结构 | 语法 | 说明/范例 |
|---|---|---|---|
| 控制语句 | Break语句 |
![]() |
break关键词用于在“公式节点”从最近的Do、For,或While循环以及switch语句中退出。 |
| Continue语句 |
![]() |
continue关键词用于在“公式节点”中将控制权传递给最近的Do、For,或While循环的下一次迭代。 | |
| 条件语句 |
![]() |
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-Else语句 |
![]() |
||
| 循环语句 |
![]() |
||
| Do循环 |
![]() |
do {
int32 temp;
temp = --a[2]+y;
y=y-1;
}
while (y!=x && a[2]>=a[0]);
|
|
| For循环 |
![]() |
for (y=5; y<x; y*=2) {
int32 temp;
temp = --a[2]+y;
x-=temp;
}
|
|
| While循环 |
![]() |
while (y!=x && a[2]>=a[0]) {
int32 temp;
temp = --a[2]+y;
y=y-1;
}
|
|
| Switch语句 |
![]() |
switch(month){
case 2: days = evenyear? 29: 28; break;
case 4:case 6:case9: days = 30; break;
default: days = 31; break;
}
|
|
| Case语句列表 |
![]() |
||
| Case语句 |
![]() |
variable-declaration:


array-index-list:
![数组索引列表的BNF语法包括[整型常量]、[整型常量]数组索引列表。](https://docs-be.ni.com/bundle/labview/page/GUID-7CFE3F7A-1772-4B77-9308-8C624A875F0F-a5.png?_LANG=zhcn)
![数组索引列表的BNF语法包括[整型常量]、[整型常量]数组索引列表。](https://docs-be.ni.com/bundle/labview/page/GUID-7CFE3F7A-1772-4B77-9308-8C624A875F0F-a5.png?_LANG=zhcn)
type-specifier:


floating-point-type:


integer-type:


non-digit: one of the following


digit: one of the following


nonzero-digit: one of the following


binary-digit: one of the following


octal-digit: one of the following


hex-digit: one of the following


identifier:
![标识符(包括非数字[非第一个字符])的BNF语法。](https://docs-be.ni.com/bundle/labview/page/GUID-9165680F-38ED-4CF7-B427-1C2F8B65A5E7-a5.png?_LANG=zhcn)
![标识符(包括非数字[非第一个字符])的BNF语法。](https://docs-be.ni.com/bundle/labview/page/GUID-9165680F-38ED-4CF7-B427-1C2F8B65A5E7-a5.png?_LANG=zhcn)
non-first-character:
![非第一个字符(包括非数字[非第一个字符]和数字[非第一个字符])的BNF语法。](https://docs-be.ni.com/bundle/labview/page/GUID-54C0B8FF-C4F8-4930-A500-61A533FE48AA-a5.png?_LANG=zhcn)
![非第一个字符(包括非数字[非第一个字符]和数字[非第一个字符])的BNF语法。](https://docs-be.ni.com/bundle/labview/page/GUID-54C0B8FF-C4F8-4930-A500-61A533FE48AA-a5.png?_LANG=zhcn)
number:


integer-constant:


decimal-constant:


binary-constant:


octal-constant:


hex-constant:


float-constant:


fraction:


exponent-part:
![指数部分的BNF语法,包括e [sign] #digit和E [sign] #digit。](https://docs-be.ni.com/bundle/labview/page/GUID-A4ED4AF6-1AE5-4571-9B5F-2C767F817337-a5.png?_LANG=zhcn)
![指数部分的BNF语法,包括e [sign] #digit和E [sign] #digit。](https://docs-be.ni.com/bundle/labview/page/GUID-A4ED4AF6-1AE5-4571-9B5F-2C767F817337-a5.png?_LANG=zhcn)
sign: one of the following


comment:









![循环的BNF语法包括for ( [assignment] ; [assignment] ; [assignment] )语句。](https://docs-be.ni.com/bundle/labview/page/GUID-A9BE44EB-8BCA-4B4E-83F0-2AB324D086D0-a5.png?_LANG=zhcn)



