Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DaemondShu committed Dec 25, 2015
2 parents 7aa7898 0957b85 commit 42b0c88
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 102 deletions.
Binary file modified Compiler/ZodiacConsole.exe
Binary file not shown.
20 changes: 5 additions & 15 deletions Compiler/test/error.zs
Original file line number Diff line number Diff line change
@@ -1,15 1,5 @@

func ok : long
{
param i = long;
param j = long;
return x j;
}




var i = ~111;
var j = 44 99 / 66 * 55 ok(11,22);

@@ ^^ 没实现
func ok : long {
param i = long;
param j = long;
return x j;
}
31 changes: 0 additions & 31 deletions Compiler/test/expression.zs

This file was deleted.

29 changes: 29 additions & 0 deletions Compiler/test/expression_test.zs
Original file line number Diff line number Diff line change
@@ -0,0 1,29 @@
var number = 42;
IO.writeln(number);
number = 1;
IO.writeln(number);

var float_number = 3.14;
IO.writeln(float_number);

var a, b = 3, 4;
IO.writeln(a);
IO.writeln(b);

var ch = "a";
IO.writeln(ch);

var flag = number > 0;
IO.writeln(flag);

var lst = list(1, 10);
IO.writeln(lst);
lst = list(2, 4, 1); @@ 列表的下标为23,长度为2,并且填充为1
IO.writeln(lst);
lst = list(2, 4, 1, 4);
IO.writeln(lst);
lst = list();
IO.writeln(lst);
lst = list(2, 10, 1, 4);
IO.writeln(lst);
IO.writeln(lst[4]);
17 changes: 17 additions & 0 deletions Compiler/test/func.zs
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
func foo : long {
param i = long;
param k = long;

IO.writeln(i);
return k 1;
}

func foo : real {
param i = long;
param k = real;

IO.writeln(i);
return k 1.414;
}

IO.writeln(foo(2, 1.1));
25 changes: 0 additions & 25 deletions Compiler/test/select_qsort.zs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 1,3 @@

var n = 0;
n = IO.readln();
var l = list();
Expand All @@ -13,13 12,10 @@ for i in list(0, n) {
if (l[j] > max) {
max = l[j];
maxi = j;
IO.writeln(max);
}
}
IO.writeln(i);
l[maxi] = l[i];
l[i] = max;
IO.writeln(l);
}

IO.writeln(l);
23 changes: 23 additions & 0 deletions Compiler/test/type.zs
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
type Complex {
var r = long;
var i = long;

func _init {
param rr = long;
param ii = long;
r = rr;
i = ii;
}

oper : long {
param a = Complex;
param b = Complex;

return a.r b.r;
}
}


var cA = Complex(1, 1);
var cB = Complex(2, 2);
IO.writeln(cA cB);
58 changes: 31 additions & 27 deletions Iteration3/LanguageDesignV1-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 89,15 @@ True || False @@ 或运算,得True
变量定义时使用`var`作为关键字,在定义时可以声明变量类型,或者直接赋值立即数,以`;`结束语句。

```
var number1 = 42; var number2 = long(42); @@ number = 42
var number1 = 42; var number2 = long(42); @@ number = 42
var float_number = real(3.14); @@ float_number = 3.14
var ch = char('a'); @@ ch = 'a'
@same as var ch = char("a");
var flag = True; @@ flag = True(or False)
var lst = list(1, 3); @@ lst = [1, 2]
var lst_2 = list(2,4,1); @@ 列表的下标为2到3,长度为2,并且填充为1。
var lst_3 = list(2,4,1, 4)
var lst_3 = list(2,4,1, 4);
@{
列表的下标为2到3,长度为2,并且填充值为1, 2。
如果填充列表小于列表长度,其余项填充0。
Expand All @@ -108,11 108,11 @@ var lst_3 = list(2,4,1, 4);
如果想使用类型的默认值,可以这样写:

```
var number = long; @@ number = 0
var float_number = real; @@ float_number = 0.0
var ch = char; @@ ch = '\0'
var flag = bool; @@ flag = False
var lst = list; @@ lst = []
var number = long(); @@ number = 0
var float_number = real(); @@ float_number = 0.0
var ch = char(); @@ ch = '\0'
var flag = bool(); @@ flag = False
var lst = list(); @@ lst = []
```

### 函数定义
Expand All @@ -130,15 130,12 @@ var lst = list; @@ lst = []
举例如下:

```
func Foo : long{
@@ 参数设定块
param flag = bool;
param i, j := long, long; @@ 传值
param k := long(1); @@ 传值
func Foo : long {
param i = long;
param k = long;
@@ 函数执行块
do_something();
return ret_1;
IO.writeln(i);
return k 1;
}
```

Expand All @@ -158,18 155,27 @@ do_something(foo, bar);
如果函数的形参类型不同,则可以进行重载,举例如下:

```
func foo {
func foo : long {
param i = long;
return i;
param k = long;
IO.writeln(i);
return k 1;
}
func foo {
param i = bool;
return !i;
func foo : real {
param i = long;
param k = real;
IO.writeln(i);
return k 1.414;
}
IO.writeln(foo(2, 1.1));
```

在调用时如果采用`long`类型调用,则调用第一个`foo`函数,如果采用`bool`类型调用,则调用第二个`foo`函数。
在调用时如果采用第二个参数`long`类型调用,则调用第一个`foo`函数,如果采用`real`类型调用,则调用第二个`foo`函数。


#### 操作符重载
Expand All @@ -186,14 192,12 @@ oper : long {

### 变量赋值

我们可以采用`=`关键字将等号右边的对象赋值给等号左边的对象,同时Z语言也支持多重赋值,将等号右边的对象一次赋值到等号左边的对象中。
我们可以采用`=`关键字将等号右边的对象赋值给等号左边的对象,同时Zodiac语言也支持多重赋值,将等号右边的对象一次赋值到等号左边的对象中。

举例如下:

```
a = b; @@ 把b的对象赋值给a
a, b = c, d; @@ 把c的对象赋值给a,把d的对象赋值给b
a, b = b, a; @@ 交换a和b的对象
var a, b = 3, 4;
```


Expand Down Expand Up @@ -312,7 316,7 @@ while (True) { @@ 此处将不断循环
在生成列表时,为了简化代码,增强列表的功能,Z语言提供了一种内联的查询语句。采用了`select`, `from`, `where`语句来实现,举例如下:

```
var even_numbers =
var even_numbers =
from item in list(1, 100)
where item % 2 == 0
select item
Expand Down Expand Up @@ -347,7 351,7 @@ real => long: 1.5 => long = 1

在继承关系中,也支持继承类型之间的转换,如果想使用多态特性,需要显式地使用转换功能使得父类子类函数相互调用,举例如下:

```type Base
```type Base
{
var x = long;
func _init
Expand Down

0 comments on commit 42b0c88

Please sign in to comment.