https://github.com/chaosunity/fangyen
Concatenative programming language but written in Mandarin?!?! PogChamp 串接堆疊導向程式語言但是用中文撰寫?!?! 太神啦
https://github.com/chaosunity/fangyen
programming-language
Last synced: 7 months ago
JSON representation
Concatenative programming language but written in Mandarin?!?! PogChamp 串接堆疊導向程式語言但是用中文撰寫?!?! 太神啦
- Host: GitHub
- URL: https://github.com/chaosunity/fangyen
- Owner: ChAoSUnItY
- Created: 2022-01-13T18:59:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-25T02:24:14.000Z (almost 4 years ago)
- Last Synced: 2025-03-05T21:41:55.197Z (11 months ago)
- Topics: programming-language
- Language: V
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Fang Yen Programming Langauge方言程式語言
##
> Concatenative stack-oriented programming language but written in Mandarin?!?! PogChamp
> 串接堆疊導向程式語言但是用中文撰寫?!?! 太神啦
[繁體中文](/README_ZH.md)
English
Fang Yen is a concatenative programming language inspired by [Porth programming language](https://gitlab.com/tsoding/porth) and [Forth programming language](https://zh.wikipedia.org/wiki/Forth). Requires [Hieroglymph Virtual Machine](https://github.com/ChAoSUnItY/HieroglyphVM) to execute.
Build
Prereuisites
- [V Lang](https://github.com/vlang/vlang)
- Makefile
Build it from source
```cmd
$ git clone https://github.com/ChAoSUnItY/FangYen.git
$ git submodule update --init --recursive # pull Hieroglymph VM
$ v up # update V to latest version (optional but highy suggest)
$ v --prod ./FangYen.v # compile Fang Yen compiler into executable
$ ./FangYen # compile Fang Yen into bytecode and execute it
```
> Note: bytecode can be found at ~/.hvm/cache
Getting started
Fang Yen 101
Since Fang Yen is concatenative stack-oriented programming language,
**all single words in Fang Yen (except several keywords) has specific opcode to be emitted**.
That's it, no redundant operation is allowed.
Types
Currently Fang Yen has the following primitive types:
- Integer
```c
1234
```
- Boolean
Note that boolean is also considered as a numeric type.
```c
是 // Stands for true
非 // Stands for false
```
- Nil
Note that nil is also considered as a numeric type.
```c
空指標 // Stands for `NULL` in C
```
Declare a primitive value will result in pushing value onto stack.
Output
To dump a value from stack (dump: pop and print), use `傾印` keyword.
- Dump
```c
123 傾印 // this will print out 123
```
Arithmetic
Note that it would lead to undefined behavior if dividing or modding with `false` or `nil`.
| Operator | Fang Yen Keyword | Appliable types |
|:--------:|:----------------:|:---------------:|
| + | 加 | `integer`, `boolean`, `nil` |
| - | 減 | `integer`, `boolean`, `nil` |
| * | 乘 | `integer`, `boolean`, `nil` |
| / | 除 | `integer`, `boolean` (`true` only) |
| % | 餘 | `integer`, `boolean` (`true` only) |
Comparison
Besides the basic comparison operations, `boolean` and `nil` are also comparable since they both stored as byte.
| Operator | Fang Yen Keyword | Appliable types |
|:--------:|:----------------:|:---------------:|
| == | 等於 | `All types` |
| != | 不等於 | `All types` |
| > | 大於 | `integer`, `boolean`, `nil` |
| >= | 大等於 | `integer`, `boolean`, `nil` |
| < | 小於 | `integer`, `boolean`, `nil` |
| <= | 小等於 | `integer`, `boolean`, `nil` |