首页 科技资讯大全正文

文言文亦能编程,该项目在GitHub摘得5500星

IT前沿12月18日劲爆消息 有美国开发者上传的文言文編程語言其他项目现在在Git智能家居产品h智能家居产品ub上摘得了5500星,你可知如何去用文言文输出“H智能家居产品ello World”?吾过一 言。曰「「問天地好在。」」。書之。

据悉,该文言文编程语言图片频道CMU本科生Huang Lingdong。可编译成Javascri智能家居产品pt,也可编译成Python,亦有线上编辑器 (IDE) 可直接选择运行。

GitHub店地址:https://github.com/LingDong智能家居产品-/wenyan-lang

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

Hello world

Wenyan:

吾过一

數。曰三。名之曰「甲」。為是「甲」遍。吾过一

言。曰「「問天地好在。」」。書之。云云。

Equivalent JavaScript:

varn=3;for(vari=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./examplesfolder.

Features

AnNLPsharing the grammar ofClassical Chinese

Compiles toJavaScriptorPython

Turing complete

Anonline IDE

Examplesto get started

InstallationThe Compiler

Clone the repo, (OR simply download./build/wenyan.jsand set its executable bit using the terminal commandchmod +x wenyan.js). Then run./build/wenyan.jsto compile your wenyan souce code to target language. Calling the compiler without arguments prints the help message, reproduced below:

Usage:wenyan[options][inputfiles]Options:--eval-e<string>:Giveastringinsteadofafile(default:`')--exec-x<boolean>:Executeoutput(default:`false')--inspect-i<boolean>:InteractiveREPL(default:`false')--lang-l<string>:Language:js/py(default:`js')--log<string>:Logfile(default:`/dev/null')--output-o<string>:Outputfile(default:`/dev/stdout')--roman-r<boolean>:Romanizeidentifiers(default:`true')

Try building the included examples first, e.g.:

./build/wenyan.jsexamples/helloworld.wy-ohelloworld.js

Building platform-specific binaries

Clone the repo

npm install

npm run make_cmdline

The macOS, Windows and Linux binaries will be in the./buildfolder.

Syntax Cheatsheet

A context-free grammar description is under construction. Meanwhile, please check the cheatsheet below, or look intosrc/parser.jsto learn about the syntax. Be sure to check out the examples from the online IDE too!

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。