Code Monkey home page Code Monkey logo

wenyanlanguage's Introduction

Wengyan Language

Netlify Status LICENSE LICENSE

Projects

Name Description
@wy-lang/site 包含文言资料的网页
@wy-lang/parser 一个使用 ANTLR 文法的解析器
@wy-lang/formatter 格式化文言代码
@wy-lang/estree 将文言代码转化到 ESTree

How to Start

wenyanlanguage's People

Contributors

dependabot[bot] avatar lotayou avatar oovm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wenyanlanguage's Issues

Feature: Automatically Curried Functions

Automatically curried functions

functions in wenyan are now automatically curried, that is, partially applied to return a new function.

吾有一術。名之曰「丁」。欲行是術。必先得三數。曰「寅」曰「卯」曰「辰」乃行是術曰。
    乘「寅」以「卯」。加其以「辰」。乃得其。
是謂「丁」之術也。

施「丁」於一於二。名之曰「半丁」。
施「半丁」於三。書之。

compiles to

var 丁 = () => 0;
丁 = function(寅) {
    return function(卯) {
        return function(辰) {
            var _ans1 = 寅 * 卯;
            var _ans2 = _ans1 + 辰;
            return _ans2
        };
    };
};
var _ans3 = 丁(1)(2);
var 半丁 = _ans3;
var _ans4 = 半丁(3);
console.log(_ans4);

Again, more FP on its way.

Originally posted by @LingDong- in https://github.com/LingDong-/wenyan-lang/issues/322#issuecomment-568219775

Algorithm: Parsing Chinese Numbers

我这有个算法不知道有没有漏洞:

从左往右读, 每一读一位乘十加上后一位, 但如果是倍数词那得乘上相应的倍数

然后读到 <EOS> 额外检测, 如果是不是十那么乘十.

因为只有 二百五, 没有 二百五万, 只能读成 二百五十万.

这个算法好处是同时支持 一零九九一千零九十九 两种读法.

Originally posted by @GalAster in https://github.com/LingDong-/wenyan-lang/issues/338#issuecomment-568283148

Feature: Nested Function Calling

Nested Function calling

#155 @UltimatePea proposed that Nested function calling like var e = (f (g a) b (h c d)) or in python e = f(g(a), b, h(c,d)), can be implemented by introducing temporary variables

施「庚」於「甲」名之曰「其一」。
施「辛」於「丙」於「丁」名之曰「其二」。
施「己」於「其一」於「乙」於「其二」名之曰「戊」。

or using lambda expressions

施「己」
於數。欲得是數,施「庚」於「甲」。
於「乙」
於數。欲得是數,施「辛」於「丙」於「丁」。

Actually by simulating the stack of functions, there is a third solution, which allow a serialized syntax that is more elegant and doesn't involve complex syntax like lambda expression. The compilation should not be to hard with the help of an extra stack.

入「甲」求「庚」入「乙」「丙」「丁」取二求「辛」求「己」得「戊」

We have four keywords in the above expression:

  • 入[x]:push an item x into the stack

  • 求[f]:receives a function f, pops out elements from the stack for evaluation, and push the result back into the stack. By default, all the elements from the stacks are poped out as function arguments.

  • 取[n]求[f]:Only pop the top n items for function evaluation

  • 得[x]:pop the top of the stack and assign it to variable x

The execution procedure is as follows:

operation Stack expression
入「甲」 a a
求「庚」 _1 g(a)
入「乙」「丙」「丁」 _1, b, c, d g(a), b, c, d
取二求「辛」 _1, b, _2 g(a), b, h(c, d)
求「己」 _3 f(g(a), b, h(c, d))
得「戊」 empty e = f(g(a), b, h(c, d))

Examples

python 文言
e = f(g(a), b, h(c, d)) 入「甲」求「庚」入「乙」「丙」「丁」取二求「辛」求「己」得「戊」
e = d(c(b(a))) 入「甲」求「乙」「丙」「丁」得「戊」
x = f(e, d(c,x), b(a,x)) 入「戊」「丙」「斯」取二求「丁」入「甲」「斯」取二求「乙」求「己」得「斯」

Originally posted by @Lotayou in https://github.com/LingDong-/wenyan-lang/issues/285#issuecomment-568061353

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.