diff --git a/demo/demo.js b/demo/demo.js index 65e87d9..d96d1df 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -173,10 +173,11 @@ Demo.prototype.error = function(msg) { } this.vt100((this.cursorX != 0 ? '\r\n' : '') + '\u0007? ' + msg + (this.currentLineIndex >= 0 ? - ' in line ' + this.program[this.currentLineIndex].lineNumber() : + ' in line ' + this.program[this.evalLineIndex].lineNumber() : '') + '\r\n'); this.gotoState(2 /* STATE_PROMPT */); this.currentLineIndex = -1; + this.evalLineIndex = -1; return undefined; }; @@ -203,6 +204,7 @@ Demo.prototype.doPrompt = function() { this.keys = ''; this.line = ''; this.currentLineIndex = -1; + this.evalLineIndex = -1; this.vt100((this.cursorX != 0 ? '\r\n' : '') + '> '); this.gotoState(3 /* STATE_READLINE */); return false; @@ -272,6 +274,7 @@ Demo.prototype.doCommand = function() { } } else { this.currentLineIndex = -1; + this.evalLineIndex = -1; this.tokens = tokens; this.gotoState(5 /* STATE_EVAL */); } @@ -420,7 +423,8 @@ Demo.prototype.doPrint = function() { }; Demo.prototype.doExec = function() { - this.tokens = this.program[this.currentLineIndex++].tokens(); + this.evalLineIndex = this.currentLineIndex++; + this.tokens = this.program[this.evalLineIndex].tokens(); this.tokens.reset(); this.doEval(); if (this.currentLineIndex < 0) { @@ -547,7 +551,7 @@ Demo.prototype.term = function() { Demo.prototype.factor = function() { var token = this.tokens.nextToken(); if (!token) { - return token; + return this.error(); } var value = undefined; diff --git a/demo/demo.jspp b/demo/demo.jspp index 60d4fd6..da46ae5 100644 --- a/demo/demo.jspp +++ b/demo/demo.jspp @@ -173,10 +173,11 @@ Demo.prototype.error = function(msg) { } this.vt100((this.cursorX != 0 ? '\r\n' : '') + '\u0007? ' + msg + (this.currentLineIndex >= 0 ? - ' in line ' + this.program[this.currentLineIndex].lineNumber() : + ' in line ' + this.program[this.evalLineIndex].lineNumber() : '') + '\r\n'); this.gotoState(STATE_PROMPT); this.currentLineIndex = -1; + this.evalLineIndex = -1; return undefined; }; @@ -203,6 +204,7 @@ Demo.prototype.doPrompt = function() { this.keys = ''; this.line = ''; this.currentLineIndex = -1; + this.evalLineIndex = -1; this.vt100((this.cursorX != 0 ? '\r\n' : '') + '> '); this.gotoState(STATE_READLINE); return false; @@ -272,6 +274,7 @@ Demo.prototype.doCommand = function() { } } else { this.currentLineIndex = -1; + this.evalLineIndex = -1; this.tokens = tokens; this.gotoState(STATE_EVAL); } @@ -420,7 +423,8 @@ Demo.prototype.doPrint = function() { }; Demo.prototype.doExec = function() { - this.tokens = this.program[this.currentLineIndex++].tokens(); + this.evalLineIndex = this.currentLineIndex++; + this.tokens = this.program[this.evalLineIndex].tokens(); this.tokens.reset(); this.doEval(); if (this.currentLineIndex < 0) { @@ -547,7 +551,7 @@ Demo.prototype.term = function() { Demo.prototype.factor = function() { var token = this.tokens.nextToken(); if (!token) { - return token; + return this.error(); } var value = undefined;