MEGA65 / mega65-rom-public

MEGA65 ROM public issue reporting
4 stars 0 forks source link

Get ELSE IF working? #166

Open dansanderson opened 2 months ago

dansanderson commented 2 months ago

We have IF ... ELSE ... THEN, and we can make their statements into blocks with BEGIN ... BEND. However, for some reason ELSE comes with syntax restrictions that prevents ELSE IF from working properly. We should look into this.

10 X=1
20 IF X=0 THEN BEGIN
30   PRINT "ZERO"
40 BEND:ELSE IF X=1 THEN BEGIN
50   PRINT "ONE"
60 BEND:ELSE IF X=2 THEN BEGIN
70   PRINT "TWO"
80 BEND

This prints "ONE" and "TWO". It should only print "ONE".

The documentation for ELSE implies a bunch of odd syntax restrictions. If this is an inherent limitation, we should try to understand and document it better.

dansanderson commented 2 months ago

Previous discussion: https://www.forum64.de/index.php?thread/111002-mega65-rom-benchmark-results/&postID=1622976#post1622976

dansanderson commented 2 months ago

Notably, it is expected behavior for BEND to demarcate a line, not a statement position. The rest of the line is ignored. It's counterintuitive but it has existed since BASIC 7.

Also notably, putting the ELSE IF clauses on separate lines from the BENDs doesn't fix the issue.