User Tools

Site Tools


semantics_specification

This is an old revision of the document!


General considerations

  • continue和break必须在循环里(for或者while)
  • a.b:如果a是string或array类型,b只能为length;如果a是record类型,b必须是一个field的名字
  • 不需要检查函数所有control flow末端是否都有return语句

类型匹配

  • return的表达式类型与函数返回类型一致
  • if/while/for的条件(cond)类型必须是int(0表示false,非零表示true)
  • [expr]前面必须是string或array类型,expr必须是int类型

命名空间

  • native函数、普通函数、record名字,都不能重名,他们之间也不能重名
  • record的fields也不能重名(但可以和record本身同名,或与其他函数同名)
  • 函数内变量之间不能重名,与top level的native函数、普通函数、record名字也不能重名

Operator types

类型映射 说明
, (a,b)→b
= (a,a)→a null是任意record type
|| and && (int,int)→{0,1} 短路逻辑
== and != (a,a)→{0,1} record的比较是比较地址而不是值
字符串比较的是值而不是地址
<, <=, > and >= (a,a)→{0,1} 不能比较record
字符串按字典序比较
+ 见加法类型表
-, *, / and % (int,int)→int 编译器不负责检查除数是否为零
! int→{0,1}
+ and - int→int 一元运算仅适合int类型
加法类型表 Right-hand side
int char string record/array
Left-hand side int int int string (error)
char int int string (error)
string string string string (error)
record/array (error) (error) (error) (error)

Native function semantics

char chr(int i) 只取参数的低8位
int ord(char c)
semantics_specification.1330256322.txt.gz · Last modified: 2012/02/26 11:38 by xjia

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki