BASIC PREPROCESSOR

These files might not work on the most current version of the Commander X16, or these may be held over from the previous forum. To find previous versions of the emulator, so you can test old programs, please visit Our GitHub Page
Post Reply
Scott Robison
Posts: 952
Joined: Fri Mar 19, 2021 9:06 pm

BASIC PREPROCESSOR

Post by Scott Robison »


BASIC PREPROCESSOR allows one to create Commodore BASIC programs with a normal text editor without line numbers. Features:





  1. 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.


  2. A label can be defined on a line by itself as @+LABEL@.


  3. A label can be referenced after a GOTO or GOSUB as @-LABEL@ (including ON statements).


  4. A long variable name can be used as @!NAME@.


  5. A preprocessed comment can be used as @' whatever text you want @. These comments are not written to the PRG file.


  6. Any leading whitespace on a line is removed before writing the code to the PRG file.


  7. 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.



bpp.gif


Examples:





  1. 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.


  2. TEST.BPP is a simple example with a couple of labels.


  3. ON.BPP is a simple example with an ON expr GOSUB @-label@ ... statement.


  4. ARM.BPP shows a list of Armstrong numbers between 1 and 999 inclusive.




Changes to 0.4:





  1. 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.


  2. 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.


  3. 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:





  1. Defined the variable name array so that more than 10 variables could be defined.


  2. Added code to strip leading spaces from lines before writing them to the output file.




Changes to 0.2:





  1. 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):





  1. Supports writing Commodore BASIC programs without line numbers.


  2. Labels serve as GOTO and GOSUB destinations. Use @+LABEL@ to define a label and @-LABEL@ to expand a label.


Attachments
SIMPLE.PRG
BASIC PREPROCESSOR
(113 Bytes) Downloaded 87 times

[The extension bpp has been deactivated and can no longer be displayed.]

[The extension bpp has been deactivated and can no longer be displayed.]

ARM.PRG
BASIC PREPROCESSOR
(492 Bytes) Downloaded 94 times

[The extension bpp has been deactivated and can no longer be displayed.]

ON.PRG
BASIC PREPROCESSOR
(180 Bytes) Downloaded 95 times

[The extension bpp has been deactivated and can no longer be displayed.]

TEST.PRG
BASIC PREPROCESSOR
(137 Bytes) Downloaded 96 times

[The extension bpp has been deactivated and can no longer be displayed.]

BPP.PRG
BASIC PREPROCESSOR
(4.68 KiB) Downloaded 121 times
Post Reply