Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

childrentime/js-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 inparse, and then interpret it ininterperter.

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";constresult=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 timehere.

Warning: It is best not to enter infinite loop code

test cases

Alternatively, you can view its test fileshere.

API

export{tokenizer,parse,interpreter};constcode='var a = 1;';consttokens:{type:string,value:string|number}[]=tokenizer(code);constast=parse(code);constinterpreter:any[][]=interpreter(code);

License

MIT © ChildrenTime

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp