Program Structure

The structure of an ASB program is rather loose, consisting of one or more lines satisfying the following syntax:

{line #}{label:}{statement} {! comment}

Throughout this document, squiggly brackets {  } indicate optional elements, so each of the four parts of the typical program line above is optional.

Line numbers served two purposes in early versions of BASIC: as a target for GOTO or GOSUB / CALL statements, and as a way of identifying locations of runtime errors. Although they remain supported, their use is generally deprecated now in favor of labels, which are themselves typically limited to places where they are needed to identify the target of a GOTO or GOSUB. Some programmers insert labels as a kind of road map (e.g BEGIN: or MAIN'BODY: ) but a label without any references to it should probably be replaced by a comment, just to eliminate any doubt as to whether the location could be the target of a GOTO.

Statements are terminated implicitly by the end of the source text line (LF or CRLF), or explicitly by the comment character "!".  To extend a logical statement over multiple source text lines, use the "&" character to indication continuation, e.g.

statement'syntax$ = lineno$      &

                    + label$     &  ! optional comment may follow "&"

                    + statement$    ! another comment

 

As shown in the example above, comments may follow the & continuation character without interfering with the continuation. However, be careful about ending a comment with the & continuation character, since it effectively extends the comment to the next line. For example, in the following, the "print b" statement will become part of the comment at the end of the previous line, due to it ending in & ...

print a    ! don't end a comment with &

print b    ! else following line (this one) will be part of comment

 

Multiple statements may also be combined on a single source text line by separating them with a colon, e.g.

if SWAP then &

    V1 = V1+V2 : V2 = V1-V2 : V1 = V1-V2    ! 3 statements on a line

 

Note that while the above form is typical in older code, the style—if without endif, continuation, multiple statements per line—like the archaic verb "LET", is generally deprecated in favor of the more readable:

if SWAP then

    V1 = V1 + V2

    V2 = V1 - V2

    V1 = V1 - V2

endif

 

Statements fall into the following categories:

•   Declaration of Variables

•   Control Structures

•   Compiler Directives

•   Dynamic Structure Functions

•   Miscellaneous Statements