546669204 / javascript-interpreter

用js实现js的解释器。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript-Interpreter

用js实现js的解释器。

demo: https://546669204.github.io/javascript-interpreter/

Expression

  • ArrayExpression [1,2,3,...]
  • AssignmentExpression a = 1
  • BinaryExpression a>b
  • CallExpression x()
  • ConditionalExpression x?a:b
  • FunctionExpression var x = function(){}
  • LogicalExpression a || b
  • MemberExpression a.b.c
  • NewExpression new x
  • ObjectExpression {a:"1",...}
  • SequenceExpression expression1,expression2,...
  • ThisExpression this
  • UnaryExpression !x/~x/...
  • UpdateExpression x++/x--/...

Statement

  • BlockStatement {}
  • BreakStatement break
  • ContinueStatement continue
  • DoWhileStatement do while
  • EmptyStatement ;
  • ExpressionStatement exp;
  • ForInStatement for in
  • ForStatement for
  • FunctionDeclaration function
  • IfStatement if else
  • LabeledStatement label:
  • ReturnStatement return
  • SwitchStatement switch
  • ThrowStatement throw
  • TryStatement try catch
  • VariableDeclaration var let const
  • WhileStatement while
  • WithStatement with

TEST

# 安装依赖
yarn
# 构建成果
yarn build
# 运行jest测试
yarn test

TODO

  • 递归转循环
  • 效率升级
  • jest test262 测试用例

dep

https://github.com/facebook/jest
https://github.com/acornjs/acorn
https://github.com/babel/babel

https://262.ecma-international.org/5.1/#sec-12.1
https://developer.mozilla.org/
https://astexplorer.net/
https://github.com/tc39/test262

About

用js实现js的解释器。

License:Apache License 2.0


Languages

Language:TypeScript 92.1%Language:JavaScript 6.6%Language:HTML 1.3%