Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
End if
#1
Is there a way so you can write:

IF a = b THEN PRINT "A and B are equal";

Instead of:
IF a = b THEN PRINT "A and B are equal";: END IF

To keep compatibillty with the original ZX BASIC?

Then you will not have to change all of those IF/THEN lines in old sorce code, and also perhaps some kind of swithc or a #pragma directive so
you will not have to rewrite draw and plot commands while also keeping the new way of using those commands and then without the directive
of course.

The original BASIC version would also not allow to PLOT or DRAW on the bottom two lines.
Example:
PLOT x+100,y-100 ' original BASIC version
PLOT x+100,96-y ' zxb version

This would greatly simplify things and keep bugs to the minimum.

READ/RESTORE/DATA is not that important compared to the other stuff.
Reply
#2
Like

#Pragma Compat

that works with the --sinclair option or any "optional" machine for that matter.

Then READ/RESTORE/DATA would only be allowed in that mode.

Kind of like -lang qb in FreeBasic.
Reply
#3
This topic has been debated before. Unfortunately, no.
Doing that is very ambiguous. Eg.

Code:
IF A = B THEN PRINT "1st"
PRINT A
PRINT B
IF B = C THEN PRINT "2nd"
PRINT C
END IF
Which IF is closed by END IF? The 1st or the 2nd one?
There is a rule (when this is hardly implemented) which states it must be the 2nd if.

I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).
Reply
#4
boriel Wrote:I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).

Yes, I agree. All things considered then this is the ONLY viable solution in my view.

Also, it might also be sensible to enable Single Line IFs in Compat only mode along with the old versions of PLOT/DRAW and the READ/RESTORE/DATA
commands.

Or do seperate directives like: #Pragma CompatPrimitives and #Pragma CompatSingleIFs and #Pragma CompatDATALists.
Then the user can control what to rewrite and whatnot, and the CompatPrimitives (PLOT etc) is then coupled with the --sinclair option.
Then you can turn it all on at once by using #Pragma CompatOriginalBASIC and that makes four #Pragma(s) in total. No need to specify
"CompatOriginalZXBASIC" because that is specified implicitly with the --sinclair option.

Of course, in SingleIFs mode with END IF disabled then the current format is disabled but that is OK because I suspect that the orginal BASIC dialog
in the other machines do not support it.
Reply
#5
Darkstar Wrote:
boriel Wrote:I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).

Yes, I agree. All things considered then this is the ONLY viable solution in my view.

I think there's another solution: SAM Coupé's SAM BASIC and MasterBASIC, written by Andy Wright. already solved the same problem: An IF without a THEN or with no command after its THEN would be multiline and would need an END IF. In ZX BASIC, this behaviour would be optional, as you said.

Code:
#pragma sinclair_basic_compat ' ...or whatever name

IF a=1 THEN PRINT "This is old code pasted from Sinclair BASIC"

if b=2
  print "This is modern code"
end if

if b=3 then
  print "this is modern code too"
end if

IF PI THEN BEEP 1,2:PRINT "MORE OLD CODE"

What do you think? Would it be feasible?
Reply
#6
Yes. ;-)
This is exactly what I was thinking! and believe it could be done. Smile
An IF followed by a THEN in the same line will be a single line IF, so all old BASIC listings will be more compatible.

What do the others think?
Reply
#7
boriel Wrote:An IF followed by a THEN in the same line will be a single line IF

An IF followed by a THEN and at least one command, all in the same (logical) line. Otherwise compatibility with current code would be broken, and both kinds of IF could not be mixed unless you switch on and off the option flag.

Code:
' Example of old and new IF structures in the same source,
' all of them with THEN.
#pragma short_if=TRUE ' ...or whatever name
IF PI THEN PRINT "PURE SINCLAIR BASIC IF":BORDER 1:PAPER 0:CLS
IF PI THEN
  PRINT "MULTILINE IF":BEEP 3,3
END IF
if pi _
    then _
    print "This is a single-line IF from old sinclair code...":_
    border 2: _
    print "Sure!"
if pi then
    print "This is modern multiline IF"
    border 1
    print "Sure!"
end if
Reply
#8
Well, after *SEVEN* years :oops: (sorry), what I though impossible became possible :!:

I finally achieved it: ZX Basic now allows omitting the trailing END IF for single line IF THEN sentences (like Sinclair BASIC). Moreover, it also allows ELSE in the same line. This can lead to really strange (but valid) code:
Code:
10 IF a < b THEN LET a = a + 1: IF a < c THEN a = a + c: ELSE a = a - 1: LET c = c - 1: ELSE b = b + c
is now *VALID* and it's equivalent to:
Code:
IF a < b THEN
   LET a = a + 1
   IF a < c THEN
       a = a + c
   ELSE
       a = a - 1
       LET c = c - 1
   END IF
ELSE
   b = b + c
END IF
The 2nd way, despite being longer, can be more readable. It's up to you

The END IF for a single-line if is now optional (so you current code is still compatible):
Code:
10 REM lines 20 and 30 are equivalent
20 IF a < b THEN a = a + 1
30 IF a < b THEN a = a + 1: END IF
Reply
#9
Oh wow.

What are we going to talk about in the support and bug report forums now though?
Reply
#10
:mrgreen: :mrgreen: Haha

Well, this will be in 1.8 (about to be released).
The optimizer -O3 now has even more optimizations (really tested) and the compiler is a bit faster.
Also the plugin for VSCode is under development to enable syntax checking (syntax highlight already done). This plugin is not mine (I just made a small contribution).
Reply
#11
boriel Wrote::mrgreen: :mrgreen: Haha

Well, this will be in 1.8 (about to be released).
The optimizer -O3 now has even more optimizations (really tested) and the compiler is a bit faster.
Also the plugin for VSCode is under development to enable syntax checking (syntax highlight already done). This plugin is not mine (I just made a small contribution).


You know I'm going to benchmark it... Big Grin
Reply
#12
Also: vscode??

Visual studio? Or some other text editor?


Need to get one for sublime Wink
Reply
#13
The LSP (Language Server Protocol) is supported by VSCode, Sublime and many others.
BTW VSCode (Visual Studio Code) is open source (yes, the Visual Studio Editor) and multi-platform (Linux / Win / Mac).
Give it a try :roll:
Also for Windows we have other IDEs, like BorIDE, TommyGun (resurrected?)...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)