{"id":13512243,"url":"https://github.com/StepfenShawn/Cantonese","last_synced_at":"2025-03-30T22:32:15.905Z","repository":{"id":46027970,"uuid":"323026888","full_name":"StepfenShawn/Cantonese","owner":"StepfenShawn","description":"粤语編程語言.The Cantonese programming language.","archived":false,"fork":false,"pushed_at":"2024-10-27T06:33:18.000Z","size":2004,"stargazers_count":1152,"open_issues_count":33,"forks_count":46,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-10-29T15:38:54.456Z","etag":null,"topics":["cantonese","cantonese-language","compiler","programming-language","python3"],"latest_commit_sha":null,"homepage":"https://cantonese-community.github.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StepfenShawn.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-20T08:30:23.000Z","updated_at":"2024-10-27T06:33:22.000Z","dependencies_parsed_at":"2023-11-08T13:37:03.717Z","dependency_job_id":"c937be3c-4857-44ee-a828-16cbe64bcd86","html_url":"https://github.com/StepfenShawn/Cantonese","commit_stats":{"total_commits":147,"total_committers":14,"mean_commits":10.5,"dds":"0.36734693877551017","last_synced_commit":"64e85d60ca3a5868d6f07c1f8ad420163ecf8015"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepfenShawn%2FCantonese","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepfenShawn%2FCantonese/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepfenShawn%2FCantonese/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepfenShawn%2FCantonese/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StepfenShawn","download_url":"https://codeload.github.com/StepfenShawn/Cantonese/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246390895,"owners_count":20769475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cantonese","cantonese-language","compiler","programming-language","python3"],"created_at":"2024-08-01T03:01:37.826Z","updated_at":"2025-03-30T22:32:10.895Z","avatar_url":"https://github.com/StepfenShawn.png","language":"Python","readme":"![logo](img/logo.jpg)  \n[![pypi](https://img.shields.io/pypi/dm/Cantonese)](https://pypi.org/project/Cantonese/)\n[![pypi](https://img.shields.io/pypi/v/Cantonese)](https://pypi.org/project/Cantonese/) \n# The Cantonese programming language\nIf you don't know Cantonese or programming, please see [learn Cantonese while learning programming in 5 minutes](doc/cantonese.md)\n# Installation\n```\npip install Cantonese\n```\n# Introduction\n\u003ca href=\"#0\"\u003eWhat is Cantonese?\u003c/a\u003e  \n\u003ca href=\"#1\"\u003eQuick Start\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#2\"\u003eHello World\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#3\"\u003eAssignment statement \u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#4\"\u003eGet the type of variable\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#5\"\u003eLoop\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#6\"\u003eIf statement\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#7\"\u003eFunction\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#8\"\u003eThrow exception\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#9\"\u003eAssertion statement\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#10\"\u003eCatch statement\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#11\"\u003eCall python library\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#12\"\u003eobject-oriented programming\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#13\"\u003eStack\u003c/a\u003e  \n\u003ca href=\"#14\"\u003eMore examples\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#15\"\u003eGet the time\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#16\"\u003eSleep\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#17\"\u003eGet the random number\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#18\"\u003eCalculate the  correlation coefficient\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#19\"\u003eMachine learning\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#20\"\u003eTurtle drawing\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#21\"\u003eMaze game\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#22\"\u003eVarious sorting and searching algorithms\u003c/a\u003e  \n\u0026emsp;\u0026emsp;\u003ca href=\"#23\"\u003eWebsite design\u003c/a\u003e   \n\u0026emsp;\u0026emsp;\u003ca href=\"#24\"\u003eDevelop an app in Cantonese\u003c/a\u003e   \n\u003ca href=\"#25\"\u003eHow to run?\u003c/a\u003e  \n\u003ca href=\"#26\"\u003eTODOs\u003c/a\u003e  \n# \u003ca name=\"0\"\u003eWhat is Cantonese programming language?\u003c/a\u003e\nWhat is the cantonese programming language? It is a programming language that communicates with computers in [Cantonese](https://en.wikipedia.org/wiki/Cantonese).      \nThe computer can read the Cantonese you write and you can operate (abuse) the computer in Cantonese.\n\n# \u003ca name=\"1\"\u003eQuick Start\u003c/a\u003e\n### \u003ca name=\"2\"\u003eHello World\u003c/a\u003e\nThe first program written in Cantonese: `Hello World`:  \n```\n畀我睇下 \" Hello World! \" 點樣先??\n```\n### \u003ca name=\"3\"\u003eAssignment statement \u003c/a\u003e\n```\n介紹返 |A| 係 1\n介紹返 |B| 係 2\n```\n### \u003ca name=\"4\"\u003eGet the type of variable\u003c/a\u003e\n```\n介紹返 |A| 係 1\n起底: |A|\n```\nYou will get:  \n```\n\u003cclass 'int'\u003e\n```\n### \u003ca name=\"5\"\u003eLoop\u003c/a\u003e\nPrint numbers from 1 to 100:  \n```\n介紹返: |start| 係 0\n介紹返: |结束| 係 唔啱\n落操场玩跑步\n    介紹返: |start| 係 |start + 1|\n    畀我睇下 |start| 點樣先??\n    如果 |start \u003e= 100| 嘅话 =\u003e {\n        饮茶先啦\n    }\n玩到 |结束| 为止\n收工\n```\nYou can also use `For` Loop:  \n```\n|A| 从 1 行到 100\n    畀我睇下 |A| 點樣先??\n到步\n```\n### \u003ca name=\"6\"\u003eIf statement\u003c/a\u003e\n```\n介紹返: |A| 係 2\n如果 |A 係 2| 嘅话 =\u003e {\n    畀我睇下 \"A 係 2\" 點樣先??\n}\n唔係 嘅话 =\u003e {\n    畀我睇下 \"A 唔係 2\" 點樣先??\n}\n```\n### \u003ca name=\"7\"\u003eFunction\u003c/a\u003e\nFactorial algorithm in Cantonese:  \n```\n$factorial |项数| 點部署:\n    如果 |项数 係 0| 嘅话 -\u003e {\n        还数 1\n    }\n    唔係 嘅话 -\u003e {\n        还数 |factorial(项数 减 1) 乘 项数|\n    }\n搞掂\n```  \nGet the max value:  \n```\n$get_max |数字1, 数字2| 點部署:\n    如果 |数字1 比唔上 数字2| 嘅话 -\u003e {\n        还数 |数字2|\n    }\n    唔係 嘅话 -\u003e {\n        还数 |数字1|\n    }\n搞掂\n```\nCall the function:  \n```\n用下 |get_max(23, 17)|\n```\n### \u003ca name=\"8\"\u003eThrow exception\u003c/a\u003e\n```\n掟个 |ImportError| 嚟睇下?\n```\nYou will get:\n```\n濑嘢: ImportError()!\n```\n### \u003ca name=\"9\"\u003eAssertion statement\u003c/a\u003e\n```\n谂下: |1 + 1 == 3| ?\n```  \nYou will get:  \n```\n濑嘢: AssertionError()!\n```\n### \u003ca name=\"10\"\u003eCatch statement\u003c/a\u003e\ntry-except-finally:  \n```\n执嘢 -\u003e {\n    介紹返: |A| 係 |B|\n}\n揾到 |NameError| 嘅话 -\u003e {\n    畀我睇下 \"揾到NameError\" 點樣先？\n}\n执手尾 -\u003e {\n    畀我睇下 \"执手尾\" 點樣先？\n    介紹返: |A| 係 1\n    介紹返: |B| 係 1\n    畀我睇下 |A, B| 點樣先？\n}\n``` \n### \u003ca name=\"11\"\u003eCall Python library\u003c/a\u003e\n```\n使下 os\n使下 math\n```\n### \u003ca name=\"12\"\u003eobject-oriented programming\u003c/a\u003e\nDeclare object `duck` and extend from `object`, define two methods:  `游水` and `睡觉`, and attribute: `性别`\n```\n咩係 |duck|?\n    佢個老豆叫 |object|\n    佢嘅 |性别| 係 \"公\"\n    佢識得 |游水| -\u003e {\n        畀我睇下 \"Duck is swimming\" 點樣先？\n    }\n    佢識得 |睡觉| -\u003e {\n        畀我睇下 \"Duck is sleeping\" 點樣先？\n    }\n明白未啊?\n```  \nCall the methods which in class:  \n```\n|duck()| -\u003e |游水|: ||\n|duck()| -\u003e |睡觉|: ||\n```\nYou will get:  \n```\nDuck is swimming\nDuck is sleeping\n```\n### \u003ca name=\"13\"\u003eStack\u003c/a\u003e\n```\n有条仆街叫 |Deo哥|\n顶你 -\u003e |Deo哥|: 1\n顶你 -\u003e |Deo哥|: 2\n顶你 -\u003e |Deo哥|: 3\n丢你 -\u003e |Deo哥|\n```\nYou will get:  \n```\nStack: [1,2]\n```\n# \u003ca name=\"14\"\u003eMore examples\u003c/a\u003e\n### \u003ca name=\"15\"\u003eGet the time\u003c/a\u003e\n```\n使下 datetime\n畀我睇下 |宜家几点()| 點樣先？\n```\nYou will get:  \n```\n2021-01-17 09:16:20.767191\n```\n### \u003ca name=\"16\"\u003eSleep\u003c/a\u003e\n```\n瞓阵先 /* 暂停2s */\n瞓 5s /* 暂停5s */\n```  \n### \u003ca name=\"17\"\u003eGet the random number\u003c/a\u003e\n```\n使下 random\n介紹返: |A| 就 |求其啦()|\n```\nYou will get:  \n```\n0.15008236307867207\n```  \n### \u003ca name=\"18\"\u003eCalculate the correlation coefficient\u003c/a\u003e\nDefine two list and calculate the correlation coefficient:  \n```\n使下 math\n|2.165, 1.688, 1.651, 2.229| 拍住上 =\u003e |A|\n|2.060, 1.822, 1.834, 2.799| 拍住上 =\u003e |B|\n畀我睇下 |A同B有几衬| 點樣先？\n```\nYou will get:  \n```\n0.8066499427138474\n```\n### \u003ca name=\"19\"\u003eMachine learning\u003c/a\u003e\nKNN algorithm in Cantonese:\n```\n使下 math\n|[5, 1], [4, 0], [1, 3], [0, 4]| 拍住上 -\u003e |数据|\n|'动作片', '动作片', '科幻片', '科幻片'| 拍住上 -\u003e |标签|\n介紹返: |K| 係 3\n嗌 KNN 过嚟估下 =\u003e |[3, 0]|\n```\nYou will get:\n```\n动作片\n```\nLinear regression:  \n```\n使下 math\n|300.0 , 400.0 , 400.0 , 550.0 , 720.0 , 850.0 , 900.0 , 950.0| 拍住上 -\u003e |X|\n|300.0 , 350.0 , 490.0 , 500.0 , 600.0 , 610.0 , 700.0 , 660.0| 拍住上 -\u003e |Y|\n嗌 L_REG 过嚟估下 =\u003e |900.0|\n```\nYou will get:\n```\nLinear function is:\ny=0.530960991635149x+189.75347155122432\n667.6183640228585\n```\n### \u003ca name=\"20\"\u003eTurtle drawing\u003c/a\u003e\n```\n老作一下 -\u003e {\n    首先: |画个圈(100)|\n    跟住: |写隻字(\"Made By Cantonese\\n\")|\n    最尾: |听我支笛()|\n}\n```  \nYou will get:    \n![turtle_result](img/turtle_etc.jpg)  \n\n### \u003ca name=\"21\"\u003eMaze game \u003c/a\u003e\n[Code](examples/games/game.cantonese)  \nYou will get:  \n![game_result](img/game_result.jpg)\n\n### \u003ca name=\"22\"\u003eVarious sorting and searching algorithms\u003c/a\u003e\n* [Binary Search](examples/algorithms/binary_search.cantonese)\n* [Linear Search](examples/algorithms/linear_search.cantonese)\n* [Bubble Sort](examples/algorithms/bubble_sort.cantonese)\n* [Insert Sort](examples/algorithms/insert_sort.cantonese)\n\n### \u003ca name=\"23\"\u003eA simple web page\u003c/a\u003e\nThis is a simple web page:\n```\n老作一下 {\n    打标题 =\u003e [ \"我嘅第一个网页\" ]\n    拎笔 =\u003e [ \"Hello World\" ]\n}\n```\nAfter running, open '127.0.0.1:80' to view the running results:  \n```\npython src/cantonese.py ../examples/web/hello_web.cantonese -to_web \n```\n![web_result](img/web_result.jpg)\n\n### \u003ca href=\"#24\"\u003eDevelop an app in Cantonese\u003c/a\u003e\nAt first, you need install `kivy`:\n```\npip install kivy\n```\nThe first App `HelloWord` in Cantonese:  \n```\n使下 kivy\n咩係 HelloApp?\n    佢個老豆叫 App\n    佢識得 |HelloWorld| =\u003e {\n        |同我show| 下 =\u003e \"Hello World\" @ |做嘢|\n        还数 |做嘢|\n    }\n明白未啊?\n\n|App运行| 下 =\u003e |HelloApp, HelloApp().HelloWorld|\n```\n![App](img/HelloApp.jpg)  \n\n# More?\n\n[Here](examples/) you can see more examples.  \n\n# \u003ca name=\"25\"\u003eHow to run?\u003c/a\u003e\nThe Cantonese language runs on the python virtual machine, and the environment supports Python 3, because it conforms to the advanced ideas of the Cantonese! \n```shell\npython src/cantonese.py [-filename]\n```\nConvert Cantonese to Python:  \n```shell\npython src/cantonese.py [-filename]] -to_py\n```\nFor example:  \n```\npython src/cantonese.py examples/basic/helloworld.cantonese -to_py\n```\nYou will get:  \n```\nprint(\" Hello World! \")\nexit()\n```\nIt can also generate `HTML` code:  \n```shell\npython src/cantonese.py examples/web/web_hello.cantonese -to_web -compile\n```\n```html\n\u003chtml\u003e\n\u003chead\u003e\n\u003cmeta charset=\"utf-8\" /\u003e\n\u003c/head\u003e\n\u003ctitle\u003e我嘅第一个网页\u003c/title\u003e\n\u003ch1\u003eHello World\u003c/h1\u003e\n\u003c/html\u003e\n```\nRun in traditional Chinese:\n```\npython src/cantonese.py [-filename] -use_tr\n```  \nVscode plus for Cantonese:  https://github.com/Cantonese-community/vscode-cantonese  \n\n# \u003ca name=\"26\"\u003eTODOs\u003c/a\u003e\nAll cantonese or programming lovers are welcome to discuss and contribute together! Contribute to the protection of Cantonese cultural heritage!\nTODOs:   \n* Improve and perfect the syntax error checking\n* Add more statements\n* Improve own virtual machine\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStepfenShawn%2FCantonese","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStepfenShawn%2FCantonese","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStepfenShawn%2FCantonese/lists"}