User Tools

Site Tools


semantics_specification

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
semantics_specification [2012/02/23 13:22] – [Native function semantics] xjiasemantics_specification [2012/03/25 13:57] (current) – [Operator types] mhwang
Line 1: Line 1:
 ====== General considerations ====== ====== 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名字,都不能重名,他们之间也不能重名   * native函数、普通函数、record名字,都不能重名,他们之间也不能重名
   * record的fields也不能重名(但可以和record本身同名,或与其他函数同名)   * record的fields也不能重名(但可以和record本身同名,或与其他函数同名)
   * 函数内变量之间不能重名,与top level的native函数、普通函数、record名字也不能重名   * 函数内变量之间不能重名,与top level的native函数、普通函数、record名字也不能重名
-  * continue和break必须在循环里(for或者while) 
-  * 函数所有control flow末端(主要是if)必须有return语句,且return的表达式类型与函数返回类型一致 
-  * if/while/for的条件(cond)类型必须是int(0表示false,非零表示true) 
  
 ====== Operator types ====== ====== Operator types ======
Line 11: Line 19:
 ^ '',''             | (a,b)->b | ^ '',''             | (a,b)->b |
 ^ ''=''             | (a,a)->a | null是任意record type | ^ ''=''             | (a,a)->a | null是任意record type |
-^ ''||'' and ''&&'' | (int,int)->{0,1} | +^ ''||'' and ''&&'' | (int,int)->{0,1} | 短路逻辑 
-^ ''=='' and ''!='' | (a,a)->{0,1} | record的比较是比较地址而不是值 |+^ ''=='' and ''!='' | (a,a)->{0,1} | record/array的比较是比较地址而不是值 |
 ^ ::: | ::: | 字符串比较的是值而不是地址 | ^ ::: | ::: | 字符串比较的是值而不是地址 |
-^ ''<'', ''<''''='', ''>'' and ''>='' | (a,a)->{0,1} | 不能比较record |+^ ''<'', ''<''''='', ''>'' and ''>='' | (a,a)->{0,1} | 不能比较record/array |
 ^ ::: | ::: | 字符串按字典序比较 | ^ ::: | ::: | 字符串按字典序比较 |
 ^ ''+'' | 见加法类型表 || ^ ''+'' | 见加法类型表 ||
-^ ''-'', ''*'', ''/'' and ''%'' | (int,int)->int | 不需要检查是否零 |+^ ''-'', ''*'', ''/'' and ''%'' | (int,int)->int | 编译器负责检查除数是否零 |
 ^ ''!'' | int->{0,1} | ^ ''!'' | int->{0,1} |
 ^ ''+'' and ''-'' | int->int | 一元运算仅适合int类型 | ^ ''+'' and ''-'' | int->int | 一元运算仅适合int类型 |
  
 ^ 加法类型表 ^^ Right-hand side |||| ^ 加法类型表 ^^ Right-hand side ||||
-^::: ^^ int ^ char ^ string ^ record |+^::: ^^ int ^ char ^ string ^ record/array |
 ^ Left-hand side ^ int | int | int | string | (error) | ^ Left-hand side ^ int | int | int | string | (error) |
 ^ ::: ^ char | int | int | string | (error) | ^ ::: ^ char | int | int | string | (error) |
 ^ ::: ^ string | string | string | string | (error) | ^ ::: ^ string | string | string | string | (error) |
-^ ::: ^ record | (error) | (error) | (error) | (error) |+^ ::: ^ record/array | (error) | (error) | (error) | (error) |
  
 ====== Native function semantics ====== ====== Native function semantics ======
 ^ ''char chr(int i)'' | 只取参数的低8位 | ^ ''char chr(int i)'' | 只取参数的低8位 |
 ^ ''int ord(char c)'' | | ^ ''int ord(char c)'' | |
semantics_specification.1330003367.txt.gz · Last modified: 2012/02/23 13:22 by xjia

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki