All Projects → StepfenShawn → Cantonese

StepfenShawn / Cantonese

Licence: mit
粤语编程语言.The Cantonese programming language.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Cantonese

Compiler series
Material for the Creating a Compiler video lesson series.
Stars: ✭ 409 (-9.91%)
Mutual labels:  compiler
Jwebassembly
Java bytecode to WebAssembly compiler
Stars: ✭ 426 (-6.17%)
Mutual labels:  compiler
Graphql Compiler
Turn complex GraphQL queries into optimized database queries.
Stars: ✭ 447 (-1.54%)
Mutual labels:  compiler
Oblivion
The language of Art
Stars: ✭ 414 (-8.81%)
Mutual labels:  compiler
Flow To Typescript
Convert Flow-annotated files to TypeScript
Stars: ✭ 425 (-6.39%)
Mutual labels:  compiler
Groovy
Apache Groovy: A powerful multi-faceted programming language for the JVM platform
Stars: ✭ 4,359 (+860.13%)
Mutual labels:  compiler
Perlito
"Perlito" Perl programming language compiler
Stars: ✭ 396 (-12.78%)
Mutual labels:  compiler
Tinyrb
A tiny subset of Ruby with a Lua'esc VM
Stars: ✭ 452 (-0.44%)
Mutual labels:  compiler
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (-6.39%)
Mutual labels:  compiler
Scala Js
Scala.js, the Scala to JavaScript compiler
Stars: ✭ 4,249 (+835.9%)
Mutual labels:  compiler
Scala Native
Your favorite language gets closer to bare metal.
Stars: ✭ 4,053 (+792.73%)
Mutual labels:  compiler
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (-7.05%)
Mutual labels:  compiler
Mazucc
A minimalist C compiler with x86_64 code generation
Stars: ✭ 437 (-3.74%)
Mutual labels:  compiler
Enso
Hybrid visual and textual functional programming.
Stars: ✭ 5,238 (+1053.74%)
Mutual labels:  compiler
Haxe
Haxe - The Cross-Platform Toolkit
Stars: ✭ 4,665 (+927.53%)
Mutual labels:  compiler
Bytecoder
Rich Domain Model for JVM Bytecode and Framework to interpret and transpile it.
Stars: ✭ 401 (-11.67%)
Mutual labels:  compiler
Enzyme
High-performance automatic differentiation of LLVM.
Stars: ✭ 418 (-7.93%)
Mutual labels:  compiler
Minigo
minigo🐥is a small Go compiler made from scratch. It can compile itself.
Stars: ✭ 456 (+0.44%)
Mutual labels:  compiler
Flingos
An educational operating system written in C#. A great stepping stone from high to low level development.
Stars: ✭ 451 (-0.66%)
Mutual labels:  compiler
Nelua Lang
Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
Stars: ✭ 438 (-3.52%)
Mutual labels:  compiler

粤语编程语言

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

目录

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

引言

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

咋咋淋入门

Hello World

用粤语写嘅第一个程序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| 点样先?
}

调用 Python 库

使下 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

各种排序同埋查找算法

写个网页睇下

一个简单嘅网页:

畀我睇下 |This Page is made by cantonese!| 点样先?

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

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

web_result

喺呢度睇下更多例子.

点样运行?

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

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

将 Cantonese 转化成 Python:

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

例如:

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

运行嘅结果系:

print(" Hello World! ")
exit()

TODOs

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

  • 完善语法错误检查
  • 加多啲语句
  • 编写编辑器插件
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].