Pascal
|
Pascalated Boriel ZX BASIC
|
Note
|
|
#include <input.bas> ' string$ = INPUT(32), number = VAL INPUT(12)
#include <attr.bas> ' ATTR function
#include <point.bas> ' POINT function
#include <screen.bas> ' SCREEN$ function
#define PROGRAM REM
#define BEGIN REM
'#define CONST CONST ' already defined
#define VAR DIM
#define INTEGER LONG
#define REAL FLOAT
#define CHAR STRING ' UBYTE is type integer
'#define STRING STRING ' already defined
#define BOOLEAN UBYTE
#define TYPE AS
'#define WHILE WHILE ' already defined
#define REPEAT DO
#define UNTIL LOOP UNTIL
#define PROCEDURE SUB
'#define FUNCTION FUNCTION ' already defined
#define TRUNC INT
#define SQRT SQR
'#define MOD MOD ' already defined
CONST TRUE TYPE BOOLEAN = 1
CONST FALSE TYPE BOOLEAN = 0
|
You must insert these lines at the beginning of the program.
Or, you can put these lines on a file named "pascal.h"
and write the following line at the beginning of your program:
#include "pascal.h"
|
VAR
x :INTEGER;
y :REAL;
z :STRING;
ok :BOOLEAN;
an :ARRAY [0..5] OF INTEGER;
ax :ARRAY [0..5] OF REAL;
Board :ARRAY [0..5] OF STRING;
|
VAR x TYPE INTEGER : REM -32768..32767
VAR x2 TYPE INTEGER = 12345 ' with initialization
VAR y TYPE REAL ' same as ZX Spectrum numbers
VAR z$ TYPE STRING ' $ is optional - is ignored.
VAR ok TYPE BOOLEAN
VAR AN(0 TO 5) TYPE INTEGER ' indexes start at 0 instead of 1
VAR AX(5) TYPE REAL
VAR Board1$(5) ' Indexes are initialized with zero instead of space: a$(1) = CODE 0
VAR Board2$(0 TO 5) TYPE STRING ' do not use Board$(2,3) to access data
VAR Board3$(8) TYPE STRING ' use Board$(2)(3) to access data
|
Uppercase is different from lowercase.
Other types can be used. Click here for a list of types.
|
REPEAT
...
UNTIL condition;
|
REPEAT
...
UNTIL condition
|
REPEAT loop
|
WHILE condition DO
BEGIN
...
END
|
WHILE condition
...
END WHILE
|
WHILE loop
|
IF condition1 THEN
BEGIN
...
END
ELSE IF condition2 THEN
BEGIN
...
END
ELSE
BEGIN
...
END
|
IF condition1 THEN
...
ELSEIF condition2 THEN
...
ELSE
...
END IF
|
IF control structure.
|
PROCEDURE procedure_name;
BEGIN
...
END
|
PROCEDURE ProcedureName
...
END PROCEDURE
|
Procedure declaration without arguments.
|
procedure_name(arg)
|
ProcedureName(arg)
|
Procedure call with arguments.
|
FUNCTION function_name (arg:REAL) :REAL;
BEGIN
...
function_name := result
END;
|
FUNCTION FunctionName (arg TYPE REAL) TYPE REAL
...
RETURN result
END FUNCTION
|
Function declaration with arguments.
Use RETURN only on the last line of a function.
|
t := function_name(arg)
|
t = FunctionName(arg)
|
Function call with arguments.
|
total_apples := 0
|
LET total_apples = 0
total_apples = 0
LET TotalApples = 0
TotalApples = 0
|
Pascal notation
or Java notation.
|
READ( line );
READ( number );
|
line$ = INPUT(Size)
number = VAL( INPUT(Size) )
|
You must add this line
at the begining of the program:
#include <input.bas>
|
Boriel ZX BASIC
|
Remember:
This is not Sinclair ZX BASIC
|
LET s$ = "0123"
PRINT s$(0)
|
Strings start at position 0.
Sugestion: you can initialize the string with one character
and the index will be like the ZX Spectrum
but then the LEN will be one extra character.
|
VAR U$(8) TYPE STRING
IF U$(3)(4) = " " THEN PRINT "OK"
|
On the ZX Spectrum, DIM initializes character arrays to " ".
But here, strings on the array must be initialized by the program.
VAR U$(8) ' On the ZX Spectrum: DIM U$(8,5)
FOR i=0 TO 7
LET U$(i+1) = "012345"
NEXT i
|
VAR v
|
You should specify the variable TYPE
because the variable could end up with some undesirable type.
Example: UBYTE (with values of 0..255).
|
LET s$="012"
PRINT CODE( s$(1) ) - CODE( s$(2) )
|
This prints 255 instead of -1.
You should use PRINT CAST(INTEGER,0) + CODE(s$(1)) - CODE(s$(2))
Forcing INTEGER to REAL:
LET r = (0.1+a-0.1)/b
or LET r = CAST(REAL,a)/b
Other example:
PRINT PEEK (0)-255
PRINT -255+PEEK 0
|
PRINT ''' 123
|
On ZX Spectrum, ' moves to next line.
On the ZX BASIC compiler ' is equal to REM.
You should use: PRINT CHR$(13, 13, 13) ; 123
|
LET A$ = "123"
LET a$ = "456"
|
Uppercase is different from lowercase.
It's better to use Uppercase for global variables and lowercase for local variables.
|
LET line$ = "123"
|
You can use string identifiers with more than 1 character.
|
LET name$ = "123"
LET name = "123"
|
"$" is ignored - do not use numerical variables and string variables with the same name.
|
Escaped characters
\\
\*
\`
\#NNN
|
The \ backslash symbol.
The (c) Copyright Symbol.
The £ pound sterling symbol.
Any character, where NNN is a decimal number in the range 000 to 255.
|
Block characters
\ \·'\'·\''
\·.\·:\'.\':
\.·\.'\:·\:'
\..\.:\:.\::
|
Graphic block characters from CHR$(128) to CHR$(143).
|
Control characters.
\{pN}
\{iN}
\{bN}
\{fN}
|
Control characters.
PAPER color 0 to 8.
INK color 0 to 8.
BRIGHT 0 or 1.
FLASH 0 or 1.
|
LET f$ = "4/2*3+2^3"
PRINT VAL( f$ )
|
Works only with basic operators.
Sugestion: To use variables create a function VALx$
that substitutes "x" by its value on the entite string.
Example:
LET f$ = "2*x"
LET x = 111
LET g$ = VALx$( f$ ) : REM g$ = "2*111"
PRINT VAL(g$) : REM gives 222
Sugestion: To use functions create a function VALf$
that substitutes function name to its code.
Example:
LET f$ = "SIN 1.7"
LET g$ = VALf$( f$ ) : REM g$ = CHR$ 178 + "1.7"
PRINT VAL(g$) : REM gives 0.99166481
|
NEW
|
Does not exist.
Use: RANDOMIZE USR 0
|