Skip to content

Commit b64799b

Browse files
authored
Merge pull request #505 from LingDong-/master
v0.2.2
2 parents 8f87c0f + 83d505e commit b64799b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1312
-74375
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
<img src="screenshots/logo.png" align="right" width="100" height="100"/>
1+
<img src="screenshots/logo.png" align="right" width="128" height="128"/>
22

33
# 文言 wenyan-lang
44

55
[![npm](https://img.shields.io/npm/v/@wenyanlang/core)](https://www.npmjs.com/package/@wenyanlang/core)
66
[![build](https://img.shields.io/github/workflow/status/LingDong-/wenyan-lang/Build%20%26%20Test)](https://github.com/LingDong-/wenyan-lang/actions)
7+
[![Netlify Status](https://api.netlify.com/api/v1/badges/c36d4838-1c8f-4cfe-986e-43e0de6f71a3/deploy-status)](https://app.netlify.com/sites/wenyan-lang/deploys)
78

8-
[http://wenyan-lang.lingdong.works](http://wenyan-lang.lingdong.works)
9+
### [https://wy-lang.org](https://wy-lang.org)
910

1011
English | [简体中文](./README.zh-Hans.md) | [繁体中文](./README.zh-Hant.md)
1112

12-
文言文編程語言。A programming language for the ancient Chinese. [Try it online.](http://wenyan-lang.lingdong.works/ide.html)
13+
文言文編程語言。A programming language for the ancient Chinese. [Try it online.](https://wy-lang.org/ide)
1314

1415
![](screenshots/screenshot01.png)
1516

@@ -59,7 +60,7 @@ More sophisticated examples, such as the Sieve of Eratosthenes, Quicksort, Mande
5960
- [Natural Language Programming](https://en.wikipedia.org/wiki/Natural-language_programming) sharing the grammar of [Classical Chinese](https://en.wikipedia.org/wiki/Classical_Chinese)
6061
- Compiles to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Python](https://python.org), or [Ruby](http://ruby-lang.org)
6162
- [Turing complete](https://github.com/LingDong-/wenyan-lang/blob/master/examples/turing.wy)
62-
- An [online IDE](http://wenyan-lang.lingdong.works/ide.html)
63+
- An [online IDE](https://wy-lang.org/ide)
6364
- [Examples](https://github.com/LingDong-/wenyan-lang/tree/master/examples) to get started
6465

6566

@@ -83,7 +84,7 @@ wenyan examples/helloworld.wy
8384
> From v0.1.0, the `wenyan` command will direct execute the script by default. If you are migrating from previous versions, please use `wenyan -h` to output the help and check [this PR](https://github.com/LingDong-/wenyan-lang/pull/356) for the detailed changes.
8485
8586

86-
### [The Online IDE](http://wenyan-lang.lingdong.works/ide.html)
87+
### [The Online IDE](https://wy-lang.org/ide)
8788

8889
![](screenshots/screenshot02.png)
8990

@@ -114,7 +115,7 @@ Please refer to [Browser Runtime](./documentation/Runtime.md)
114115

115116
## Syntax Cheatsheet
116117

117-
A context-free grammar description is under construction. Meanwhile, please check the cheatsheet below, or look into `src/parser.js` to learn about the syntax. Be sure to check out the examples from the online IDE too!
118+
You can find the Language Specification [here](https://wy-lang.org/spec) (WIP). To get started, you can also check the cheatsheet below, or look into `src/parser.js` to learn more. Be sure to check out the examples from the online IDE too!
118119

119120
### Variables
120121

documentation/Standard-Lib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Add comments in the stdlib files (one line above the function/value), the format
141141

142142
After you fill the comments, you need to update the document by running
143143
```bash
144-
npm run docs:update
144+
npm run build:docs
145145
```
146146

147147
Check the output document out and submit a pull request. Thank you!

documentation/wenyan.g4

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
grammar wenyan;
2+
program : statement* ;
3+
statement : declare_statement
4+
| define_statement
5+
| print_statement
6+
| for_statement
7+
| function_statement
8+
| if_statement
9+
| return_statement
10+
| math_statement
11+
| assign_statement
12+
| import_statement
13+
| object_statement
14+
| reference_statement
15+
| array_statement
16+
| flush_statement
17+
| BREAK
18+
| comment;
19+
20+
reference_statement : '' data ('' (STRING_LITERAL|INT_NUM|'其餘'|IDENTIFIER|''))? name_single_statement? ;
21+
22+
23+
array_statement : array_cat_statement|array_push_statement ;
24+
array_cat_statement : '' (IDENTIFIER|'') (PREPOSITION_RIGHT IDENTIFIER)+ name_single_statement?;
25+
array_push_statement : '' (IDENTIFIER|'') (PREPOSITION_RIGHT data)+ name_single_statement?;
26+
27+
28+
function_statement : function_define_statement|(function_call_statement (name_single_statement)?) ;
29+
function_call_statement : function_pre_call|function_post_call ;
30+
function_pre_call : ('' IDENTIFIER (preposition data)*)|('施其' (preposition data)*) ;
31+
function_post_call : ('' INT_NUM '以施' IDENTIFIER)+ ;
32+
function_define_statement : '吾有' INT_NUM '' name_single_statement ('欲行是術' '必先得' (INT_NUM TYPE ('' IDENTIFIER)+)+)? ('是術曰'|'乃行是術曰') statement* '是謂' IDENTIFIER '之術也' ;
33+
34+
35+
if_statement : IF if_expression '' statement+ (ELSE statement+)? FOR_IF_END ;
36+
if_expression : unary_if_expression|binary_if_expression ;
37+
unary_if_expression : data|(IDENTIFIER ''(''|STRING_LITERAL|IDENTIFIER))|'' ;
38+
binary_if_expression : unary_if_expression IF_LOGIC_OP unary_if_expression ;
39+
40+
41+
declare_statement : ('吾有'|'今有') INT_NUM TYPE ('' data)*;
42+
define_statement : (declare_statement name_multi_statement)|init_define_statement ;
43+
44+
45+
name_multi_statement : '名之' ('' IDENTIFIER)+ ;
46+
name_single_statement : '名之' ('' IDENTIFIER) ;
47+
init_define_statement : '' TYPE data (name_single_statement)? ;
48+
49+
50+
for_statement : for_arr_statement
51+
| for_enum_statement
52+
| for_while_statement ;
53+
for_arr_statement : FOR_START_ARR IDENTIFIER FOR_MID_ARR IDENTIFIER statement* FOR_IF_END ;
54+
for_enum_statement : FOR_START_ENUM (INT_NUM|IDENTIFIER) FOR_MID_ENUM statement* FOR_IF_END ;
55+
for_while_statement : FOR_START_WHILE statement* FOR_IF_END ;
56+
57+
58+
math_statement : (arith_math_statement|boolean_algebra_statement|mod_math_statement) (name_multi_statement)? ;
59+
arith_math_statement : arith_binary_math|arith_unary_math ;
60+
arith_binary_math : ARITH_BINARY_OP (data|'') preposition (data|'') ;
61+
arith_unary_math : UNARY_OP (IDENTIFIER|'') ;
62+
mod_math_statement : '' (INT_NUM|FLOAT_NUM|IDENTIFIER|'') preposition (INT_NUM|FLOAT_NUM|IDENTIFIER) POST_MOD_MATH_OP? ;
63+
boolean_algebra_statement : '' IDENTIFIER IDENTIFIER LOGIC_BINARY_OP ;
64+
65+
66+
assign_statement : '昔之' IDENTIFIER ('' (INT_NUM|STRING_LITERAL|IDENTIFIER))? '' (('' ((data ('' INT_NUM)?)|'') '是矣')|'今不復存矣') ;
67+
68+
69+
return_statement : '乃得' (data|'')|'乃歸空無'|'乃得矣' ;
70+
71+
72+
import_statement : '吾嘗觀' STRING_LITERAL '之書' ('方悟' IDENTIFIER+ '之義')? ;
73+
74+
75+
object_statement : '吾有' INT_NUM '' name_multi_statement (object_define_statement)? ;
76+
object_define_statement : '其物如是' ('物之' STRING_LITERAL '' TYPE '' data)+ '是謂' IDENTIFIER '之物也' ;
77+
78+
79+
data : STRING_LITERAL|BOOL_VALUE|IDENTIFIER|INT_NUM|FLOAT_NUM ;
80+
81+
STRING_LITERAL : '「「' ( ~('') )* '」」' ;
82+
IDENTIFIER : '' ( ~('') )+ '' ;
83+
84+
ARITH_BINARY_OP : ''|''|'' ;
85+
LOGIC_BINARY_OP : '中有陽乎'|'中無陰乎' ;
86+
POST_MOD_MATH_OP : '所餘幾何' ;
87+
UNARY_OP : '' ;
88+
89+
preposition : PREPOSITION_LEFT|PREPOSITION_RIGHT ;
90+
PREPOSITION_LEFT : '' ;
91+
PREPOSITION_RIGHT : '' ;
92+
93+
IF : '' ;
94+
ELSE : '若非' ;
95+
IF_LOGIC_OP : '等於'|'不等於'|'不大於'|'不小於'|'大於'|'小於' ;
96+
97+
FOR_START_ARR : '' ;
98+
FOR_START_ENUM : '為是' ;
99+
FOR_START_WHILE : '恆為是' ;
100+
FOR_MID_ARR : '中之' ;
101+
FOR_MID_ENUM : '' ;
102+
FOR_IF_END : '云云'|'' ;
103+
104+
FLOAT_NUM : INT_NUM '' (INT_NUM FLOAT_NUM_KEYWORDS)+ ;
105+
FLOAT_NUM_KEYWORDS : ''|''|''|''|''|''|''|''|''|'' ;
106+
INT_NUM : INT_NUM_KEYWORDS+ ;
107+
108+
INT_NUM_KEYWORDS : ''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|'' ;
109+
TYPE : ''|''|''|'' ;
110+
BOOL_VALUE : ''|'' ;
111+
print_statement : '書之' ;
112+
113+
WS : ([ \t\r\n]|''|'')+ -> skip ;
114+
comment : ('注曰'|'疏曰'|'批曰') STRING_LITERAL ;
115+
flush_statement : '' ;
116+
117+
BREAK : '乃止' ;

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| [tree2.wy](tree2.wy) | 畫樹二 |
4040
| [try.wy](try.wy) | 異常處理示例 |
4141
| [turing.wy](turing.wy) | 圖靈機 |
42+
| [pascal_triangle.wy](pascal_triangle.wy) | 賈憲三角 |
4243

4344
[1]: https://en.wikipedia.org/wiki/Fizz_buzz
4445
[2]: https://zh.wikipedia.org/wiki/自產生程式

examples/pascal_triangle.wy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
吾有一術。名之曰「賈憲三角」。欲行是術。必先得一數。曰「層數」。乃行是術曰。
2+
吾有一列。名之曰「前層之得」。
3+
充「前層之得」以一。夫「前層之得」。書之。
4+
若「層數」等於一者乃歸空無也。
5+
6+
充「前層之得」以一。夫「前層之得」。書之。
7+
若「層數」等於二者乃歸空無也。
8+
9+
有數三。名之曰「計甲」。
10+
恆為是。若「計甲」大於「層數」者乃止也。
11+
吾有一列。名之曰「此層之得」。
12+
充「此層之得」以一。
13+
有數一。名之曰「計乙」。
14+
夫「前層之得」之長。名之曰「層長」。
15+
恆為是。若「計乙」不小於「層長」者乃止也
16+
加一以「計乙」。名之曰「計乙又一」
17+
夫「前層之得」之「計乙」。名之曰「數甲」。
18+
夫「前層之得」之「計乙又一」。名之曰「數乙」。
19+
加「數甲」以「數乙」。名之曰「新數」。
20+
充「此層之得」以「新數」。
21+
加「計乙」以一。昔之「計乙」者。今其是矣。
22+
云云。
23+
充「此層之得」以一。夫「此層之得」。書之。
24+
昔之「前層之得」者。今「此層之得」是矣。
25+
加「計甲」以一。昔之「計甲」者。今其是矣。
26+
云云
27+
是謂「賈憲三角」之術也。
28+
29+
施「賈憲三角」於九。

lib/js/位經.wy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535

3636
疏曰「「位變。同犀之~x也。」」
3737
今有一術。名之曰「位變」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
38-
施「(x=>y=>(~x))」於「甲」。名之曰「乙」。乃得「乙」。
38+
施「(x=>(~x))」於「甲」。名之曰「乙」。乃得「乙」。
3939
是謂「位變」之術也。

lib/列經.wy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
今有一術。名之曰「擷取」。欲行是術。必先得一列。曰「甲」。二數。曰「乙」曰「丙」。乃行是術曰。
8787
吾有一列。名之曰「丁」。
8888
吾有一數。曰「乙」。名之曰「戊」。
89-
若「丙」小於零者。夫「甲」之長。加其以「丙」。昔之「丙」者。今其是矣。
89+
若「丙」小於零者。夫「甲」之長。加其以「丙」。昔之「丙」者。今其是矣。云云。
9090

9191
恆為是。若「戊」大於「丙」者乃止也。
9292
夫「甲」之「戊」。充「丁」以其。

lib/曆法.wy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
夫「乙」之「「商」」。加其以一。夫「數字」之其。加其以「「十」」。昔之「數」者。今其是矣。云云。
150150
夫「乙」之「「餘」」。若其大於零者。
151151
夫「乙」之「「餘」」。加其以一。夫「數字」之其。加「數」以其。昔之「數」者。今其是矣。云云。
152-
乃得「數」
152+
乃得「數」。
153153
是謂「言百內數」之術也。
154154

155155
吾有一術。名之曰「言年月日」。欲行是術。必先得一數。曰「積日」。乃行是術曰。
@@ -173,6 +173,7 @@
173173
夫「年」。取一以施「言百內數」。加其以「「年」」。加「年月日」以其。昔之「年月日」者。今其是矣。
174174
若非。
175175
夫「年」。取一以施「言序數」。加其以「「年」」。加「年月日」以其。昔之「年月日」者。今其是矣。
176+
云云。
176177
減一於「積年」。除其以十。所餘幾何。加其以一。夫「天干」之其。加「年月日」以其。昔之「年月日」者。今其是矣。
177178
減一於「積年」。除其以十二。所餘幾何。加其以一。夫「地支」之其。加「年月日」以其。昔之「年月日」者。今其是矣。
178179
加「年月日」以「「年」」。昔之「年月日」者。今其是矣。
@@ -183,6 +184,7 @@
183184
加「年月日」以「「正月」」。昔之「年月日」者。今其是矣。
184185
若非。
185186
夫「月」。取一以施「言百內數」。加其以「「月」」。加「年月日」以其。昔之「年月日」者。今其是矣。
187+
云云。
186188

187189
若「日」不大於十者。
188190
加「年月日」以「「初」」。昔之「年月日」者。今其是矣。云云。
@@ -249,7 +251,7 @@
249251
今有一術。名之曰「言彼之時刻」。欲行是術。必先得一數。曰「時」。乃行是術曰。
250252
施「時差」於「時」。加其於「時」。名之曰「甲」。
251253
夫「甲」。夫八萬六千四百。取二以施「取底除」。名之曰「乙」。
252-
夫「乙」之「「餘」」。取一以施「言時刻」。乃得矣。
254+
夫「乙」之「「餘」」。取一以施「取底」。取一以施「言時刻」。乃得矣。
253255
是謂「言彼之時刻」之術也。
254256

255257
注曰「「彼年何年號。同Javascript之"西元" for modern dates也。」」
@@ -347,7 +349,7 @@
347349
今有一術。名之曰「彼秒何秒」。欲行是術。必先得一數。曰「時」。乃行是術曰。
348350
施「時差」於「時」。加其於「時」。名之曰「甲」。
349351
夫「甲」。夫六十。取二以施「取底除」。
350-
取一以施「取底」。乃得矣。
352+
夫其之「「餘」」。取一以施「取底」。乃得矣。
351353
是謂「彼秒何秒」之術也。
352354

353355
吾有一術。名之曰「月積何日」。欲行是術。必先得一數。曰「積月」。乃行是術曰。

0 commit comments

Comments
 (0)