Syntax

Vocabulary

The following reserved keywords form the basic vocabulary of the language. The keywords may be spelled with either upper or lower case letters, or a mix of both. Therefore PRINT, print and Print are equivalent.

AND AS ASM BYTE CALL CHARAT CLOSE CONST CONTINUE DATA DECIMAL DECLARE DIM DO ELSE END ERROR EXIT FAST FLOAT FOR FUNCTION GET GOSUB GOTO IF INCBIN INCLUDE INLINE INPUT INT LET LOCATE LOAD LONG LOOP MEMCPY MEMSET MEMSHIFT MOD NEXT NOT ON OPEN OR ORIGIN OVERLOAD POKE PRINT PRIVATE RANDOMIZE READ REM RETURN SAVE SCREEN SHARED STATIC STEP STRING SUB SWAP SYS TEXTAT THEN THIS TO TYPE UNTIL WAIT WHILE WORD WRITE XOR

Note

In XC=BASIC (unlike CBM BASIC) you must separate keywords from each other or from other identifiers with at least one space. This will not impose any speed or size penalty on the compiled program.

Identifiers

Identifiers are used to name constants, variables, labels, subs and functions in XC=BASIC. You may choose identifiers as you wish, following these rules:

  1. The first character must be alphabetic or an underscore (_) character
  2. The remaining characters must be alphabetic, numeric, or the underscore (_) character
  3. The $ sign may suffix the identifer, however it doesn't automatically mean that the identifier refers to a string.
  4. Either upper or lower case alphabetic characters may be used. Both are considered equivalent. Therefore XYZ and xyz are considered the same identifier.
  5. An identifer may not duplicate one of the reserved keywords in the basic vocabulary above.

Identifiers can be of any length. Unlike CBM BASIC, where only the first two characters are significant, in XC=BASIC all characters are significant. The length of your identifers will not affect the size of the compiled program. For this reason, you are advised to use descriptive identifiers that are easy to read.

Statements

Statements can be separated using the colon (:) character. The separator is not required if there's only one statement on a line. The following two code pieces will be compiled to the same exact executable.

FOR i AS INT = 1 TO 5 : PRINT i : NEXT

FOR i AS INT = 1 TO 5
  PRINT i
NEXT

Comments

Anything after a single quote (') character, up until the end of the line is ignored during compilation.

x = 5 ' Assigning the value 5 to the variable x

The REM statement also serves to add comments. However, it must be separated from other statements using the colon (:) character if it is on the same line. Anything following the REM keyword up until the end of the line is ignored.

REM This is a comment
PRINT x : REM Outputting the value of x

Whitespace

Whitespace (e.g. spaces and tabs) are required between identifiers and keywords to avoid confusion. You are encouraged to use indentation to make the program more readable:

FOR i AS INT = 0 TO 10
  FOR j AS INT = 0 TO 10
    PRINT "row ", i, "column ", j
  NEXT j
NEXT i

Labels and Line Numbers

Labels can be used to mark points in your code and are referenced by GOTO and GOSUB statements. Labels must be appended with a colon (:).

GOSUB intro
END

intro:
PRINT "welcome to my program"  
RETURN

In later sections of this tutorial you will learn more about labels and how they can be useful in your program.

In addition to labels, you can use line numbers as well. Line numbers will be treated like labels by XC=BASIC. However, the following conditions apply:

  • Line numbers do not have to be consecutive
  • The colon (:) character must not be appended to line numbers
  • Labels, line numbers or unnumbered/unlabeled lines can be mixed in the program