// See http://tech.einaregilsson.com/2009/02/20/jscript-repl/
function print(s) { WScript.Echo(s);}
var _$ = '';

while (_$ != 'exit') {
    WScript.StdOut.Write(_$ ? '... ' : '>>> ');
    _$ += (_$ ? '\n':'') + WScript.StdIn.ReadLine().replace(/^\s*|\s*$/g, '');

    if (_$.match(/^[^\n]*;$|;;$|\n;$/)) {
        try {

            if (_$.match(/\n/) || _$.match(/^(if|while|var|try|do|with|function|switch|for|print)\b/)) {
                eval(_$);
            } else {
                _$ = eval(_$);
                if (typeof(_$) == 'undefined') {
                    print('undefined');
                } else if (typeof(_$) == 'boolean') {
                    print(_$ ? 'true' : 'false');
                } else if (typeof(_$) == 'string') {
                    print("'" + _$ + "'");
                } else {
                    print(_$);
                }
            }
        } catch(_$) {
            print('ERROR: ' + _$.message);
        }
        _$ = '';
    }             
}
