https://github.com/basemax/mylang
A hobby compiler build by nearley. (Thanks from Toby)
https://github.com/basemax/mylang
compiler grammar grammar-checker grammar-parser interpreter js lexer nearley nearley-grammar nearleyjs nodejs
Last synced: about 2 months ago
JSON representation
A hobby compiler build by nearley. (Thanks from Toby)
- Host: GitHub
- URL: https://github.com/basemax/mylang
- Owner: BaseMax
- License: gpl-3.0
- Created: 2021-05-03T11:46:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-03T13:10:22.000Z (over 4 years ago)
- Last Synced: 2025-08-11T02:54:31.871Z (about 2 months ago)
- Topics: compiler, grammar, grammar-checker, grammar-parser, interpreter, js, lexer, nearley, nearley-grammar, nearleyjs, nodejs
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MyLang
A hobby compiler build by nearley.
## Features
- Lexer
- Parser
- AST Tree as JSON format
- Generate JS as intermediate code## Statements
- While loop
- Variable
- Operator `+ - * / >= <= > < = :=`## Using
```
$ node parser.js examples/hello-world.mylang
$ node examples/hello-world.js
```## Examples
```
$ node parser.js examples/hello-world.mylang
$ node examples/hello-world.js
``````js
print 10
```### Loop
```
$ node parser.js examples/loop.mylang
$ node examples/loop.js
``````js
n := 1
while n < 10 {
n := n + 1
print n
}
```### Fibonacci
```
$ node parser.js examples/fib.mylang
$ node examples/fib.js
``````js
i := 1
n := 10
fi := 1
fii := 1
while i <= n {
print fi
temp := fi + fii
fi := fii
fii := temp
i := i +1
}
```## TODO
- For
- Function
- Array value
- String value
- Boolean value© Copyright Max Base 2021
Thanks from Toby Ho and Nearley (https://nearley.js.org/)