The expression parser now allows spaces inside expressions (a relaxation for certain MACRO-10 typos; eg, "- 1" where "-1" was expected)
This commit is contained in:
parent
776e225920
commit
d13e7a5faf
3 changed files with 31 additions and 6 deletions
|
|
@ -1714,7 +1714,7 @@ B35000: SETZ ;PRELOAD AC,E WITH 0
|
|||
B35500: SETZ ;PRELOAD AC WITH 0
|
||||
SETO 1, ;PRELOAD E WITH -1,,-1
|
||||
HLLM 1 ;*HLLM SHOULD PLACE 0,,-1 INTO E
|
||||
CAIE 1,-1 ;PASS IF C(E) =0,,-1
|
||||
CAIE 1,- 1 ;PASS IF C(E) =0,,-1
|
||||
STOP
|
||||
|
||||
;***** FAILURE ANALYSIS *****
|
||||
|
|
|
|||
|
|
@ -1285,7 +1285,9 @@ class Macro10 {
|
|||
w = this.dbg.parseInstruction(sOperator, sOperands, this.nLocation, true);
|
||||
}
|
||||
|
||||
if (w < 0) w = this.parseExpression(sExp, true);
|
||||
if (w < 0) {
|
||||
w = this.parseExpression(sExp, true);
|
||||
}
|
||||
|
||||
if (w !== undefined) {
|
||||
this.genWord(w, this.dbg.sUndefined);
|
||||
|
|
|
|||
|
|
@ -660,6 +660,16 @@ class Debugger extends Component
|
|||
sOp = (iValue < iLimit? asValues[iValue++] : "");
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* When parseExpression() calls us, it has collapsed all runs of whitespace into single spaces,
|
||||
* and although it allows single spaces to divide the elements of the expression, a space is neither
|
||||
* a unary nor binary operator. It's essentially a no-op. If we encounter it here, then it followed
|
||||
* another operator and is easily ignored (although perhaps it should still trigger a reset of nBase
|
||||
* and nUnary -- TBD).
|
||||
*/
|
||||
if (sOp == ' ') {
|
||||
continue;
|
||||
}
|
||||
if (sOp == '^B') {
|
||||
this.nBase = 2;
|
||||
continue;
|
||||
|
|
@ -706,15 +716,27 @@ class Debugger extends Component
|
|||
}
|
||||
|
||||
aVals.push(this.truncate(v));
|
||||
|
||||
/*
|
||||
* When parseExpression() calls us, it has collapsed all runs of whitespace into single spaces,
|
||||
* and although it allows single spaces to divide the elements of the expression, a space is neither
|
||||
* a unary nor binary operator. It's essentially a no-op. If we encounter it here, then it followed
|
||||
* a value, and since we don't want to misinterpret the next operator as a unary operator, we look
|
||||
* ahead and grab the next operator as appropriate.
|
||||
*/
|
||||
if (sOp == ' ') {
|
||||
if (iValue < asValues.length - 1 && !asValues[iValue]) {
|
||||
iValue++;
|
||||
sOp = asValues[iValue++]
|
||||
} else {
|
||||
fError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sOp) break;
|
||||
|
||||
if (sOp == ' ') {
|
||||
fError = true;
|
||||
break;
|
||||
}
|
||||
|
||||
this.assert(Debugger.aBinOpPrecedence[sOp] != null);
|
||||
if (aOps.length && Debugger.aBinOpPrecedence[sOp] < Debugger.aBinOpPrecedence[aOps[aOps.length - 1]]) {
|
||||
if (aOps.length && Debugger.aBinOpPrecedence[sOp] <= Debugger.aBinOpPrecedence[aOps[aOps.length - 1]]) {
|
||||
this.evalOps(aVals, aOps, 1);
|
||||
}
|
||||
|
||||
|
|
@ -734,6 +756,7 @@ class Debugger extends Component
|
|||
|
||||
if (!fError) {
|
||||
value = aVals.pop();
|
||||
this.assert(!aVals.length);
|
||||
} else if (fQuiet === false) {
|
||||
this.println("parse error (" + (sValue || sOp) + ")");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue