Skip to content

jinghua000/demo-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-interpreter

Introduction

A demo JavaScript interpreter.

Features

Only Support Features Below

  • let - only Identifier
  • const - only Identifier
  • function (function declaration treated as const declaration, params only support Identifier)
  • if / else if / else
  • binary expression
  • assignment expression
  • logic expression: && / || / ??
  • condition expression: cond ? A : B
  • update expression: ++ / --

Example

Can run like this:

import { run } from '../src'

run(
    `
        function fib(n) {
            if (n < 2) return n 

            return fib(n - 1) + fib(n - 2)
        }

        fib(10)
    `
) // => 55

Tests

Run yarn test.

About

A demo JavaScript interpreter.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published