home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
robot-pd
/
12400.ZIP
/
12400B.DSK
/
manual05.txt
< prev
next >
Wrap
Text File
|
1998-04-30
|
21KB
|
635 lines
═
╩C H A P T E R F I V EΩ
╩5 COMP - Extended BASIC Language CompilerΩ
╩FormatΩ :╔COMP [<selectors>] <source.file> <object.file>Θ
The compiler reads through the given source file and
converts it into a BASIC program. This program can then be
executed under Centrox in the same way as a transient
program. The object code produced by COMP will be placed
in the destination file path.
Compilation can be aborted by holding down the "Q" key for
about one second.
The selector "S" produces system object code. If this
option is selected then COMP will create a /COM file. The
file name element of the destination file path will be
acknowledged but the directory path and file type will be
ignored.
Single drive users can only use this option if the source
code is held on the SYSTEM disk. The easiest way to
transfer your source across is to load it into CTX, then
save it back onto the system disk.
The selector "E" produces error trapped code. If an error
occurs the program will display the BASIC error number and
line, by default this switch is disabled which means that
errors cause the system to return to BASIC.
╩5.1 Source File RequirementsΩ
EBL differs from BASIC in that it does not use line
numbers. The program is laid out as a series of
statements, for which only the order is important. The
actual "style" of the text is irrelevant to the computer.
It is recommended that all global variables be defined in
one go, right at the start. The term "global variable"
simply means a type of variable which can be accessed by
any part of the program. All locomotive BASIC variables
are global, for example.
Note that all the commands listed here can be abbreviated
by truncating the command name, and following it by a dot.
Comments can be inserted by enclosing the text between two
braces eg: {This is a comment}
Commands must be followed by a semicolon `;'. Older
versions of the compiler allowed the semicolon to be
omitted if it was at the end of a line-THIS IS NO LONGER
ALLOWED.
Extensive use is made of complex overlay techniques.
Whilst this releases useful memory, it does have the
disadvantage of increasing disk access. As a result, the
compiler does run fairly slowly. With a trailing wind it
can average 10 lines per minute!
╩5.2 ProceduresΩ
Procedures are similar to subroutines. That is, they are
sections of code which can be "called" (invoked) at any
time to carry out frequently required tasks. The main
difference between a subroutine and a procedure is that
procedures have defined entry and exit points-subroutines
do not.
The other difference is that procedures usually provide a
means by which arguments can be passed into the routine.
They also provide for the creation of "local" variables.
Local variables become invisible whenever a section of
code outside "their" procedure is being executed. This
provides TOTAL isolation for a procedure's variables,
reducing the possibility of unwanted interference.
╩5.3 Using CommandsΩ
The compiler is only programmed with program flow commands
such as IF..THEN, WHILE..WEND etc. It is up to the user to
define ╔actionΘ commands such as PRINT,≤DRAW etc.≤They can
be defined using the DEFCOM command, or inserted directly
into the BASIC code using the "INLINE" command.
╩5.4 Code BlocksΩ
Most of the structure commands work on a principle known
as code blocking. One example of this is the BASIC
WHILE...WEND structure. The code being repeated can be
thought of as a block of instructions. This principle is
extended in EBL.
It is considered good practice to indent each section of
code in a block. This improves readability of the code, as
it makes it easier to see where a code block has not been
closed.
╩5.5 Command DictionaryΩ
Each of the commands listed is given in the following
format:-
1.Command Format.
Describes the general form of the command-ie exactly what
the compiler can expect. This information is given in the
same form as for the O.S. command list.
2.Example Code.
This is a short section of code which shows one use of the
command under consideration. In all the examples, only the
relevant section of code is given. The commands and
functions shown may need to have been defined elsewhere
for the example to ╔workΘ.
╩5.5.1 Definition CommandsΩ
╩FormatΩ :╔DEFTITLE("<Title string>"[,version[,mark]]);Θ
(Overlayed)
This changes the program title from the default of
<program name>. This title will form part of the copyright
banner. The version and mark numbers can also be added.
Note that the message:-
The format of the copyright banner is:-
<Title String> v<version>.<mark> - (c) <user name>, <year>
Where <version> and <mark> default to 1 and 0.
The copyright banner is always displayed by COMP object
code and is displayed after the program has finished
loading.
╩FormatΩ :╔DEFVAR ++<<variable><type>[=<expression>]>;Θ
(Overlayed)
╩ExampleΩ :DEFVAR name$="This is my name"
count%
money!=0
ENDVAR;
Defines the following list of variables so that the
compiler will recognise them when they appear (later) in
the code. If DEFVAR is used outside a procedure, the
variables will be global. If it is used within a procedure
they will be local to that procedure.
If the optional expession is included, then the variable
will be given that value every time the DEFVAR statement
is executed. Note that for this to happen the DEFVAR
statement be inside the main program body or a procedure.
External variables-variables which were created by some
other program-can be defined simply by placing a star
between the name and type. The most common use of external
variables is accessing Centrox variables. A list of
Centrox variables can be found in the technical section of
this manual.
╩FormatΩ :╔DEFFUNC <name>:<keyword>[<type>]
╙≤≤≤≤ ([++<<name><type>>])Θ
(Overlayed)
╩ExampleΩ :DEFFUNC left:left$(string$,posn%);
Defines a BASIC function. The keyword will replace the
name when compiled. The list of types indicate the
parameter type required for the function. If a function
has optional parameters, then define more than one version
of the function:-
╔DEFFUNC rnd0:RND!();Θ
╔DEFFUNC rnd1:RND!(value%);Θ
The name supplied as a parameter serves only as a reminder
to the programmer as to the argument required to be passed
to the function. The parameters do, however, exist as
global variables in their own right. You can use these
parameters by name if you find yourself running out of
memory. Note that string functions MUST be suffixed by the
dollar sign as normal.
╩FormatΩ :╔DEFPROC <name>([++<<variable><type>>]);Θ
(Overlayed)
╩ExampleΩ :DEFPROC box(xco%,
yco%,
side%)
move(xco,yco);
drawr(side,0);
drawr(0,-side);
drawr(-side,0);
drawr(0,side);
ENDPROC;
Defines a section of code such that its actions can be
invoked by name and treated as a command. It should be
noted however that procedures do involve some overhead in
code and will therefore execute slower than normal
commands.
The list of variables are the parameters of the procedure.
The best way to think of parameter variables is that they
are normal variables (like those that might have been
created with DEFVAR) but that when the procedure is
invoked, they take on the value of the corresponding
argument.
The above ╔BOXΘ procedure could be invoked by:-
╔box(50,50,100);Θ
Which would draw a box whose top left coordinates were
50,50 and whose sides were 100 pixels long.
╩FormatΩ :╔DEFPROG <name>([++<<variable><type>>]);Θ
(Overlayed)
╩ExampleΩ :DEFPROG mode(mode.number%)
mode(mode.number);
ENDPROG;
NB:The name given with the command has no affect on the
program, it only serves as a useful reminder to the
programmer.
Defines the start of a program. The list of variables may
be given to allow argument passing from the Shell. The
Shell command line format for such arguments is given
below:-
1.INTEGERs and REAL numbers.
Simply type the number after the command name or previous
arguments:-
╔1>box 50 50 100Θ
2.STRING values.
These should be entered enclosed between quotes.
╔2>centre 12 "Centres text on given line"Θ
It is NOT recommended that you read filenames into string
parameters, since users may be confused by the double
quotes (remember-the Shell does not normally require that
you use double quotes). The solution to this problem will
be covered in the section on using KERNEL vectors.
Arguments must be constant values. Expressions will NOT be
evaluated-only misinterpreted. Take care when entering
numeric data from the Shell, programs may crash if numeric
data is given in an invalid format. At the very least, a
value of zero will be placed in the parameter.
╩FormatΩ :╔DEFLOOP <number of times>[ USING <variable>];Θ
(Internal)
╩ExampleΩ :prints("8 Times table");
count=1;
DEFLOOP 12;
printn(count);prints("times 8 is");
printn(count*8);
ENDLOOP
In most programs there will be a section of code which
needs to be repeated a certain number of times. The
DEFLOOP command defines the start of such a section of
code, and the number of repetitions. The section of code
is terminated by an ENDLOOP command.
The optional USING clause allows you to specify a
particular variable to be used as the loop counter. The
above example could (and should) be written as:-
Prints("8 Times table");
DEFLOOP 12 USING Count;
Printn(Count);Prints("times 8 is");
Printn(Count*8);
ENDLOOP
Loops may be nested - that is, one loop may be defined
inside another, up to the level of ten nested loops. The
compiler will associate ONE AND ONLY ONE ENDLOOP command
with every DEFLOOP.
╩FormatΩ :╔DEFCASE <variable>:++<<expression>
≤≤≤≤≤ DO <procedure call> {CONT DONE DEFAULT ENDCASE}>;Θ
(Overlayed)
╩ExampleΩ :DEFCASE menu.choice "L" DO load.file;DONE;
"S" DO save.file;DONE;
"P" DO print.file;DEFAULT;
not.a.choice;ENDCASE;
Defines a multiple 'IF' command. In effect, each of the
expressions is evaluated in turn. When the result matches
the contents of the given variable, the procedure
associated with the expression will be called. There are
four possible actions after the procedure has been called.
The action depends on the next identifier.
CONT - Continue searching down the tree for a further
match.
DONE - Jump past the remaining tree tests.
DEFAULT - The next procedure call (NO expression) is to be
executed if no match has been found so far.
ENDCASE - End of tree.
╩FormatΩ :╔DEFCOM <command name><BASIC.name>
≤≤≤≤≤ ([++<<name><type>>]);Θ
(Overlayed)
╩ExampleΩ :DEFCOM prints:print(string$);
As mentioned above, COMP knows very few BASIC commands.
There are two methods of entering commands that it does
not know about. DEFCOM is ideal for BASIC commands that
have a set number of parameters. When it finds the command
name, the compiler will swap it for the BASIC name. The
brackets will ┴NOTß appear in the object code.
If a command has optional parameters, then define several
versions with different command names, but the same BASIC
name. The parameter name serves only as a reminder as to
the nature of the argument.
╩FormatΩ :╔DEFLABEL <name>[=<address>];Θ
(Overlayed)
╩ExampleΩ :DEFLABEL data1;
INLINE restore^data1
This defines a label that can be referenced from INLINE
code-see later. The optional [=<address>] clause can be
used to assign a particular line number to the label.
╩FormatΩ :╔DEFWHILE <condition>;Θ
(Internal)
╩ExampleΩ :count=0;
DEFWHILE count<10;
count=count+1;
prints("Now at number");printn(count);
ENDWHILE;
In a lot of programs there will be a section of code which
needs to be repeated until a certain condition becomes
true. The DEFWHILE command defines the start of just such
a section of program code. The code is terminated by
ENDWHILE.
WHILE loops can be nested up to ten deep.
╩FormatΩ :╔DEFARRAY <array name><type.id>
≤≤≤≤≤ [++<subscript range>]Θ
(Overlayed)
╩ExampleΩ :DEFARRAY name$[6-10]
Warns the compiler that space should be made available for
the given array. Note that the command allows the user to
choose the range of subscripts, ie choose the number of
the first subscript instead of it starting at zero. COMP
will NOT accept a starting subscript number less than one.
Note that COMP produces object code in which the first
subscript of an array is ALWAYS zero, by compensating for
any offset. This means that care needs to be taken when
accessing arrays using INLINE code-it must be written to
allow for this.
As an example:-
╔DEFARRAY fred$[6-6] {Single dimension array !}
....
fred[6]="Example"
INLINE ?fred[0] {Display `Example'}Θ
Once defined, arrays can be accessed like variables-as
long as the subscripts are given. They can also be local
if required.≤Array ╔elementsΘ can ≤be passed as arguments
but not if they are to form part of an array's subscript.
Arrays or their elements may NOT be defined as parameters
under any circumstances !
Note that array notation requires that subscripts are
enclosed in square brackets, hence the square brackets
used to define the command do NOT imply that the
subscripts are optional.
╩5.5.2 Control StructuresΩ
╩FormatΩ :╔IF <cond.> THEN <comd.> [ELSE <comd.>] ENDIFΘ
(Internal)
╩ExampleΩ :IF choice=1 THEN got.it.right;
ELSE got.it.wrong;
ENDIF;
If the result of the condition is TRUE, the first section
of commands will be executed. If the result of the
condition is FALSE then the second set of commands (if
given) will be executed, control then jumps to the next
command after the ENDIF command.
╩5.5.3 General CommandsΩ
╩FormatΩ :╔READARG([++<<variable><type>])Θ
(Overlayed)
╩ExampleΩ :READARG(name$);
Reads arguments into the given variables, in the same way
as DEFPROG. Note that, again, the variables do not have to
have been defined already.
╩FormatΩ :╔INLINE(<inline code>);Θ
(Overlayed)
╩ExampleΩ :INLINE(?using"╤##±";var!);
The INLINE command is the alternative method for entering
BASIC commands. The inline code will be copied into the
object code exactly as read except for certain "meta
characters":-
╔_<expression>_Θ
This signals that the following text is a COMP evaluatable
expression. The resulting code will then be inserted into
the text. The use of "_" as an expression terminator is
optional. Any other legal terminator would also suffice,
with the following proviso.
Standard terminators like ";,)]" are accepted by the
expression parser and not returned to INLINE. This means
that the following INLINE statement would not work:-
╔INLINE(ink _expr1,_expr2);Θ
The separating comma would be "swallowed" by the
expression parser and would hence not appear in the object
code. The solution is to add a "throwaway" terminator. The
"_" sysmbol is intended to be used for this purpose. The
correct code might be:-
╔INLINE(ink _expr1_,_expr2_);Θ
╔"^<label>"Θ
This allows the user to reference a label. (see DEFLABEL)
note that this command causes the current line of object
code to be written to disk and hence the following would
not have the intended result:-
╔INLINE(If true% THEN GOSUB^DoThis:GOTO ^DoThatΘ
The GOTO≤statement would be≤placed on the line ╔afterΘ the
GOSUB and IF.
╩FormatΩ :╔INCLUDE <file path>Θ
(Overlayed)
╩ExampleΩ :INCLUDE -/eblc.src/basiccom.lib;
Tells≤the compiler≤to ╔temporarilyΘ abandon reading from
the current file, and to start reading from the given file
instead. INCLUDE should be used to build up library files
which contain useful sections of code. The following
library files are provided as standard:-
"BASICCOM.LIB"
Contains common BASIC command definitions. It is
recommended that this file be automatically INCLUDEd at
the start of all programs.
"TURTLE.LIB"
This file contains turtle extensions, mainly in the form
of procedures. Note that these definitions require that
the "BASICCOM.LIB" and "BASICFN.LIB" files be included
BEFORE the "TURTLE.LIB" file.
"BASICFN.LIB"
Contains common BASIC function definitions.
It is recommended that users CAT each LIB file to see what
commands are available.
Note that≤all ╔proceduresΘ appear in the≤resulting object
code-even if they haven't been used. This means that
surplus procedures will waste disk storage space. Bare
this in mind when creating library text files. Such a
problem≤will not occur≤with ╔commandsΘ and ╔functionsΘ as
they don't translate to BASIC code.
INCLUDEd files can themselves use INCLUDE, but only four
files can be suspended at any one time. INCLUDE can be
used any number of times provided that the above rule is
adhered to.
╩FormatΩ :╔EXCLUDEΘ
(Overlayed)
Instructs the compiler to abandon the current file and
return to the previous file suspended by INCLUDE.
╩FormatΩ :╔SETLINE <line number>Θ
(Overlayed)
Instruct the compiler to compile subsequent object code
with a new sequence of line numbers, starting with the
number given. This command can be used to generate
Compiler LINK files, by making the first command in the
file:-
SETLINE 10000
╩FormatΩ :╔LINETO <address>[,<offset>]Θ
This marks the start of a block of code that is to be
compiled from the given line number. The <offset> saves
your from having to use the DEFSEG command, but works in
the same way. The block of code is terminated by the
LINEBACK command and subsequent code is generated in the
original sequence until further SETLINE or LINETO commands
are issued.
╩FormatΩ :╔EXIT LOOPΘ
or
╔EXIT WHILEΘ
╔EXIT PROCΘ
╔EXIT VIA <proc call>Θ
EXIT LOOP and EXIT WHILE cause a jump to the next
statement after the current ENDLOOP or ENDWHILE. Note that
use of EXIT LOOP while inside a DEFLOOP nested DEFWHILE
block will terminate both the DEFWHILE and DEFLOOP blocks.
EXIT PROC simply terminates the current procedure, while
EXIT VIA terminates the current procedure by jumping
directly into another, specified, procedure.
╩FormatΩ :╔SYSTEM <vector>[++<argument>]Θ
(Overlayed)
Calls one of the system vectors. The list of arguments
vary for each vector and are listed here:-
╤#±1 :<directory number>
╤#±2 :<directory path>╟+τ
╤#±3 :<File path>╟+τ
╤#±4 :None.
╤#±5 :<command phrase>
╤#±6 :<AMSDOS file.name>,<USER number>,<drive flag>
╤#±7 :None.
╤#±8 :<Type flag>
╤#±9 :<phrase or word>
╤#±10:As ╤#±6
╤#±11:None.
╤#±12:None.
╤#±13:<drive flag>
╟+τ:These should be prefixed by a space eg; " test.bas"
╩Passing Filenames As Arguments From The ShellΩ
If your program requires a filename to be passed, use the
following method:-
╔Command format:1>MYPROG <number> <filename> <selectors>Θ
╔Program:-Θ
DEFPROG myprog(number%); {Read number direct}
INLINE vectr%=3:GOSUB 60000;
{Above line evaluates file path as received from Shell}
READARG(selectors$); {read string of selectors}
...
ENDPROG
Note that SYSTEM 3 is NOT used, since this requires that a
file path is already known.
Note that your program picks up command tail arguments in
the same way as other programs, allowing the intermixing
of vector╤#±3 with READARG() as above.
For further details, see the technical information section
at the end of this manual.
F I V EΩ
╩5 COMP - Extended BASIC Language CompilerΩ
╩FormatΩ :╔COMP [<selectors>]