GithubHelp home page GithubHelp logo

johnnyvipcn2 / cantonese Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stepfenshawn/cantonese

0.0 0.0 0.0 468 KB

粤语编程语言.The Cantonese programming language.

License: MIT License

Python 100.00%

cantonese's Introduction

logo

粤语编程语言

如果你不会粤语或编程,请看5分钟边学编程边学粤语

目录

引言
咋咋淋入门
  Hello World
  赋值语句
  睇下变量嘅类型
  循环
  条件语句
  函数
  抛出异常
  断言语句
  错误捕捉语句
  调用Python库
  面向对象编程
  栈嘅使用
更多例子
  睇睇时间
  暂停
  嚟个随机数
  计算相关系数
  仲可以机器学习?
  海龟画图
  迷宫游戏仔
  各种排序同埋查找算法
  写个网页来睇下?
  用粤语开发一个App
点样运行?
TODOs

粤语编程语言系咩? 佢系一门用粤语嚟同计算机沟通嘅编程语言。
喺呢个语言度,计算机可以读明你写嘅粤语。所以话,你可以用粤语嚟操作(虐待)计算机。

用粤语写嘅第一个程序Hello World:

畀我睇下 " Hello World! " 点样先?
讲嘢 |A| 系 1
讲嘢 |B| 系 2
讲嘢 |A| 系 1
起底: |A|

运行结果:

<class 'int'>

打印从1到100:

讲嘢: |start| 系 0
讲嘢: |结束| 系 唔啱
落操场玩跑步
    讲嘢: |start| 系 |start + 1|
    畀我睇下 |start| 点样先?
    如果 |start >= 100| 嘅话 -> {
        饮茶先啦
    }
玩到 |结束| 为止
收工

当然用For循环都得:

|A| 从 1 行到 100
    畀我睇下 |A| 点样先?
行晒
讲嘢: |A| 系 2
如果 |A 系 2| 嘅话 -> {
    畀我睇下 "A 系 2" 点样先?
}
唔系嘅话 -> {
    畀我睇下 "A 唔系 2" 点样先?
}

用 Cantonese 实现嘅阶乘:

$factorial |项数| 要做咩:
    如果 |项数 系 0| 嘅话 -> {
        还数 1
    }
    唔系嘅话 -> {
        还数 |factorial(项数 减 1) 乘 项数|
    }
搞掂

返回最大值:

$get_max |数字1, 数字2| 要做咩:
    如果 |数字1 比唔上 数字2| 嘅话 -> {
        还数 |数字2|
    }
    唔系嘅话 -> {
        还数 |数字1|
    }
搞掂

调用函数:

用下 |get_max(23, 17)|
掟个 |ImportError| 来睇下?

运行结果:

濑嘢: ImportError()!
谂下: |1 + 1 == 3| ?

运行结果:

濑嘢: AssertionError()!

try-except-finally:

执嘢 -> {
    讲嘢: |A| 系 |B|
}
揾到 |NameError| 嘅话 -> {
    畀我睇下 "揾到NameError" 点样先?
}
执手尾 -> {
    畀我睇下 "执手尾" 点样先?
    讲嘢: |A| 系 1
    讲嘢: |B| 系 1
    畀我睇下 |A, B| 点样先?
}
使下 os
使下 math

声明对象duck, 继承至object, 分别有两个方法游水同埋睡觉, 仲有一个属性性别:

咩系 |duck|?
    佢个老豆叫 |object|
    佢嘅 |性别| 系 "公"
    佢识得 |游水| -> {
        畀我睇下 "Duck is swimming" 点样先?
    }
    佢识得 |睡觉| -> {
        畀我睇下 "Duck is sleeping" 点样先?
    }
明白未啊?

调用类中嘅方法:

|duck()| -> |游水|: ||
|duck()| -> |睡觉|: ||

运行结果:

Duck is swimming
Duck is sleeping
有条仆街叫 |Deo哥|
顶你 -> |Deo哥|: 1
顶你 -> |Deo哥|: 2
顶你 -> |Deo哥|: 3
丢你 -> |Deo哥|

运行结果:

Stack: [1,2]
使下 datetime
畀我睇下 |宜家几点()| 点样先?

运行结果:

2021-01-17 09:16:20.767191
瞓阵先 /* 暂停2s */
瞓 5s /* 暂停5s */
使下 random
讲嘢: |A| 就 |求其啦()|

运行结果:

0.15008236307867207

声明两个list, 计算相关系数:

使下 math
|2.165, 1.688, 1.651, 2.229| 拍住上 -> |A|
|2.060, 1.822, 1.834, 2.799| 拍住上 -> |B|
畀我睇下 |A同B有几衬| 点样先?

运行结果:

0.8066499427138474

实现KNN算法:

使下 math
|[5, 1], [4, 0], [1, 3], [0, 4]| 拍住上 -> |数据|
|'动作片', '动作片', '科幻片', '科幻片'| 拍住上 -> |标签|
讲嘢: |K| 系 3
嗌|KNN|过嚟估下 -> |[3, 0]|

运行结果:

动作片

线性回归:

使下 math
|300.0 , 400.0 , 400.0 , 550.0 , 720.0 , 850.0 , 900.0 , 950.0| 拍住上 -> |X|
|300.0 , 350.0 , 490.0 , 500.0 , 600.0 , 610.0 , 700.0 , 660.0| 拍住上 -> |Y|
嗌L_REG过嚟估下 -> |900.0|

运行结果:

Linear function is:
y=0.530960991635149x+189.75347155122432
667.6183640228585
老作一下 -> {
    首先: |画个圈(100)|
    跟住: |写隻字("Made By Cantonese\n")|
    最尾: |听我支笛()|
}

运行结果:
turtle_result

代码
运行结果:
game_result

一个简单嘅网页:

老作一下 {
    写标题 => [ "我嘅第一个网页" ]
    写隻字 => [ "Hello World" ]
}

运行后, 打开127.0.0.1:80可查看运行结果:

python src/cantonese.py ../examples/web/hello_web.cantonese -to_web 

web_result

首先安装kivy:

pip install kivy

第一个AppHelloWord:

使下 kivy
咩系 HelloApp?
    佢个老豆叫 App
    佢识得 |HelloWorld| -> {
        |同我show| 下 -> "Hello World" @ |做嘢|
        还数 |做嘢|
    }
明白未啊?

|App运行| 下 -> |HelloApp, HelloApp().HelloWorld|

App

仲有啲咩?

喺呢度睇下更多例子.

Cantonese 语言运行喺 Python 虚拟机上,环境净系支持 Python3,因为噉先符合广东人先进嘅**!

python src/cantonese.py [-文件名]

将 Cantonese 转化成 Python:

python src/cantonese.py [文件名] -to_py

例如:

python src/cantonese.py examples/basic/helloworld.cantonese -to_py

运行嘅结果系:

print(" Hello World! ")
exit()

生成HTML:

python src/cantonese.py examples/web/web_hello.cantonese -to_web -compile
<html>
<head>
<meta charset="utf-8" />
</head>
<title>我嘅第一个网页</title>
<h1>Hello World</h1>
</html>

用繁体字运行:

python src/cantonese.py [文件名] -use_tr

Vscode插件:https://github.com/Cantonese-community/vscode-cantonese

本项目代码写得很陋(烂),欢迎各个粤语同埋编程爱好者一齐讨论同贡献!为粤语文化遗产嘅保护贡献出自己嘅一份力量! 今后要做咩:

  • 完善语法错误检查
  • 加多啲语句
  • 编写编辑器插件

cantonese's People

Contributors

hfhchan avatar laubonghaudoi avatar sherlockcxk avatar stepfenshawn avatar

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.