Giter Club home page Giter Club logo

wenyan's Introduction

文言 wenyan-lang

npm build Netlify Status

English | 简体中文 | 繁體中文

文言文編程語言。A programming language for the ancient Chinese. Try it online.

CHANGELOG

之世,結繩而足治,屈指而足算。是時豈料百代之後,計算機械之巧,精於公輸木鳶,善於武侯流馬;程式語言之多,繁若《天官》之星宿,奇勝《山經》之走獸。,或以速稱。,各爭文采。方知鬼之所以夜哭,天之所以雨粟。然以文言編程者 ,似所未有。此誠非文脈之所以傳,文心之所以保。嗟予小子,遂有斯志。然則數寸之烏絲猶覆於頭,萬卷之素書未破於手;一身長羈於遠邦,兩耳久曠于雅言。然夫文章者吾之所宿好,程式者偶承時人之謬譽。故希孟不慚年少,莊生不望無涯。乃作斯言。誠未能嘔瀝長吉心血,亦庶幾免於義山流沫。既成之後,復學干將鑄劍而自飼,越王嚐糞而當先。自謂偶追《十書》之筆意,但恨少八家之淋漓。此子山所謂士衡撫掌而甘心,平子見陋而固宜。然則雖實覆甕之質,尚存斧正之望;雖乏呂相之金,易字之渴蓋同。此亦開源之大義,吾輩之所以勉勵也。一笑。

Helloworld

Wenyan:

吾有一數。曰三。名之曰「甲」。
為是「甲」遍。
	吾有一言。曰「「問天地好在。」」。書之。
云云。

Equivalent JavaScript:

var n = 3;
for (var i = 0; i < n; i++) {
	console.log("問天地好在。");
}

Output:

問天地好在。
問天地好在。
問天地好在。

Punctuations and newlines are completely optional (just like they are in Classical Chinese), so the above code is equivalent to:

吾有一數曰三名之曰「甲」為是「甲」遍吾有一言曰「「問天地好在」」書之云云

More sophisticated examples, such as the Sieve of Eratosthenes, Quicksort, Mandelbrot set, and Tower of Hanoi, can be found in the ./examples folder.

Features

Try it out

Text Editor Plugins

Command Line Compiler

Install the compiler by

npm install -g @wenyan/cli

Try run the included examples, e.g.:

wenyan examples/helloworld.wy
# will output: 問天地好在。

You can now translate JavaScript to wenyan-lang using the wenyanizer by zxch3n.

3rd Party Compilers

Documentation

Check out our Wiki pages

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

wenyan's People

Contributors

ai-zixun avatar antfu avatar cuixiping avatar demongodyy avatar dependabot[bot] avatar fros1er avatar jacoblincool avatar jiangzoi avatar jingkecn avatar kaiyuan01 avatar kevinjycui avatar lancemoe avatar liaocm avatar lingdong- avatar lm2343635 avatar loozhengyuan avatar madao-3 avatar merakdipper avatar mio-19 avatar oovm avatar poyea avatar saafo avatar simon300000 avatar statementreply avatar stevefan1999-personal avatar tony-aptx4869 avatar user670 avatar yuren-tw avatar z-fly avatar zxch3n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wenyan's Issues

吾有一數。曰三。名之曰「甲」应更为 “置三为甲

<九章算术> 云
〔一一〕今有惡粟二十斗,舂之,得糲米九斗。今欲求粺米十斗,問︰惡粟幾何?

荅曰:二十四斗六升、八十一分升之七十四。
術曰:置糲米九斗,以九乘之,為法。亦置粺米十斗,以十乘之,又以惡粟二十斗乘之,為實。實如法得一斗。

How to work with objects?

古有一道法、以一物照一物、謂之曰「射」。 凡變數以「射」為原型者、謂之曰「對象」。 今有程序員者一人、遍讀此作而不知「對象」應作何書、方前來求問。

unexpected results when defining or outputting negative floating point number

The following wenyan code:

吾有一數。曰負一又二分三釐四毫五絲六忽七微,書之。

is compiled to the following JavaScript equivalent code:

var _ans138 = 1.234567;
console.log(_ans138);

However, it should be:

var _ans138 = -1.234567;
console.log(_ans138);

The following wenyan code:

乘一又二分三釐四毫五絲六忽七微以負一。名之曰「甲」。
吾有一數。曰 「甲」。書之。

produced the following output by compiled JavaScript code:

負undefined

But the output should be:

負一又二分三釐四毫五絲六忽七微

来点面向对象编程的思路

重点是封装和继承,是不是可以考虑这段:

北冥有鱼,其名为鲲。鲲之大,不知其几千里也。化而为鸟,其名 为鹏。鹏之背,不知其几千里也。怒而飞,其翼若垂天之云。是鸟也 ,海运则将徙于南冥。

想到一种switch语句的实现

简单地来自最熟悉的论语😂

吾日省「吾身」:
    其「七十七」乎?
            代码块一。
            乃止。
    其「六十六」乎?
            代码块二。
            乃止。
    若非也:
            代码块三。

临时起意想到的,还可以改一下,比如:

  1. “日省”可以改为“省”,因为加了“日”就有了一种是在循环之中的次序的感觉
  2. 因为case后面加的都是值,所以原文中没有“其”,我给加上了,感觉通顺一点
  3. 最后那个default翻译成“若非也”好像不是很妥当,但是我一时也想不到更好的了,见谅😂

Use Jest to automatically test the program

Instead of checking the error by human, we can use Jest to test automatically.

For example:

吾有一數。曰三。名之曰「甲」。

This sentence should init a variable call ,and it is 3

An Error In wenyan-lang

There's a slight error here that the number 「二百五」 will be mistaken for 205, which should be 250.

增加木兰诗支持

{唧唧复唧唧,木兰当户织}应该编译为:定义一个叫户的类,织是户的方法,唧是织别名,木兰是户的实例,然后在一个循环里木兰把唧执行了四次[偷笑]

示例代碼`一數五十。名之曰「大衍」。`錯誤編譯?

> cat examples/helloworld.txt
一數五十。名之曰「大衍」。

> ./build/wenyan examples/helloworld.txt -o hello.js

> cat hello.js
var DA4YAN3=_ans1;

> file examples/helloworld.txt
examples/helloworld.txt: UTF-8 Unicode text

> node -v
v8.10.0

五十並未出現?

Will some Math functions and constants be added?

For example:

  • 圓周率 -> Math.PI
  • 之平方/自乘 -> Math.pow(x, 2)
  • 之立方 -> Math.pow(x, 3)
  • 之平方根/開方除之 -> Math.sqrt(x)
  • 「甲」度之正弦值 -> Math.sin(x * Math.PI / 180)

Code example:

吾有一術。名之曰「勾股定理」。欲行是術。必先得二數。曰「勾」。曰「股」。乃行是術曰。
  批曰「「勾股各自乘,並之,為弦實,開方除之,即弦。」」
  「勾」自乘。名之曰「勾實」。
  「股」自乘。名之曰「股實」。
  加「勾實」以「股實」。開方除之。名之曰「弦」。
  乃得「弦」。
是謂「勾股定理」之術也。

施「勾股定理」於三。於四。書之。

Consider using identifier names directly

Currently Chinese identifier names are transformed into pinyin, which might cause a redefinition if the same pinyin is also defined using wenyan, like this:

Both ES2015 and Python 3 support Unicode identifier names, there shouldn't be much problem using it directly.

很有意思的项目呀,求勾搭

微信:Ahkari-ifly ~ 邮件发了没回复,只好发 issue 里来吸引大佬目光了。

另外各位大佬对 NLP 和前端智能感兴趣的都可以加我聊聊哈。

列index没对应上

列的“充” 与 夫 列 之xx。index没有对应上 。充没有-1但是夫列之xx-1了

Unexcepted results from loops

I tried following scripts

吾有一數。曰三。名之曰「甲」。
吾有一數。曰五。名之曰「乙」。
為是「甲」遍。
	加一以「乙」。書之。
云云。

And got "六 六 六". It should be “六 七 八”, right?

How to express these logic?

  1. a || !b

  2. !a || b

  3. !a && b

  4. a && !b

  5. a << 2

  6. a >> 2

  7. a >> n

  8. a << n

  9. this.

  10. constructor

  11. require()

  12. import

  13. a ** 2

  14. Math.sqrt()

  15. console.table()

[Proposal] Support ECMAScript6 Class Standard

Definition

吾有一經。名之曰「南山」。是經曰。⋯⋯是謂「南山」之經也。
class Foo {......}

Field

吾有一經。名之曰「生徒」。是經曰。
    其有一言,其名為「名」。
    其有数廿三,其名為「齡」。
是謂「生徒」之經也。
class Foo {
    name;
    age = 23;
}

Constructor & Method

吾有一經。名之曰「鳥」。是經曰。
    其有一言,其名為「名」。
    其有首術。欲行是術。必先得一言。曰「名」。乃行是術曰。
        充其「名」以「名」。
    是謂其首術也。
    其有一術。名之曰「飛」。是謂「飛」之術也。
是謂「鳥」之經也。

有「雞」焉,其状如「鳥」,其「名」曰「「鳳凰」」也。
class Foo {
    name;
    constructor(name) {
        this.name = name;
    }
    fly() {}
}

var foo = new Foo("鳳凰");

Extend

吾有一經。名之曰「鳥」。是經曰。
    其有一言,其名為「名」。
    其有首術。欲行是術。必先得一言。曰「名」。乃行是術曰。
        充其「名」以「名」。
    是謂其首術也。
    其有一術。名之曰「飛」。是謂「飛」之術也。
是謂「鳥」之經也。

吾有一經。名之曰「斥鴳」。状似「鳥」焉。是經曰。
    其有一術。名之曰「飛」。
        吾有一言。曰「「我騰躍而上,不過數仞而下,翺翔蓬蒿之間,恥亦飛之至也」」。書之。
    是謂「飛」之術也。
是謂「斥鴳」之經也。

有「雞」焉,其状如「斥鴳」,其「名」曰「「學鸠」」也。
夫「雞」之「飛」者。施之。
class Foo {
    name;
    constructor(name) {
        this.name = name;
    }
    fly() {}
}

class Bar extends Foo {
    fly() {
         console.log("我騰躍而上,不過數仞而下,翺翔蓬蒿之間,恥亦飛之至也");
    }
}

var bar = new Bar("學鸠");
bar.fly();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.