文言编程 wenyan‑lang – Programming Language for the ancient Chinese - 猫猫得天空♂

/ 0评 / 0

文言编程 wenyan‑lang - Programming Language for the ancient Chinese

 

文言, or wenyan, is an esoteric programming language that closely follows the grammar and tone of classical Chinese literature. Moreover, the alphabet of wenyan contains only traditional Chinese characters and 「」 quotes, so it is guaranteed to be readable by ancient Chinese people. You too can try it out on the online editordownload a compiler, or view the source code.

v2-859a6db439401a99cec8a62000c48a12_720w.webp

Syntax

Syntax of wenyan is just like that of its namesake, classical Chinese:

天地,好在否!/ HELLO WORLD ▶︎

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

The code above is editable, go ahead customize the greeting and hit ▶︎! Another slightly more sophisticated example, using the sieve of Erathosthenes to find prime numbers:

埃氏筛 / SIEVE OF ERATOSTHENES ▶︎

吾有一術。名之曰「埃氏篩」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
	吾有一列。名之曰「掩」。為是「甲」遍。充「掩」以陽也。
	除「甲」以二。名之曰「甲半」。

	有數二。名之曰「戊」。恆為是。若「戊」等於「甲半」者乃止也。
		有數二。名之曰「戌」。恆為是。若「戌」等於「甲半」者乃止也。

			乘「戊」以「戌」。名之曰「合」
			若「合」不大於「甲」者。
				昔之「掩」之「合」者。今陰是矣。
			若非乃止也。
		加一以「戌」。昔之「戌」者。今其是矣云云。
	加一以「戊」。昔之「戊」者。今其是矣云云。

	吾有一列。名之曰「諸素」。
	昔之「戊」者。今二是矣。恆為是。若「戊」等於「掩」之長者乃止也。
		夫「掩」之「戊」。名之曰「素耶」。
		若「素耶」者充「諸素」以「戊」也。
	加一以「戊」。昔之「戊」者。今其是矣云云。
	乃得「諸素」。
是謂「埃氏篩」之術也。

施「埃氏篩」於一百。書之。
二。三。五。七。一十一。一十三。一十七。一十九。二十三。二十九。三十一。三十七。四十一。四十三。四十七。五十三。五十九。六十一。六十七。七十一。七十三。七十九。八十三。八十九。九十七

You can find many more examples such as a Universal Turing Machine, a Mandelbrot set plotter, a Tower of Hanoi solver, and so on on the online IDE.

Compilation

wenyan currently compiles to JavaScript, Python, or Ruby, and will support more languages (e.g. C) in the future. The Hello World example (or whatever you edited it to be) above translates to:

// JavaScript
var 甲 = 3;
for (let _rand1 = 0; _rand1 < 甲; _rand1++) {
    var _ans1 = "問天地好在。";
    console.log(_ans1);
};
# Python
甲=3
for _rand1 in range(甲):
	_ans1="問天地好在。"
	print(_ans1);

# Ruby
甲=3
甲.times do |_rand1|
	_ans1="問天地好在。"
	p([_ans1].join)
end

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.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注