BASIC PREPROCESSOR
BASIC PREPROCESSOR allows one to create Commodore BASIC programs with a normal text editor without line numbers. Features:
Much as strings begin and end with a quotation mark ("), macro constructs begin and end with a commercial at sign (@). This means that you cannot include @ in a macro, but otherwise any character may be used.
A label can be defined on a line by itself as @+LABEL@.
A label can be referenced after a GOTO or GOSUB as @-LABEL@ (including ON statements).
A long variable name can be used as @!NAME@.
A preprocessed comment can be used as @' whatever text you want @. These comments are not written to the PRG file.
Any leading whitespace on a line is removed before writing the code to the PRG file.
The preprocessor (probably) requires an emulator built from the master github branch.
The program is written almost completely in BASIC. The one exception has to do with tokenization. Normally as you enter lines of BASIC the computer will translate them into a compressed tokenized form, and this is necessary for the programs to be usable. In order for BPP.PRG to create tokenized BASIC programs, it has a small machine language routine in golden RAM that converts from plain text to tokenized form. The tokenized form is written to the output PRG file.
Here is a super simple example called SIMPLE.BPP.
Quote
@' THIS IS A COMMENT '@
@'
THIS IS
A MULTILINE
COMMENT
'@
@+LOOP@
IF @!COUNT-VAR@ > 10 THEN PRINT "DONE COUNTING": END
GOSUB @-INC-VAR@
GOTO @-LOOP@
@+INC-VAR@
@!COUNT-VAR@ = @!COUNT-VAR@ + 1
RETURN
An animated GIF demonstrates the process of using the program.
Examples:
BPP.BPP is the preprocessor itself as a text file. It can be modified and processed by BPP.PRG, making it easier to maintain in the future and serving as the single best example of use of the program the time of writing, as it includes labels, variables, and comments.
TEST.BPP is a simple example with a couple of labels.
ON.BPP is a simple example with an ON expr GOSUB @-label@ ... statement.
ARM.BPP shows a list of Armstrong numbers between 1 and 999 inclusive.
Changes to 0.4:
BASIC PREPROCESSOR was originally written in line number BASIC. Now that it is flexible enough, it has been rewritten in itself, serving as an example of how to use the various macros.
Added preprocessor comments that are removed from the final BASIC program file. Use @'WHATEVER TEXT@ (except you cannot include an at sign in the comment.
Note that names and labels are not limited to alphanumeric text. Any character other than at at sign can be included, such as hyphens, to make names and variables more readable than they might otherwise be.
Changes to 0.3:
Defined the variable name array so that more than 10 variables could be defined.
Added code to strip leading spaces from lines before writing them to the output file.
Changes to 0.2:
Added support for long variable names. Use @!NAME@ to use a long variable name. It will be mapped to a unique two character short name, where the first character is a letter and the second is a number to avoid conflict with any two letter tokens or predefined variables such as ST. The name can include a % or $ after the name (such as @!NAME%@ or @!NAME$@ to indicate it is an integer or string. It can also be used with DEF FN and DIM arrays.
Initial release (0.1):
Supports writing Commodore BASIC programs without line numbers.
Labels serve as GOTO and GOSUB destinations. Use @+LABEL@ to define a label and @-LABEL@ to expand a label.