Well, just to recall: I've posted some questions about FP-CALC and
others for a BASIC compiler I've been working on.

Yesterday I released the "Release Candidate 3", which is (IMHO) very
estable and completely useful. If anybody is interested, please check
the compiler page at [url]http://www.boriel.com/2008/05/05/zx-spectrum-basic-compiler/[/url]

Like Z88DK, its a cross-platform development kit, but uses BASIC
instead of C. It covers many of the ZX Spectrum BASIC construct (Line
numbers, GOTO/GOSUB, etc..) but can be also used in a modern BASIC
fashion (similar to Visual Basic Script or Free Basic). That is: You
can define functions and subroutines. Free Basic site contains an
extensive Language reference at [url]http://www.freebasic.net/wiki[/url] which I
also tried to reach, but with some exceptions, since it is a Spectrum/
Z80/8bits oriented compiler. :)

The SDK also has an assembler (zxbasm), which can be used standalone,
and a macro-preprocessor (zxbpp).

This tools are written in python, so you will need either to install
the python interpreter in your system (Linux / Windows / Mac) or use
the .MSI (windows only) version which does not requires the python
environment installed.

06-08-2008, 11:17 PM

unix

Re: ZX Spectrum BASIC Compiler just released

Boriel ha scritto:[color=blue]
> Well, just to recall: I've posted some questions about FP-CALC and
> others for a BASIC compiler I've been working on.
>
> Yesterday I released the "Release Candidate 3", which is (IMHO) very
> estable and completely useful. If anybody is interested, please check
> the compiler page at [url]http://www.boriel.com/2008/05/05/zx-spectrum-basic-compiler/[/url][/color]

(first post in this NG by me)

Hm.... I'm wrong or there is only a rc4 zipfile ?

Best regards from Italy,
Dott. Piergiorgio M. d' Errico.

06-09-2008, 12:49 PM

unix

Re: ZX Spectrum BASIC Compiler just released

Some issues for you! Under Winxp I did a couple of quick tests.

1 - How do you implement the pause command? Comes up with an error
when you you use 'pause 0' or 'pause 1'

2 this program wont work - halts after the first line is drawn - works
ok in Basic though.

1 CLS
2 FOR c=0 TO 5
3 FOR b=0 TO 255
4 PLOT b,c
5 NEXT b
6 NEXT c

3 a few sample programs and a readme on use would come in handy too.

I like the way you can produce a .asm file too - its nice to have
alook at whats happening (though I havent looked into the above code!)

Dicky

06-09-2008, 08:36 PM

unix

Re: ZX Spectrum BASIC Compiler just released

Boriel wrote:[color=blue]
> Yesterday I released the "Release Candidate 3", which is (IMHO) very
> estable and completely useful. If anybody is interested, please check
> the compiler page at
> [url]http://www.boriel.com/2008/05/05/zx-spectrum-basic-compiler/[/url][/color]

Very nice idea. I look forward to checking it out.

06-12-2008, 07:07 PM

unix

Re: ZX Spectrum BASIC Compiler just released

On 9 jun, 13:49, dickydodds <di...@dickydodds.com> wrote:[color=blue]
> Some issues for you! Under Winxp I did a couple of quick tests.
>
> 1 - How do you implement the pause command? Comes up with an error
> when you you use 'pause 0' or 'pause 1'
>
> 2 this program wont work - halts after the first line is drawn - works
> ok in Basic though.
>
> 1 CLS
> 2 FOR c=0 TO 5
> 3 FOR b=0 TO 255
> 4 PLOT b,c
> 5 NEXT b
> 6 NEXT c
>
> 3 a few sample programs and a readme on use would come in handy too.
>
> I like the way you can produce a .asm file too - its nice to have
> alook at whats happening (though I havent looked into the above code!)
>
> Dicky[/color]

There are examples in the examples/ directory (download the .zip
file).
There's also a Wiki in progress. Check at: [url]http://www.boriel.com/wiki/en/index.php/ZXBasic[/url]

The pause command is not implemented as a command, but as a function
(I decided it for a very long-to-explain reason).
Just use:
#include once <pause.bas>
....
And then, in your program:
pause(xxxx)

Note: By now, you must write it in lowercase (I will allow it case-
insensitive in future releases). Also put the parenthesis.

06-12-2008, 07:11 PM

unix

Re: ZX Spectrum BASIC Compiler just released

On 9 jun, 13:49, dickydodds <di...@dickydodds.com> wrote:[color=blue]
> Some issues for you! Under Winxp I did a couple of quick tests.[/color]
[color=blue]
> 2 this program wont work - halts after the first line is drawn - works
> ok in Basic though.
>
> 1 CLS
> 2 FOR c=0 TO 5
> 3 FOR b=0 TO 255
> 4 PLOT b,c
> 5 NEXT b
> 6 NEXT c[/color]
[color=blue]
> Dicky[/color]

This example was also discuses in speccy.org. The problem here is that
this is *compiled* basic. Default type is not floating point, but is
chosen in a smart way. Since the compiler see you uses b in the range
[0..255] it uses a byte. But a byte is not enough for a 0 to 255 loop!
(It will stop when b > 255, but this will never happen because it will
restart to 0). To fix it, DECLARE the b variable (most of compilers
requires this).

Boriel <boriel@gmail.com> wrote:[color=blue]
> There are examples in the examples/ directory (download the .zip
> file).
> There's also a Wiki in progress. Check at: [url]http://www.boriel.com/wiki/en/index.php/ZXBasic[/url]
>
> The pause command is not implemented as a command, but as a function
> (I decided it for a very long-to-explain reason).[/color]

Please explain.
After all, you are attempting a SINCLAIR basic compiler so the first aim
should be to make it as sinclair compatible as possible before implementing
new features.

PAUSE is a command, not a function. In fact, what possible return value
could you get from a PAUSE *function*? Whether or not it completed its time
in pause before a key was pressed?

Note the difference between a command and a function. A command performs a
task (PRINT, PLOT, PAUSE), a function returns a value (SGN, SIN, INKEY$).

Boriel <boriel@gmail.com> wrote:[color=blue]
> This example was also discuses in speccy.org. The problem here is that
> this is *compiled* basic. Default type is not floating point, but is
> chosen in a smart way. Since the compiler see you uses b in the range
> [0..255] it uses a byte. But a byte is not enough for a 0 to 255 loop!
> (It will stop when b > 255, but this will never happen because it will
> restart to 0). To fix it, DECLARE the b variable (most of compilers
> requires this).
>
> 1 CLS: DIM b as Uinteger
>
> Uintegers are 16 bit unsigned integers. Types are:
> Byte, UByte, Integer, Uinteger, Long, ULong, Fixed and Float.[/color]

Might it not be more sensible to assume all numbers are Float unless
declared otherwise, just as sinclair basic itself does?

It'll make compiling basic programs without having to modify them possible.
And there's a whole library of pre-written basic code out there.
--
| |What to do if you find yourself stuck in a crack|
| [email]spike1@freenet.co.uk[/email] |in the ground beneath a giant boulder, which you|
| |can't move, with no hope of rescue. |
| Andrew Halliwell BSc |Consider how lucky you are that life has been |
| in |good to you so far... |
| Computer Science | -The BOOK, Hitch-hiker's guide to the galaxy.|

06-13-2008, 07:37 AM

unix

Re: ZX Spectrum BASIC Compiler just released

On Jun 12, 9:51*pm, Andrew Halliwell <spi...@ponder.sky.com> wrote:[color=blue]
> Boriel <bor...@gmail.com> wrote:[color=green]
> > There are examples in the examples/ directory (download the .zip
> > file).
> > There's also a Wiki in progress. Check at:[url]http://www.boriel.com/wiki/en/index.php/ZXBasic[/url][/color]
>[color=green]
> > The pause command is not implemented as a command, but as a function
> > (I decided it for a very long-to-explain reason).[/color]
>
> Please explain.
> After all, you are attempting a SINCLAIR basic compiler so the first aim
> should be to make it as sinclair compatible as possible before implementing
> new features.
>
> PAUSE is a command, not a function. In fact, what possible return value
> could you get from a PAUSE *function*? Whether or not it completed its time
> in pause before a key was pressed?[/color]
Sorry. My mistake. PAUSE is a SUBroutine (read pause.bas file in /
library subdirectory).

The problem with PAUSE is that is too Sinclair Related. And this
compiler aims to be not a strict Sinclair BASIC compiler. This is
almost impossible: Many instructions like READ/DATA can only be
implemented in an interpreter which is what the ROM already does. This
is not an interpreter, but a compiler. In fact, PRINT AT Y, X should
be "LOCATE Y, X". But I finally leave the Sinclair version.

The compiler aims to be a Sinclair first, Z80 later, and generic
finally (.NET, Java, .exe, PS3 or WII) compiler (it can be done).
PRINT, PLOT are more extended (every computer has a screen). Since it
is compiled, some things have been enhanced and it tries to get as
closer as possible to FreeBasic ([url]http://www.freebasic.net/wiki/[/url]).
However, I tried to close to Sinclair BASIC as much as possible. But
some thinks are unavoidable. E.g. Every IF must be closed with END IF.

On Jun 12, 9:54*pm, Andrew Halliwell <spi...@ponder.sky.com> wrote:[color=blue]
> Boriel <bor...@gmail.com> wrote:[color=green]
> > This example was also discuses in speccy.org. The problem here is that
> > this is *compiled* basic. Default type is not floating point, but is
> > chosen in a smart way. Since the compiler see you uses b in the range
> > [0..255] it uses a byte. But a byte is not enough for a 0 to 255 loop!
> > (It will stop when b > 255, but this will never happen because it will
> > restart to 0). To fix it, DECLARE the b variable (most of compilers
> > requires this).[/color]
>[color=green]
> > 1 CLS: DIM b as Uinteger[/color]
>[color=green]
> > Uintegers are 16 bit unsigned integers. Types are:
> > Byte, UByte, Integer, Uinteger, Long, ULong, Fixed and Float.[/color]
>
> Might it not be more sensible to assume all numbers are Float unless
> declared otherwise, just as sinclair basic itself does?[/color]
Yes, that was at fist, but resulted too inefficient (faster than
BASIC, of course). Anyway, I will put a command line parameter to
allow this in brief. Something
like:

zxb.py --default-type=float ...
[color=blue]
> It'll make compiling basic programs without having to modify them possible..
> And there's a whole library of pre-written basic code out there.[/color]
Please, tell me where to get that library. It would be a very good
test bech.

Regards,
J.

06-13-2008, 07:48 AM

unix

Re: ZX Spectrum BASIC Compiler just released

> Yes, that was at fist, but resulted too inefficient (faster than
Hmm. My replies are riddled with typos and I'm not a native English
speaker.
Sorry, but forums like usenet do not allow re-editing posts, so I
can't fix them up.

My apologies.

Regards,
J.

06-13-2008, 08:42 AM

unix

Re: ZX Spectrum BASIC Compiler just released

Boriel <boriel@gmail.com> wrote:[color=blue]
> The problem with PAUSE is that is too Sinclair Related. And this
> compiler aims to be not a strict Sinclair BASIC compiler. This is
> almost impossible: Many instructions like READ/DATA can only be
> implemented in an interpreter which is what the ROM already does.[/color]

Why is read/data/restore such a problem for a compiler?
Seems quite straightforward.
Data defines an area of memory from which values are read.
Read reads that data
Restore sets a pointer to that data based on the line number it was stored
in.
A simple memory structure should be able to handle that.
Something like "Data block start marker incorporating basic line number"
"Data type indicator" "data value" "data type indicator" "data value" ...
"data block end marker"

Then read would work properly.
The compiler couid have a "current data pointer" (which restore would reset
to the beginning of a given line)

And read/data/restore are three commands that MOST 1980s BASICS had.

This[color=blue]
> is not an interpreter, but a compiler. In fact, PRINT AT Y, X should
> be "LOCATE Y, X". But I finally leave the Sinclair version.
>
> The compiler aims to be a Sinclair first, Z80 later, and generic
> finally (.NET, Java, .exe, PS3 or WII) compiler (it can be done).
> PRINT, PLOT are more extended (every computer has a screen).[/color]

Err. Not every computer...
:)
[color=blue]
> Since it
> is compiled, some things have been enhanced and it tries to get as
> closer as possible to FreeBasic ([url]http://www.freebasic.net/wiki/[/url]).[/color]

Old style compilers got around enhancements by using REM statements to hold
some commmands... Might be an idea.

Boriel <boriel@gmail.com> wrote:[color=blue][color=green]
>> It'll make compiling basic programs without having to modify them possible.
>> And there's a whole library of pre-written basic code out there.[/color]
> Please, tell me where to get that library. It would be a very good
> test bech.[/color]

Well, there's WOS, quite a few type-ins are on there...
and you could take a look at the CSSCGC (most of the crap games on there
were written in basic. Some have machine code embedded, most don't)

On Fri, 13 Jun 2008 09:42:16 +0100, Andrew Halliwell
<spike1@ponder.sky.com> wrote:
[color=blue]
>Boriel <boriel@gmail.com> wrote:[color=green]
>> The problem with PAUSE is that is too Sinclair Related. And this
>> compiler aims to be not a strict Sinclair BASIC compiler. This is
>> almost impossible: Many instructions like READ/DATA can only be
>> implemented in an interpreter which is what the ROM already does.[/color]
>
>Why is read/data/restore such a problem for a compiler?[/color]

Indeed. I wrote an Amiga-based compiler years ago that handled
READ/DATA in the same way as Speccy BASIC works.

06-13-2008, 11:35 AM

unix

Re: ZX Spectrum BASIC Compiler just released

OK, I have some more issues - sorry! I ask here as I cant post on wos
at the moment.

1 - Can you confirm if the files must be unix format? I seem to be
having issues with this. If it is, then it is not possible to use the
Freebasic compilers - listings produced by fbedit dont compile under
this compiler, nor is it possible to copy and paste in windows. as you
get all sorts of compiler errors.

I can only get code to work if its typed into notepad by hand.

I think this is a real issue - in which case, can the CRLF's in the
file be stripped out or something? I have even tried using ultraedit
in unix mode but that deosnt always work either - its driving me
NUTS!!!

Dicky

06-13-2008, 12:58 PM

unix

Re: ZX Spectrum BASIC Compiler just released

dickydodds <dicky@dickydodds.com> wrote:[color=blue]
> I think this is a real issue - in which case, can the CRLF's in the
> file be stripped out or something? I have even tried using ultraedit
> in unix mode but that deosnt always work either - its driving me
> NUTS!!![/color]

In unix there're tools to convert files from windows or mac to unix format.
dos2unix is one of them.
I imagine the same programs will have ports to windows too.

Andrew Halliwell wrote:[color=blue]
> dickydodds <dicky@dickydodds.com> wrote:[color=green]
>> I think this is a real issue - in which case, can the CRLF's in the
>> file be stripped out or something? I have even tried using ultraedit
>> in unix mode but that deosnt always work either - its driving me
>> NUTS!!![/color]
>
> In unix there're tools to convert files from windows or mac to unix format.
> dos2unix is one of them.
> I imagine the same programs will have ports to windows too.
>[/color]
I use notepad++ for all my text editing needs in windows (it really is
rather good) and it can convert to unix format from dos format and vice
versa

06-13-2008, 03:09 PM

unix

Re: ZX Spectrum BASIC Compiler just released

> I use notepad++ for all my text editing needs in windows (it really is[color=blue]
> rather good) and it can convert to unix format from dos format and vice
> versa[/color]

Yes, it is good - now I can see end of line chars. However, I still
have a problem (which I thought was due to the EOL chars)

The clock 2 example .bas has a dual while loop and so deos a bit of
gwbasic code I got off the net - looking to convert to the spectrum -
just as a test of the compiler - but everytime I get an error : -

The offending line is 190 - it deosnt matter that its lower case. I am
not stupid but it all looks fine to me, so, why deosnt it work? I
started declaring vars in the first line to see if that made a
difference to no avail. Even if I remove the lines 160, 170, 180 to a
print statement and it fails - so is it the actual While Statement? (I
added the brackets to it as another option to compile it to no avail).

I am using RC6 version too.

I love the idea of this compiler, but, I cant get much to work so far
LOL!!
Dicky

06-13-2008, 06:32 PM

unix

Re: ZX Spectrum BASIC Compiler just released

[color=blue]
> I think this is a real issue - in which case, can the CRLF's in the
> file be stripped out or something? I have even tried using ultraedit
> in unix mode but that deosnt always work either - its driving me
> NUTS!!!
>
> Dicky[/color]

It should understand both Unix and Dos formats (In fact I work in both
platforms). If you suspect there's an issue with it, please, tell me
which message error are you getting so I could fix it up in the
compiler.

On the other hand, you can also use Notepad++ which saves in both Dos
and Unix formats (as someone stated here).

Tray this and tell me.
On the other hand, when the compiler reports a syntax error, it's
related to the text file number, no to the basic line numbers.
BASIC line numbers ARE ignored and completely useless here (you can
ommit them). They're only labels useful for GOTO or GOSUB. You can
also define text labels, with a colon: