semantics_specification
This is an old revision of the document!
General considerations
- native函数、普通函数、record名字,都不能重名,他们之间也不能重名
- record的fields也不能重名(但可以和record本身同名,或与其他函数同名)
- 函数内变量之间不能重名,与top level的native函数、普通函数、record名字也不能重名
- continue和break必须在循环里(for或者while)
- 函数所有control flow末端(主要是if)必须有return语句,且return的表达式类型与函数返回类型一致
- if/while/for的条件(cond)类型必须是int(0表示false,非零表示true)
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 | ||
Left-hand side | int | int | int | string | (error) |
char | int | int | string | (error) | |
string | string | string | string | (error) | |
record | (error) | (error) | (error) | (error) |
semantics_specification.1330002926.txt.gz · Last modified: 2012/02/23 13:15 by xjia