Giter Site home page Giter Site logo

yjhmelody / lambda-language Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.22 MB

A lisp-style language written by Recursive Descent. This is my first compiler by imitating a blog.

Home Page: https://yjhmelody.github.io/lambda-language/out/Environment.html

License: MIT License

JavaScript 99.82% Shell 0.18%
lambda toy-programming-language practice-project javascipt comments

lambda-language's Introduction

The lambda-language

complier version npm


Install

$ npm install lambda-language

Syntax

ref the example

API

The following are located in the corresponding file in src

  • InputStream: output lex
  • TokenStream: output token
  • parser: output ast
  • codeGen: complier the ast to JS
  • Environment: store variables
  • Environment.Execute: execute ast with guarding stack
  • Environment.evalute: eval ast expression with an env

Run the language

$ bin/lambda demo

Compile the language to JS

$ bin/code-to-js demo2 [demo2.js]

Some examples about syntax

print_range = λ(a, b) if a <= b {
                        println(a);
                        if a + 1 <= b {
                          print_range(a + 1, b);
                        } 
                        else 
                          println("");
                      };
print_range(1, 10);

output:

1
2
3
4
5
6
7
8
9 
10
cons = λ(a, b) λ(f) f(a, b);
car = λ(cell) cell(λ(a, b) a);
cdr = λ(cell) cell(λ(a, b) b);
NIL = λ(f) f(NIL, NIL);

x = cons(1, cons(2, cons(3, cons(4, cons(5, NIL)))));
println(car(x));                      # 1
println(car(cdr(x)));                 # 2
println(car(cdr(cdr(x))));            # 3
println(car(cdr(cdr(cdr(x)))));       # 4
println(car(cdr(cdr(cdr(cdr(x))))));  # 5

output:

1
2
3
4
5

binded with some nodejs functions

code = fs-readFileSync("./demo");
println(code);
println(os-arch());

lambda-language's People

Contributors

yjhmelody avatar

Stargazers

 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.