Fix five defects the port uncovered in the reference parser and scanner
Chained subtraction and exponentiation fold left instead of abandoning the rest of the line -- `1 - 2 - 3` gave -1 and dropped the `- 3`. A unary leaf's operand moves to .left, so a negative literal is one argument again and a second argument no longer overwrites it. An operator in a line's final column survives. Hex literals reach the parser whole. A leading zero is padding, not a radix. Item 16 stays pinned: the fix works and costs an upstream golden case, which is a decision rather than a defect. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,18 +109,29 @@ int main(void)
|
||||
test_discard_error(e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in functions dispatch through the table.
|
||||
*
|
||||
* Note the arguments are never negative *literals*: a unary-minus leaf uses
|
||||
* its .right for the operand, and the parser counts arity by walking .right,
|
||||
* so `ABS(-9)` reports two arguments and is rejected. TODO.md section 12
|
||||
* item 13. The golden corpus sidesteps it the same way -- sgn.bas assigns
|
||||
* -1 to a variable first.
|
||||
*/
|
||||
/* Built-in functions dispatch through the table. */
|
||||
expect_int("N# = -9", -9);
|
||||
expect_int("A# = ABS(N#)", 9);
|
||||
expect_int("A# = SGN(N#)", -1);
|
||||
|
||||
/*
|
||||
* A negative *literal* argument, which is TODO.md section 6 item 13's
|
||||
* regression test. The reference hangs a unary leaf's operand off .right,
|
||||
* which is also where an argument list chains its arguments, so `ABS(-9)`
|
||||
* counted as two arguments and was refused outright -- no builtin could be
|
||||
* called with a negative literal at all. The corpus hid it: sgn.bas assigns
|
||||
* -1 to a variable first, which is what the three lines above do.
|
||||
*/
|
||||
expect_int("A# = ABS(-9)", 9);
|
||||
expect_int("A# = SGN(-5)", -1);
|
||||
/*
|
||||
* And with a second argument after the unary one, which is the other half of
|
||||
* the same defect: chaining the next argument through .right overwrote the
|
||||
* operand the unary leaf was keeping there.
|
||||
*/
|
||||
expect_int("A# = SHL(-1, 0)", -1);
|
||||
expect_int("A# = MOD(-7, 3)", -1);
|
||||
expect_int("A# = INSTR(\"HELLO\", \"L\")", 2);
|
||||
expect_int("A# = LEN(\"HELLO\")", 5);
|
||||
expect_int("A# = SHL(1, 4)", 16);
|
||||
expect_int("A# = SHR(16, 4)", 1);
|
||||
|
||||
Reference in New Issue
Block a user