Code Monkey home page Code Monkey logo

rmalt's Introduction

The Malt Programming Language Implementation Tutorials

  • 这是一个实现语言的教程。 我想我明确地说一句话,这个教程是如此简短、完整、充满美感和容易学习,以至于你会在同学/同事们苦恼地使用Antlr4Yacc/Lex时太快地结束工作而被误以为在划水。

  • 本教程只实现了一个解释器,你尽可以把它做成什么奇怪的编译器。LLVM是极好的

马特语言, 只需要四分之一个整日,你就能实现!

而这个方法只需要十分钟就能掌握

  • 语法介绍见document.

  • 运行方法(需要Python3.6+)

    pip install -U Redy rbnf
    python test.py
    

    即可进入repl。

  • 特性:

    • 自动柯里化
    • (局部)自定义新运算符和修改运算符
    • First-class Expression
    • 使用Lambda而非函数
    • 该语言设计者想出的非常智障的分句标志(|)

    其中前两个特性属于本人对malt的改进。

为什么我能在短短几个小时内实现它?

  • Malt is simple
  • I use rbnf, which is an alternative of RegExp tools, and can help you solve any text processing tasks no matter how difficult you once thought it to be.

实现指南

rmalt 是一个非常经典的解释器实现, 在利用rbnf解析输入字串后, 字串被转为目标语言(例如Python)内部的AST/ASDL表示.

例如,Let作为一个语法和语义的结构,其定义方式如下

Let ::= 'let' Identifier as target '=' Expr as body
         rewrite ASDL.Let(target, body)

这是一段rbnf代码, 表示输入的Tokenizer列表是如何匹配Let结构的。

IdentifierExpr都是其他和Let类似的MetaVariable, 表示在此调用其他结构的匹配规则。

as表示将匹配到的结果进行一个局部绑定,最终我们将利用这些结果构成一个Let的语义结构ASDL.Let(target, body), 如果你理解ADT或者Case Class, 那此处的构造对你应该不是难事,否则我建议你看看这个附加指南.

在你构建好这些ASTASDL后,你需要编写一个所谓的abstract machine来解释你的结构,通常而言用所谓的visitor模式便可以解决,简介的例子可见于附加指南interpret函数,也可看看rmalt的visitor.

Related

See rbnf syntaxes of malt here:

What is rbnf?

Run the repl with python test.py with following requirements

  • (Redy>=0.1.23, rbnf>=0.1.8)!

Oh you mean this repo is too informal? It's unnecessary to write a setup file cause it's just an example to bring you a piece about how to write programming langauge!

rmalt's People

Contributors

thautwarm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.