跳到主要内容

高级逻辑语法规则

高级逻辑逐行解析,一行只写一条规则。空行和以 # 开头的注释不会执行。

基本规则

规则正确写法
一行一条规则if Q1A1 then show Q2
注释行# 选择需要发票时显示抬头
DSL 关键字使用小写ifthenshowbranch
公式函数通常使用大写ANDORIFSUM
文本使用引号"不能超过100"
判断相等使用双等号Q1==100

编辑器会检查行结构、标签、括号和引号。错误行会显示红色背景和“未完成或有错误,请检查语法”。

条件语句

显示、隐藏、必填和跳转使用:

if 条件 then 动作

示例:

if Q1A1 then show Q2
if AND(Q1A1,Q2A1) then hide Q3
if Q1>60 then required Q2
if Q1A1 then branch from Q1 to Q6

条件中可以使用题目标签、选项标签、运算符和公式函数。

直接动作语句

赋值、校验和标题替换不写在 if ... then ... 后面,而是使用:

动作 目标 with 公式

示例:

assignment Q3 with SUM(Q1,Q2)
validate Q2 with IF(Q2>100,"不能超过100","")
replace Q2 with CONCATENATE("你好,",Q1)

需要条件赋值或条件校验时,把条件写进 with 后面的 IF(...)

assignment Q3 with IF(Q1A1,100,"")
validate Q2 with IF(AND(Q1A1,Q2>100),"不能超过100","")

多个目标和连续范围

多个目标使用英文逗号分隔:

if Q1A1 then show Q2,Q3,Q4

连续目标使用 ~

if Q1A1 then show Q2~Q5
if Q1A1 then hide Q2A1~Q2A4
if Q1A1 then show QS1Q1~QS1Q3

范围两端必须是完整标签。Q2~Q5 可以识别,Q2~5 不会识别。

条件表达式

if OR(Q1A1,Q1A2) then show Q2
if AND(Q1A1,Q2>18) then show Q3
if NOT(Q1A3) then hide Q4

常用运算符:

运算符含义
>大于
<小于
>=大于等于
<=小于等于
==等于
!=不等于
+ - * / %加、减、乘、除、取余

跳转语法

if 条件 then branch from 起点 to 终点
if Q1A1 then branch from Q1 to Q5
if Q1A2 then branch from Q1 to END

fromto 必须使用编辑器可见的 DSL 标签;终点可以使用 END。这里不要填写保存后的 #{...} 底层变量。

默认值

当题目未填写、选项未选中或值为空时,可以提供默认值:

assignment Q2 with Q1|0
assignment Q3 with Q1A1|222
assignment Q4 with DEFAULT(Q1A1,222)

Q1A1|222DEFAULT(Q1A1,222) 都表示 Q1A1 为空时返回 222

当前不支持的写法

以下写法不要用于正式问卷:

if Q1A1 then assignment Q2 with 100
if Q1A1 then validate Q2 with "错误"
if Q1A1 then replace Q2 with "新标题"
mutex Q1A1 deselect Q1A6
shuffle Q1A1~Q1A4
random show 1 from Q1~Q3

前 3 种动作必须使用独立的 ... with ... 语句;mutexshufflerandom show 当前没有正式运行能力。

相关文档