Created
May 26, 2017 13:55
-
-
Save nexpr/2127f83156474e2adbda59d4ceb79f4e to your computer and use it in GitHub Desktop.
repl2 for JScript (windows10 only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| C:\Users\user\Desktop>cscript jsconsole.js //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} | |
| Microsoft (R) Windows Script Host Version 5.812 | |
| Copyright (C) Microsoft Corporation. All rights reserved. | |
| > var a = 1 | |
| > a | |
| 1 | |
| > const b = 2 | |
| > b | |
| 'b' is undefined | |
| > const b = 10;a + b | |
| 11 | |
| > let c = 100\n | |
| > let d = 200\n | |
| > c*d | |
| 20000 | |
| > ^Z | |
| Bye. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const g = function*(___){ | |
| while(true) | |
| try { | |
| ___ = eval(yield ___) | |
| } catch(error) { | |
| ___ = {error} | |
| } | |
| }() | |
| g.next() | |
| !function(){ | |
| const stdin = WScript.StdIn | |
| const stdout = WScript.StdOut | |
| let str = "" | |
| let neos = true | |
| while (neos){ | |
| stdout.Write("> ") | |
| if (neos = !stdin.AtEndOfStream) { | |
| str += stdin.ReadLine() | |
| if (str.endsWith("\\n")) { | |
| str = str.replace(/\\n$/, "\n") | |
| continue | |
| } | |
| const result = g.next(str).value | |
| if (result && result.error) { | |
| stdout.WriteLine(result.error.message) | |
| } else { | |
| try { | |
| stdout.WriteLine(result) | |
| } catch (err) { | |
| stdout.WriteLine("Cannot print") | |
| } | |
| } | |
| str = "" | |
| } else { | |
| stdout.WriteLine("Bye.") | |
| } | |
| } | |
| }() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment