有心Yau Sum 即將推出 · Coming soon

有心 Yau Sum

繁體中文程式語言 / A programming language in Traditional Chinese

寫程式,要有心。

Coding takes heart.

一行程式,就是一句清楚的中文。人讀得懂,機器也只有一種讀法。

Every line is a plain Chinese sentence: clear to the people who read it, and exact for the machines that run it.

01 下一站 / Next stop

下一站:有心 Next station: Yau Sum

下一站Next station 有心Yau Sum
一位乘客,一個新的車站。One passenger, one new station.

02 程式 / The code

讀出來,就是一段指示 Read it aloud, and it is a set of instructions

名稱寫在「」裡,文字寫在『』裡,數字可以用中文寫。同一個程式,可以用書面語寫,也可以用粵語寫。

Names go in 「」, text in 『』, and numbers can be written in Chinese. The same program can be written in standard written Chinese or in Cantonese.

幾個名稱可以在一個「設:」裡一起設定,幾行文字可以在一個「顯示:」裡一起顯示;「把…加到」把一個數直接加上去。

Several names can be set together in one 設: block, several lines shown together in one 顯示: block, and 把…加到 adds a number to a name in place.

示範水果.ys$ ys run 示範水果.ys
設:「蘋果」為三。
    「橙子」為五。
    「總數」為「蘋果」加「橙子」。
顯示『你一共有{總數}個水果。』
輸出 Output
你一共有八個水果。
示範零用錢.ys$ ys run 示範零用錢.ys
註:零用錢帳簿:誰給了零用錢,花了多少,還剩多少。
定義「計算總數」接收整數列表「所有金額」,回傳整數:
    設「總數」為零。
    「所有金額」裡的每一個「金額」都:
        把「金額」加到「總數」。
    回傳「總數」。

設:「家人」為〔『媽媽』、『爸爸』〕。
    「收入」為〔五十、二十〕。
    「支出」為〔十二、八、二十五〕。

「家人」裡的每一個「人」都:
    顯示『{人}給了零用錢』。
「支出」裡的每一個「金額」都:
    顯示『花了{金額}元』。

設:「收入總數」為「計算總數」(「收入」)。
    「支出總數」為「計算總數」(「支出」)。
    「餘額」為「收入總數」減「支出總數」。
顯示:『收入:{收入總數}元』。
    『支出:{支出總數}元』。
    『還剩:{餘額}元』。
註:「收入」的總和 也是七十:加起來不一定要自己寫函式。
設「收入合計」為「收入」的總和。
顯示『用「的總和」算收入:{收入合計}元』。
「餘額」大於三十的話:
    顯示『不錯!可以存起來。』
否則:
    顯示『下個星期要省一點。』
輸出 Output
媽媽給了零用錢
爸爸給了零用錢
花了十二元
花了八元
花了二十五元
收入:七十元
支出:四十五元
還剩:二十五元
用「的總和」算收入:七十元
下個星期要省一點。
示範零用錢粵語.ys$ ys run 示範零用錢粵語.ys --style=粵語
註:零用錢帳簿:邊個俾咗零用錢,使咗幾多,仲剩幾多。
定義「計算總數」收整數列表「所有金額」,返回整數:
    設「總數」做零。
    「所有金額」入面每一個「金額」都:
        將「金額」加到「總數」。
    返回「總數」。

設:「家人」做〔『媽媽』、『爸爸』〕。
    「收入」做〔五十、二十〕。
    「支出」做〔十二、八、二十五〕。

「家人」入面每一個「人」都:
    顯示『{人}俾咗零用錢』。
「支出」入面每一個「金額」都:
    顯示『使咗{金額}元』。

設:「收入總數」做「計算總數」(「收入」)。
    「支出總數」做「計算總數」(「支出」)。
    「餘額」做「收入總數」減「支出總數」。
顯示:『收入:{收入總數}元』。
    『支出:{支出總數}元』。
    『仲剩:{餘額}元』。
註:「收入」嘅總和 都係七十:加埋唔一定要自己寫函數。
設「收入合計」做「收入」嘅總和。
顯示『用「嘅總和」計收入:{收入合計}元』。
「餘額」大過三十嘅話:
    顯示『唔錯!可以儲起佢。』
唔係嘅話:
    顯示『下個星期要慳啲。』
輸出 Output
媽媽俾咗零用錢
爸爸俾咗零用錢
使咗十二元
使咗八元
使咗二十五元
收入:七十元
支出:四十五元
仲剩:二十五元
用「嘅總和」計收入:七十元
下個星期要慳啲。

每個示範程式都是編譯器測試的一部分,上面的輸出就是它實際印出來的結果。Each example is part of the compiler's test suite; the output shown is what it really prints.

03 錯誤訊息 / Errors

出錯的時候,會說清楚 When something is wrong, it says so clearly

有心先說是哪一種錯,再指出是哪幾個字,最後給一個提示。需要的話,還可以附上英文。

Yau Sum names the problem, points to the exact characters, and suggests a fix, with English alongside if you want it.

$ ys run 英文附上編譯.ys --英文=附上

錯誤[E0003]:「二〇二六」不是正確的中文數字寫法

Error[E0003]: 「二〇二六」 is not a correctly written Chinese numeral

--> 英文附上編譯.ys 第 1 行第 7 字

1設「年份」為二〇二六。

提示:中文數字要寫出位數:寫成「二千零二十六」,或者用阿拉伯數字 2026。

Hint: A Chinese numeral must include its place units: write 「二千零二十六」, or use the Arabic digits 2026.

$ ys run 三個空格.ys

錯誤[E0215]:縮排要以四個空格為一層

--> 三個空格.ys 第 2 行第 1 字

1一大於零的話:

2···顯示『a』。

提示:這一行有三個空格;一層縮排是四個空格,請補到四個、八個或十二個。

04 設計目標 / Design goals

人讀得懂,機器讀得準 Clear to people, exact for machines

現在很多程式由 AI 寫,人負責讀、審查和維護。有心要讓程式本身,人和機器都看得懂。

More and more code is written by AI, while people read it, review it and own it. Yau Sum is built so the code itself makes sense to both.

01

人讀得懂 Readable by people

每一行都是一句平常的指示,沒學過程式的人也能照著讀。

Every line is a plain instruction that someone who has never programmed can read aloud and follow.

02

只有一種讀法 One meaning, exactly

文法是封閉的,每一種寫法都經過檢查。人、編譯器和 AI 讀同一個程式,讀到的意思都一樣。

The grammar is closed and every construct is checked, so a person, the compiler and an AI all find the same single meaning.

03

和 C 一樣快 As fast as C

目標是跑得和 C 一樣快,不比 Rust、Swift 慢。好讀,不用拿速度來換。

The target is to run as fast as C and no slower than Rust or Swift. Readable code should not cost speed.

04

預設就安全 Safe by default

整數溢位、越界、除以零都會被檢查和報告;記憶體自動管理,沒有垃圾回收的停頓。

Overflow, out-of-bounds access and division by zero are checked and reported; memory is managed for you, without garbage-collector pauses.

編譯器本身也是用有心寫的。The compiler itself is written in Yau Sum.

05 學習 / Learning

一邊寫程式,一邊學繁體字 Learn to code and learn Traditional characters, together

繁體字通行於香港、澳門、臺灣,以及世界各地的華人社區。

Traditional characters are used in Hong Kong, Macau and Taiwan, and by Chinese communities around the world.

  • 用簡體輸入也可以,有心會換成繁體。You can type in Simplified; Yau Sum turns it into Traditional.
  • 書面語和粵語兩種寫法都可以,也可以混用。Write in standard written Chinese or in Cantonese, or mix the two.
  • 錯誤訊息可以附上英文,方便學中文的人對照。Error messages can carry English too, for people learning Chinese.
有心 Yau Sum

06 即將推出 / Coming soon

列車即將到站。The train is almost here.

有心正在開發中,敬請期待。Yau Sum is in development. Stay tuned.