diff --git a/demo/demo.jspp b/demo/demo.jspp index cef6a69..538c609 100644 --- a/demo/demo.jspp +++ b/demo/demo.jspp @@ -218,31 +218,34 @@ Demo.prototype.doCommand = function() { this.gotoState(STATE_PROMPT); var tokens = new Tokens(this.line); this.line = ''; - var cmd = tokens.nextToken().toUpperCase(); - if (cmd.match(/^[0-9]+$/)) { - tokens.removeLineNumber(); - var lineNumber = parseInt(cmd); - var index = this.findLine(lineNumber); - if (tokens.nextToken() == undefined) { - if (index > 0) { - // Delete line from program - this.program.splice(index, 1); + var cmd = tokens.nextToken(); + if (cmd != undefined) { + cmd = cmd.toUpperCase(); + if (cmd.match(/^[0-9]+$/)) { + tokens.removeLineNumber(); + var lineNumber = parseInt(cmd); + var index = this.findLine(lineNumber); + if (tokens.nextToken() == undefined) { + if (index > 0) { + // Delete line from program + this.program.splice(index, 1); + } + } else { + if (index >= 0) { + // Replace line in program + this.program[index].setTokens(tokens); + } else { + // Add new line to program + this.program.splice(-index - 1, 0, new Line(lineNumber, tokens)); + } } } else { - if (index >= 0) { - // Replace line in program - this.program[index].setTokens(tokens); - } else { - // Add new line to program - this.program.splice(-index - 1, 0, new Line(lineNumber, tokens)); - } + this.currentLineIndex = -1; + this.tokens = tokens; + this.gotoState(STATE_EVAL); } - } else { - this.currentLineIndex = -1; - this.tokens = tokens; - this.gotoState(STATE_EVAL); + tokens.reset(); } - tokens.reset(); }; Demo.prototype.doEval = function() {