Skip to content

Instantly share code, notes, and snippets.

@martin12333
Forked from nexpr/repl.example.txt
Created June 3, 2024 04:56
Show Gist options
  • Save martin12333/976f45ecd8ffd619161d729b14810f9c to your computer and use it in GitHub Desktop.
Save martin12333/976f45ecd8ffd619161d729b14810f9c to your computer and use it in GitHub Desktop.

Revisions

  1. @nexpr nexpr created this gist May 26, 2017.
    13 changes: 13 additions & 0 deletions repl.example.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    C:\Users\user\Desktop>cscript //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} repl.js
    Microsoft (R) Windows Script Host Version 5.812
    Copyright (C) Microsoft Corporation. All rights reserved.

    > if(true){\
    > 1\
    > }
    1
    > var a = 10
    undefined
    > a
    10
    > exit
    21 changes: 21 additions & 0 deletions repl.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    let acc = ""
    while(true){
    WScript.StdOut.Write("> ")
    const input = WScript.StdIn.ReadLine()
    if(input === "exit"){
    break
    }
    if(input.endsWith("\\")){
    acc += input.slice(0, -1) + "\n"
    continue
    }
    const source = acc + input
    acc = ""
    try{
    const [result = "undefined" ] = [eval(source)]
    WScript.Echo(result)
    }catch(err){
    WScript.Echo(err.message)
    WScript.Echo(err.stack)
    }
    }