Pua-lang - a dialect of The Monkey Programming Language

Overview

pua-lang

PUA Programming Language written in Rust.

What's pua-lang?

pua-lang is a dialect of The Monkey Programming Language, intended to mirror the inspirational babble of Alibaba managers ("Aba-aba"). The name "pua" refers to the manipulative way Alibaba treats its employees -- much like how pickup artists treat their trophies.

This implementation is a fork of rs-monkey-lang. Monkey is a programming language designed to learn interpreters. It comes from Writing An Interpreter In Go.

Try pua-lang!

with wasm playground

https://flaneur2020.github.io/pua-lang/

We are aware that the output streams don't quite work. Rust doesn't really have I/O redirection and wasm32-unknown-unknown has no I/O by default.

with REPL

$ git clone https://github.com/flaneur2020/pua-lang.git
$ make repl

Documentation

⚠️ Please note that there may be some mistakes.

Summary

  • Everything Monkey has:
    • C-like syntax
    • variable bindings
    • integers and booleans
    • a string data structure
    • an array data structure
    • a hash data structure
    • arithmetic expressions
    • built-in functions
    • first-class and higher-order functions • closures
  • Unicode identifiers (UAX #31, XID) plus monetary extensions ([¥$_]) and an overly-lax definition of Emojis.
  • Rust-compatible double-quoted string syntax.
  • Ridiculous naming for the Aba-aba. Comparison with Monkey:
Monkey pua-lang Explanation
if 细分 "specialization"
else 路径 "pathway"
while 闭环 "closed loop"
true 三七五 "3.75", a passing performance evalulation result
false 三二五 "3.25", a failing performance evalulation result
let 赋能 "empower"
fn 抓手 "handle", as in getting a handle on things
return 反哺 "repay", used in Alibaba as a general term for feedback in systems
Array 组合拳 "combo move"; not yet a word in the language
Hash 载体 "carrier"; not yet a word in the language
= 对齐 "align"
+ 联动 "linkage"
- 差异 "difference"
/ 倾斜 "tilt"
puts 输出 "output"
quit 淘汰 "eliminate"
(atoi) 量化 quantify

The precise set of renames may change from time to time as we explore new avanues of profit pathways to the full enablement of our shareholders customers. You are encouraged to (ahem) carefully study the spirit of src/lexer/mod.rs and src/evaluator/builtins.rs in order to align yourself with Ali-speak and maximize your output.

Syntax overview

An example of Fibonacci function.

赋能 fib = 抓手(x) {
  细分 (x 对齐 0) {
    反哺 0;
  }
  细分 (x 对齐 1) {
    反哺 1;
  } 路径 {
    反哺 fib(x - 1) 联动 fib(x - 2);
  }
};

fib(10);

细分

细分 supports the general 细分. 路径 exists, but 细分 路径 does not exist yet.

细分 (三七五) {
  10;
} 路径 {
  5;
}

闭环

With the 闭环 we can execute a set of statements as long as a condition is 三七五.

闭环 (三七五) {
    输出("年年有抓手");
}

Operators

It supports the general operations.

1 + 2 + (3 * 4) - (10 / 5);
!三七五;
!三二五;
+10;
-5;
"年年有抓手" + " " + "岁岁有闭环";

反哺

It returns the value immediately. No further processing will be executed.

细分 (三七五) {
  反哺;
}
赋能 不变 = 抓手(工资p6) {
  反哺 工资p6;
};

不变("👨‍💻🐒烧酒");

赋能

赋能, such as those supported by many programming languages, is implemented. Variables can be defined using the 赋能 keyword.

Format:

赋能 <identifier> = <expression>;

Example:

赋能 x = 0;
赋能 y = 10;
赋能 福报 = add(5, 5);
赋能 alias = 福报;
赋能 identity = 抓手(x) { x };

Literals

Five types of literals are implemented.

Integer

Integer represents an integer value. Floating point numbers can not be handled.

Format:

[-+]?[1-9][0-9]*;

Example:

10;
1234;

Boolean

Boolean represents a general boolean type.

Format:

三七五 | 三二五;

Example:

三七五;
三二五;

赋能 truthy = !三二五;
赋能 falsy = !三七五;

String

String represents a string. Only double quotes can be used.

Format:

"<value>";

Example:

"Monkey Programming Language";
"Hello" + " " + "World";

组合拳

组合拳 represents an ordered contiguous element. Each element can contain different data types.

Format:

[<expression>, <expression>, ...];

Example:

[1, 2, 3 + 3, fn(x) { x }, add(2, 2), 三七五];
赋能 组合拳 = [1, 三七五, 抓手(x) { x }];

组合拳[0];
组合拳[1];
组合拳[2](10);
组合拳[1 + 1](10);

载体

载体 expresses data associating keys with values.

Format:

{ <expression>: <expression>, <expression>: <expression>, ... };

Example:

赋能 载体 = {
  "name": "Jimmy",
  "age": 72,
  三七五: "a boolean",
  99: "an integer"
};

载体["name"];
载体["a" + "ge"];
载体[三七五];
载体[99];
载体[100 - 1];

抓手

抓手 supports functions like those supported by other programming languages.

Format:

抓手 (<parameter one>, <parameter two>, ...) { <block statement> };

Example:

赋能 add = 抓手(x, y) {
  反哺 x 联动 y;
};

add(10, 20);
赋能 add = 抓手(x, y) {
  x 联动 y;
};

add(10, 20);

If 反哺 does not exist, it returns the result of the last evaluated expression.

赋能 addThree = 抓手(x) { x + 3 };
赋能 callTwoTimes = 抓手(x, f) { f(f(x)) };

callTwoTimes(3, addThree);

Passing around functions, higher-order functions and closures will also work.

Built-in Functions

You can use 1 built-in function 🚀

输出(<arg1>, <arg2>, ...): void

It outputs the specified value to stdout. In the case of Playground, it outputs to console.

输出("年年有抓手");
输出("岁岁有闭环!");
Comments
  • 建议:增加类似于golang的 `_` 操作符,命名为:不感兴趣

    建议:增加类似于golang的 `_` 操作符,命名为:不感兴趣

    golang 有个下划线 _ ,表示不关心的值,可以用在这里,下面给个案例: 函数定义:

    //golang
    func f(){
     return v1, v2
    }
    //pua
    抓手 我不爱钱(){
     反哺 钱,福报
    }
    

    调用:

    //golang
    _ ,V2 = f()
    //pua
    不感兴趣,福报 =我不爱钱() 
    
    opened by wwhai 9
  • web: 高亮

    web: 高亮

    试着整了一下 web。能跑,关键词能高亮。可是 operator 和 variables 硬是不亮中文,搞不清为啥。去 https://discuss.codemirror.net/t/some-of-my-simple-mode-unicode-patterns-dont-work-why/3101 问了。

    opened by Artoria2e5 6
  • build_wasm 失败求助

    build_wasm 失败求助

    rust 新手尝试搭建在线环境:

    $ rustup toolchain list
    stable-x86_64-apple-darwin (default)
    nightly-x86_64-apple-darwin (override)
    $ make build_wasm
    cargo build --bin wasm -Z unstable-options --profile tiny --target wasm32-unknown-unknown --features=wasm
        Updating crates.io index
      Downloaded tinyvec v1.2.0
      Downloaded unicode-normalization v0.1.17
      Downloaded unicode-xid v0.2.1
      Downloaded tinyvec_macros v0.1.0
      Downloaded 4 crates (158.2 KB) in 0.58s
       Compiling tinyvec_macros v0.1.0
       Compiling unicode-xid v0.2.1
    error[E0463]: can't find crate for `core`
      |
      = note: the `wasm32-unknown-unknown` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error[E0463]: can't find crate for `core`
      |
      = note: the `wasm32-unknown-unknown` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error: could not compile `tinyvec_macros`
    
    To learn more, run the command again with --verbose.
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    make: *** [target/wasm32-unknown-unknown/tiny/wasm.wasm] Error 101
    
    opened by nobodxbodon 5
  • add 闭环

    add 闭环

    • [x] add token about the 闭环 and lexer
    • [x] add parser about the 闭环 statement
    • [x] refactor: take reference instead of move on iterating the ast nodes
    • [x] add the interpreter logic about the 闭环 statement
    • [ ] support 破圈(break) statement (maybe we could implement it in another PR)
    opened by flaneur2020 3
  • update: adjust true and false in condition of 赋能 to 三七五 and 三二五

    update: adjust true and false in condition of 赋能 to 三七五 and 三二五

    Well, as mentioned in README.md, true or flase should be '三七五' and '三二五' but not in origin. For not make freshmen feeling confused in learning pua-lang, just replace true/flase in examples of '赋能/抓手'. Whether to replace all true and false in README.md depends on @flaneur2020.

    Nothing is truer than 3.75 in alibaba, and the same to false and 3.25. I wish these will be corrected, for the smell of alibaba really desire this.

    opened by HyperLiar 1
  • Readline 应该提供多行输入

    Readline 应该提供多行输入

    如果直接将以下内容贴进 REPL:

    赋能 不变 = 抓手(工资p6) {
      反哺 工资p6;
    };
    
    不变("码猴烧酒");
    

    会发现第一行被当作 赋能 不变 = 抓手(工资p6) {} 解析,第二、三行输入失败。正常来讲,这个东西应该要在 "need XXX, got Eof" 的时候让 Readline 继续请求输入。

    另外这里还有个小问题,就是 赋能 不变 = 抓手(工资p6) { 不知道怎么算合法的。

    opened by Artoria2e5 1
  • Syntax overview 需要更强大的抓手

    Syntax overview 需要更强大的抓手

    Syntax overview 写的不够赋能,需要按照如下方式对齐:

    赋能 案例 对齐 x;
    赋能 痛点 对齐 组合拳 { 0, 1, 2}
    赋能 传统 对齐 痛点[0];
    赋能 精简 对齐 痛点[1];
    赋能 革新 对齐 痛点[2];
    赋能 PUA 对齐 抓手(案例) {
      细分 (案例 对齐 传统) {
        反哺 传统;
      }
      细分 (案例 对齐 精简) {
        反哺 精简;
      } 路径 {
        反哺 PUA(案例 差异 精简) 联动 PUA(案例 差异 革新);
      }
    };
    

    学废了吗?

    opened by Windsander 0
  • 怎么能少花名传统?

    怎么能少花名传统?

    建议每个文件开头必须声明一个花名,类似Java的package,但又有所区别,要做到:

    1、不能缺失,否则会编译报错,或者运行崩溃;

    2、被其他文件导入(import)时又用不上。

    没错,就是那种“实际没卵用,但少了它又没法在团队里混”的感觉。

    若能增加“彩虹屁”或“花名鼓励词”的编译或运行提示,类似“花名666”、“花名绝绝子”、“花名所见略同”等,则更妙!

    opened by FooFooDamon 2
  • web端 puts 没法用,直接光字符串能输出了

    web端 puts 没法用,直接光字符串能输出了

    有需要的话我可以提PR并且顺便把所有的snippets换成中文 demo: https://flaneur2020.github.io/pua-lang/?s=JYMwBAFALgTgrgUwJRgN4CgxgA5ygZwgCIBGAOgAkEAbageyKQG50BfMG-BNTHPQonAB2MBAEMAxgAsxAI2oJGLVunSAxv0BgSpFiIUGLEQBMlGvSLKwge9jAIfo8Dw0ZJnzFyoA

    Screen Shot 2021-12-07 at 14 00 43

    opened by keidarcy 0
Owner
flaneur
flaneur
Tyrade: a pure functional language for type-level programming in Rust

A pure functional language for type-level programming in Rust

Will Crichton 286 Jan 1, 2023
An OOP programming language I am making by following Crafting Interpreters.

horba An OOP programming language I am making by following Crafting Interpreters. https://craftinginterpreters.com/ I intend it to have a somewhat C-s

Thomas 3 Dec 5, 2021
Yet Another Programming Language

Yet Another Programming Language

null 4 Sep 15, 2021
luau bindings for the Rust programming language

?? luau-rs Luau bindings for the Rust programming language using bindgen ⚠️ Disclaimer This does not provide bindings for everything as luau does not

Vurv 18 Aug 3, 2022
Czech for the Rust programming language

rez Nejsi you tired from writing Rust programs in English? Do you like saying do prdele or pivo a lot? Would you like to try something different, in a

Radek Vít 13 Oct 9, 2022
The official home of the Nyson Programming Language, built off Rust.

Nyson Programming Language The official home of the Nyson Programming Language, built off Rust. (created by Nyelsonon and AMTitan, 2021) Advertisement

Nyson-Programing-Language 19 Aug 10, 2022
The programming language for scalable development

Pen programming language Pen is the programming language that makes software development scalable, focusing on software maintainability and portabilit

Pen programming language 390 Dec 30, 2022
A newborn programming language for extensible software

A newborn programming language for extensible software.

Alexey Shmalko 17 Nov 29, 2022
A simple programming language made for scripting inspired on rust and javascript.

FnXY Programming Language Quick move: CONTRIBUTING | LICENSE What? FnXY is a simple programming language made for scripting inspired on rust and javas

null 2 Nov 27, 2021
A multithreaded programming language!

hydracane A multithreaded programming language! Getting started Coming Soon! Features: Multithreaded Platform independent Folders: src/vm: The Virtual

Krishna Ramasimha 0 Dec 10, 2021
CARBON is an interface-centric programming language named after the concept of an allotropy.

CARBON programming language Status: just an idea CARBON is an interface-centric programming language named after the concept of an allotropy. It is an

Tim McNamara 4 Aug 18, 2022
Lisp-style programming language

Bobbylisp A programming language, syntax are like mal and clojure. This project follow mal guides, Planning to add some more features after finishing

azur 36 Dec 19, 2022
An interpreter for the esoteric programming language, Brainf*ck.

Brainf*ck Interpreter This is just a normal Brainf*ck interpreter written in Rust. If you don't know what Brainf*ck is, you can check out the wikipedi

Callum Irving 0 Dec 23, 2021
The Fluet programming language.

fluet Fluet is a scripting language. License Fluet is licensed under the Mozilla Public License, v. 2.0. Contributors may dual license their contribut

null 11 May 4, 2022
Ethereal - a general-purpose programming language that is designed to be fast and simple

Ethereal is a general-purpose programming language that is designed to be fast and simple. Heavly inspired by Monkey and written in Rust

Synthesized Infinity 21 Nov 25, 2022
Dc improved: Feature-added rewrite of a 50+ year old RPN calculator/stack machine/programming language

dcim [WIP] dc improved: Feature-added rewrite of a 50+ year old RPN calculator/stack machine/programming language This readme is currently incomplete.

null 3 Jun 18, 2022
Squirt is a easy-to-use programming language.

Squirt is a easy-to-use programming language.

QuqqU 5 Nov 30, 2022
Osmon's compiler crate. Programming language made for starter & novice Uzbek audience.

Osmon Tili Osmon bu registrlarga asoslangan virtual mashinalik va yengil dasturlash tili Osmon boshqa o'zbek open source dasturchisi Sukhrob Khakimovn

Osmon 31 Dec 22, 2022
A library for functional programming in Rust

It contains purely functional data structures to supplement the functional programming needs alongside with the Rust Standard Library.

Jason Shin 1.1k Dec 30, 2022