neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

Error with REM on same line as IF...THEN #122

Closed nogoodboyo closed 4 years ago

nogoodboyo commented 4 years ago

This will not compile and produces the message "ERROR: ENDIF without IF...":

let i! = 0

if i! = 0 then rem this will not compile
  print "here"
endif

This will be compiled:

let i! = 0

if i! = 0 then 
  print "here" rem this will compile
endif
neilsf commented 4 years ago

May I ask what version you are using? Just type xcbasic64 -h and it will print version. Thanks.

neilsf commented 4 years ago

Okay so I think this is not a bug. This is a valid statement alone: if i! = 0 then rem this will not compile This is a completed IF ... THEN construct because there is a statement after THEN in the same line. Which means there must not be any ENDIF after this line. IF ... THEN has two forms:

  1. One is IF <condition> THEN <statements> (in a single line)
  2. Another is IF <condition> THEN <newline> <statements> ENDIF (multiline)
nogoodboyo commented 4 years ago

May I ask what version you are using? Just type xcbasic64 -h and it will print version. Thanks.

A little too late, I see, but for the sake of completeness, version 2.3.02

nogoodboyo commented 4 years ago

Okay so I think this is not a bug. This is a valid statement alone: if i! = 0 then rem this will not compile This is a completed IF ... THEN construct because there is a statement after THEN in the same line. Which means there must not be any ENDIF after this line. IF ... THEN has two forms:

1. One is `IF <condition> THEN <statements>` (in a single line)

2. Another is `IF <condition> THEN <newline> <statements> ENDIF` (multiline)

I see your point. However, this then invalidates the multiline construct. This seems to bring an inconsistency to the language. It is easily worked around though.

I am enjoying getting to know xcbasic. Keep up the good work!

neilsf commented 4 years ago

Thanks! I think it's clear syntax because it's either single-line or multiline, it can't be both. However, it may be confusing that REM is not just a comment that's totally ignored by the parser, but it's a valid statement (that does nothing actually).