https://github.com/yjhmelody/lambda-language
A lisp-style language written by Recursive Descent. This is my first compiler by imitating a blog.
https://github.com/yjhmelody/lambda-language
comments javascipt lambda practice-project toy-programming-language
Last synced: about 2 months ago
JSON representation
A lisp-style language written by Recursive Descent. This is my first compiler by imitating a blog.
- Host: GitHub
- URL: https://github.com/yjhmelody/lambda-language
- Owner: yjhmelody
- License: mit
- Created: 2017-08-04T01:54:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T08:14:06.000Z (over 6 years ago)
- Last Synced: 2025-04-03T18:03:53.391Z (about 2 months ago)
- Topics: comments, javascipt, lambda, practice-project, toy-programming-language
- Language: JavaScript
- Homepage: https://yjhmelody.github.io/lambda-language/out/Environment.html
- Size: 1.19 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# The lambda-language
[](https://github.com/yjhmelody/lambda-language)
[](https://github.com/yjhmelody/lambda-language)
[](https://www.npmjs.com/package/lambda-language)---
## Install```
$ npm install lambda-language
```## Syntax
ref the [example](./demo/demo1)
## 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());
```