Only one unparenthesised AND or OR is matched per expression #2

Open
opened 2026-08-02 19:04:08 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md §6 item 36 (at 9151438)

A second one is left in the token stream, and in the place a program actually writes them -- a
condition -- the THEN check then finds the wrong token and the line is refused:

X# = 1
Y# = 2
IF X# = 1 AND Y# = 2 THEN PRINT "TWO IS FINE"
IF X# = 1 AND Y# = 2 AND X# = 1 THEN PRINT "THREE IS NOT"
TWO IS FINE
? 4 : PARSE ERROR Incomplete IF statement

Parenthesising is the workaround and it works -- IF (A AND B) AND C THEN parses -- which is what
the tutorials tell a reader to do. It is a refusal rather than a wrong answer, so it costs a
puzzled minute rather than an evening.

logicalandor() (src/parser.c:329) is if ( akbasic_parser_match(obj, OPS, 2) ) at :339
where subtraction() at :425 is while. This is the same defect as the earlier
associativity one
, on the one operator pair that fix did not reach, and the Go reference has
the same shape.

The fix is the same fix: while, folding left, reassigning left from the leaf built on the
previous pass. tests/parser_expressions.c for the expression form and tests/parser_commands.c
for the IF that made it visible.

Files: src/parser.c:329,339, tests/parser_expressions.c, tests/parser_commands.c


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md §6 item 36 (at 9151438) A second one is left in the token stream, and in the place a program actually writes them -- a condition -- the `THEN` check then finds the wrong token and the line is refused: ```basic X# = 1 Y# = 2 IF X# = 1 AND Y# = 2 THEN PRINT "TWO IS FINE" IF X# = 1 AND Y# = 2 AND X# = 1 THEN PRINT "THREE IS NOT" ``` ```output TWO IS FINE ? 4 : PARSE ERROR Incomplete IF statement ``` Parenthesising is the workaround and it works -- `IF (A AND B) AND C THEN` parses -- which is what the tutorials tell a reader to do. **It is a refusal rather than a wrong answer, so it costs a puzzled minute rather than an evening.** `logicalandor()` (`src/parser.c:329`) is `if ( akbasic_parser_match(obj, OPS, 2) )` at `:339` where `subtraction()` at `:425` is `while`. **This is the same defect as the earlier associativity one**, on the one operator pair that fix did not reach, and the Go reference has the same shape. **The fix is the same fix:** `while`, folding left, reassigning `left` from the leaf built on the previous pass. `tests/parser_expressions.c` for the expression form and `tests/parser_commands.c` for the `IF` that made it visible. **Files:** `src/parser.c:329,339`, `tests/parser_expressions.c`, `tests/parser_commands.c` --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.1.x milestone 2026-08-02 19:04:08 -04:00
tachikoma added the defectblast-radius:highstatus::grooming labels 2026-08-02 19:04:08 -04:00
Sign in to join this conversation.