https://github.com/uiur/mjs
minimal javascript interpreter in c
https://github.com/uiur/mjs
Last synced: 20 days ago
JSON representation
minimal javascript interpreter in c
- Host: GitHub
- URL: https://github.com/uiur/mjs
- Owner: uiur
- Created: 2021-02-13T10:28:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-04T05:28:47.000Z (about 5 years ago)
- Last Synced: 2025-12-01T18:55:51.484Z (7 months ago)
- Language: C
- Homepage:
- Size: 122 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mjs
A minimal (toy) JavaScript interpreter.
The goal is that it can be used as a good subset of ES5.
The implementation is from scratch. It doesn't have any library dependencies except for standard C library.
The parser and lexer are written as a recursive descendant parser.
## motivation
> What I cannot create, I do not understand - Richard Feynman
The motivation is to:
- learn C language
- learn algorithms and data structures such as hash table
- learn how to build an interpreter of a dynamic-typed language
- know more deeply about JavaScript
## status
- It can run sort algorithms
- It has very basic object system with prototype chains
## development
Here's a note for myself.
### build
```sh
make
./build/main test/input/8-array-sort.js
```
### test
This runs unit tests in C and end-to-end tests in shell scripts.
```sh
make test_run
```
## examples
see `test/input`
```js
function sort(items) {
for (var i = 0; i < items.length; i = i + 1) {
var j = 0;
var stop = items.length - 1;
for (; j < stop; j = j + 1){
if (items[j] > items[j + 1]){
var temp = items[j];
items[j] = items[j + 1];
items[j + 1] = temp;
}
}
}
return items;
}
Array.prototype.sort = function () {
return sort(this);
};
console.log([3, 2, 1].sort());
```