Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@childrentime/js-interpreter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@childrentime/js-interpreter

This project is about to implement a simple javascript parser and visualize the ast

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

js-interpreter

standard-readme compliant

Background

This project is my graduation project, the main purpose is to implement a simple javascript interpreter.

Warning: This project only supports simple syntax and has no error handler, For example we don't support new syntax and let const keyword. don't use it for production.

But maybe it's a good example for you to learn how to write a javascript interpreter because I try to finish it with minimal code.

If you want to add new syntax support, in general, you need to add parsing of the syntax expression in parse, and then interpret it in interperter.

In addition, the interperter of the while statement and for statement in the project is a bit rough.

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

npm i @childrentime/js-interpreter

Usage

import { interpreter } from "@childrentime/js-interpreter";
const result = interpreter(`var a = 1; console.log(a)`);
console.log(result); // [[1]]

The output of each console statement will be contained in an array so the result is a two-dimensional array

Living Demo

You can experience it in real time here.

Warning: It is best not to enter infinite loop code
test cases

Alternatively, you can view its test files here.

API

export { tokenizer, parse, interpreter };
const code = 'var a = 1;';
const tokens: { type: string, value: string | number }[] = tokenizer(code);
const ast = parse(code);
const interpreter: any[][] = interpreter(code);

License

MIT © ChildrenTime

FAQs

Package last updated on 22 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc