Skip to content

CPP

Compile Program

This string function returns compiled program lines for the given program-string, which contains Thoroughbred Basic program lines in LIST format preceded by their lengths. It is useful in building executable programs from ASCII strings of Thoroughbred Basic program lines.

CPP (program-string [,ERR=line-ref|,ERC=error-code])
program-string
is an uncompiled Thoroughbred Basic program in the format shown below in the REMARKS section.
line-ref
is the program line number or label to branch to if an error is produced by this function.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

This function primarily provides the ability to convert a formatted, listed program from its ASCII character representation into an executable public program.

Starting with release 8.3.0, a program string containing formats and data names will have its format and data name references validated against the data dictionary. Data name references in a program string can only be validated if their respective formats are already INCLUDEd; if not, the references will produce an error. Any errors that result from a program string’s format and data name references are saved to the ERRBUF system variable and the CPP function results in an ERR=160.

The format of program-string is as follows:

Byte(s) Description
1 - 8 Name of program
9 - 10 Length of first Thoroughbred Basic program line; unsigned binary
11 - n First Thoroughbred Basic program line in listed format

Length and listed format repeat as necessary

The statements can be in any order.

If an attempt is made to use CPP on a program-string containing statements with identical numbers or statements without a line number, an ERR=19 results.

If an attempt is made to use CPP on a program-string containing a duplicate label declaration, an ERR=21 results.

If an attempt is made to use CPP on an invalid string, an ERR=30 results. The resultant string from the CPP function must be placed in executable memory with the ADDR directive. It can then be executed with a CALL directive.

COMPILED$=CPP("TESTPROG"+ $000A$+"5 ENTER A$"+ $0010$+"10 FOR I=1 TO
10" +$000B$+"20 PRINT A$"+$0009$+"30 NEXT I"+$0007$+"40 EXIT")

is equivalent to a saved program called “TESTPROG” that lists as follows:

00005 ENTER A$
00010 FOR I=1 TO 10
00020 PRINT A$
00030 NEXT I
00040 EXIT
ADDR "TESTPROG", COMPILED$

puts the previous example into executable memory so that it can then be CALLed.

FMT1$="#DNFFMT1",
FMT2$="#DNFFMT2";
FORMAT INCLUDE #FMT1$;
FORMAT INCLUDE #FMT2$;
DNM1$=".DNAME1",
DNM3$=".DNAME3",
COMPILED$=CPP("DNAMEPGM"+$001B$+"100 FORMAT INCLUDE "+FMT1$+
$001B$+"200 FORMAT INCLUDE "+FMT2$+$0025$+"300 "+FMT1$+DNM1+
" = "+FMT2$+DNM3$+$0025$+"400 "+FMT1$+DNM3+" = "+FMT2$+DNM1$+
$0008$+"900 EXIT")

is equivalent to a saved program called “DNAMEPGM” that lists as follows:

00100 FORMAT INCLUDE #DNFFMT1
00200 FORMAT INCLUDE #DNFFMT2
00300 LET #DNFFMT.DNAME1 = #DNFFMT2.DNAME3
00400 LET #DNFFMT1.DNAME3 = #DNFFMT2.DNAME1
00900 EXIT

PFL and PFP functions ERRBUF system variable

From the Thoroughbred Basic Language Reference, Volume I: A–E, version 8.9.1. Open this page in the PDF