通用语法 (部分)
- 变量声明
- 类型:
Real
,Integer
,Boolean
- 前缀:
input
,output
,parameter
- 可见性:
public
,protected
- 类型:
- 算术运算:
+
,-
,*
,/
- 注释:
- 单行注释:
// this is a line comment
- 多行注释:
/* this is a block comment */
- 引号注释:
Real foo "A special comment";
- 单行注释:
- 数组:
x[3]
:一维数组 (3-element vector)x[3, 3]
:二维数组 (3x3 matrix)
- 逻辑运算符:
and
,or
,not
,<
,>
,<>
,<=
,>=
- 条件语句:
if <condition> then ... elseif <condition> then ... else ... end if;
- 循环语句:
for i in 1:10 loop ... end for;
函数语法
- 参数声明:
input
- 输出声明:
output
- 赋值运算符:
:=
- 特点(部分):
- 自上至下顺序执行
- 参数引用方式为只读, 即函数内无法更改输入参数数值
函数语法及调用
- 分区标识符
- 函数内容:
algorithm
- 局部变量:
protected
- 函数内容:
- 参数默认值:
input Real tol = 1e-5 "Input with default value"
- 多个输出变量
- 调用
函数模板
function <函数名>
input TypeI1 in1;
input TypeI2 in2;
input TypeI3 in3 = <默认值> "注释" annotation(...);
...
output TypeO1 out1;
output TypeO2 out2 = <默认值>;
protected
<局部变量>
...
algorithm
<语句>
...
end <函数名>;