# yzhanJSInterpreter
[![npm](https://img.shields.io/npm/v/yzhanjsinterpreter)](https://www.npmjs.com/package/yzhanjsinterpreter)
[![npm](https://img.shields.io/npm/dt/yzhanjsinterpreter)](https://www.npmjs.com/package/yzhanjsinterpreter)
[![GitHub license](https://img.shields.io/github/license/mantoufan/yzhanjsinterpreter)](https://github.com/mantoufan/yzhanjsinterpreter/blob/main/LICENSE)
A JavaScript Interpreter Using JS itself, implement `eval`
JavaScript 解释器,包含词法分析、语法解析和执行。实现 `eval`
## Demo
You could change JavaScript Code and view the result in realtime.
[Online Demo](https://mantoufan.github.io/yzhanJSInterpreter)
![DEMO PNG](https://s2.loli.net/2023/06/15/lwu5Cat9gox27dR.png)
## Setup
### Node.js
```javascript
npm i yzhanjsinterpreter
import yzhanJSInterpreter from 'yzhanjsinterpreter'
```
### Browser
```html
<script src="https://cdn.jsdelivr.net/npm/yzhanjsinterpreter@latest/docs/yzhanjsinterpreter.min.js"></script>
```
## Usage
### Declaration Code
```javascript
const code = `let a = 1;
let b = 1;
a <<= b++;
for (let i = 0; i < 10; i++) {
if (i % 2 === 0) continue;
if ((i | 2) == '11') break;
a++;
}
undefined && 1 ?? (0 || a + b);`
```
### Eval · Evaluate
`eval` is a reserved keyword, so use `evaluate` instead
```javascript
const evalResult = yzhanJSInterpreter.evaluate(code)
```
`evaluate` runs followed 3 steps:
#### 1. Lexical Analyzer
```javascript
const lexResult = yzhanJSInterpreter.lex(code)
```
#### 2. Syntax Parser
```javascript
const parseResults = yzhanJSInterpreter.parse(lexResult)
```
#### 3. Executor
```javascript
const executeResult = yzhanJSInterpreter.execute(parseResults[0])
const evalResult = executeResult
```
## Development
### Unit Testing
```shell
npm test
```
### Build
```shell
npm run build
```
### Preview
```shell
npm run dev
```
## Todo
1. Travese AST, using child to replace the parent when there is only one parent Node.
2. Treeshaking: earse unseded declarations.
没有合适的资源?快使用搜索试试~ 我知道了~
JavaScript 解释器,包含词法分析、语法解析和执行。基于 LR 实现 eval.zip
共31个文件
js:26个
json:2个
css:1个
0 下载量 18 浏览量
2024-04-17
11:00:13
上传
评论
收藏 150KB ZIP 举报
温馨提示
本资源位课程设计希望对你有帮助
资源推荐
资源详情
资源评论
收起资源包目录
JavaScript 解释器,包含词法分析、语法解析和执行。基于 LR 实现 eval.zip (31个子文件)
__test__
classes
JSObject.spec.js 1013B
helpers
executor
0-add-if-for.spec.js 16KB
3-new-promise.spec.js 7KB
1-logical-break-continue.spec.js 7KB
2-object-func-return-call.spec.js 14KB
lexical-analyer.spec.js 521B
syntax-parser.spec.js 23KB
webpack.config.js 769B
src
classes
JSObject.js 727B
Promise
ResolveFunction.js 659B
ThenFunction.js 959B
RejectFunction.js 654B
PromiseFunction.js 1KB
Environment.js 531B
Reference.js 232B
Completion.js 123B
Task.js 178B
JSFunction.js 849B
data
conf.js 8KB
helpers
lexical-analyzer.js 594B
syntax-parser.js 3KB
executor.js 14KB
index.js 431B
docs
index.html 2KB
yzhanjsinterpreter.min.js 32KB
static
prism.css 4KB
prism.js 18KB
function.js 2KB
package.json 958B
package-lock.json 422KB
README.md 2KB
共 31 条
- 1
资源评论
小码蚁.
- 粉丝: 2584
- 资源: 4344
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功