You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.


An XC=BASIC program is built from one or more plain ASCII text files that consist of lines, allowing one or more statements per line.

Each line may optionally contain a label and zero or more statements separated by a colon (:):

label1: print "hello world"
print "hello again"
let x = 5 : print x : rem "these were more statements in a line"


Whitespace (tabs, spaces, empty lines) is ignored. Indentation is allowed and encouraged.

rem ** fibonacci series **
let max = 32767
let t1 = 0
let t2 = 1
print "fibonacci series:"
  print t1, " "
  let nx = t1 + t2
  let t1 = t2
  let t2 = nx
  if nx < max then goto loop

Whitespace is not required between keywords and identifiers, though it's recommended for readability. The following is a valid statement:


Multi-line statements

Line break is ignored if the last character of a line is a tilde (~) character. This can be useful in a DATA statement with a long list, for example:

data my_long_data[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ~
                      11, 12, 13, 14, 15

Note that no other character is allowed after the tilde, including whitespace.

Case sensitivity

Keywords may be written in lowercase or uppercase as well. All identifiers (variable names, procedure names, etc.) can be mixed-case and are case sensitive by default.

If the civars compiler option is turned on, variable names are treated insensitive. This only applies to variable names. Labels and other identifiers are case sensitive.


Identifiers can be of any length, may contain mixed-case alphanumeric characters and underscores, though they may not start with a number, nor with a keyword.

Valid identifiers include:


The following are not valid identifiers:



The INCLUDE directive is useful in splitting your program to several files.


The only way to add comments is the REM statement. The REM keyword however has two aliases: the semicolon (;) and the single quote (').

  rem This is a comment
  ' This is also a comment
  ; This is also a comment

String literals

Strings are enclosed in double quotes (). All characters in strings will be translated from ASCII to PETSCII (or screencodes - depending on the context).

There are several escape sequences that you can use in string literals to be able to print special PETSCII characters.

The escape sequence {num} (where num is a decimal number) will be replaced by the PETSCII code indicated by num. You can also use the following convenience escape sequences: {CLR}, {HOME}, {INSERT}, {DEL}, {CR}, {REV_ON}, {REV_OFF}, {CRSR_UP}, {CRSR_DOWN}, {CRSR_LEFT}, {CRSR_RIGHT}


print "{CLR}welcome to a fresh new screen"
print "this is line one{CR}and this is line two"
print "{5}white text"

Make sure to check the list of all PETSCII escape sequences.

Character literals

Since version 1.2, a character enclosed in single quotes (') evaluates to its PETSCII code. Escape sequences are supported in character literals as well.


print 'a' + 1
rem -- will output: 66
print '{white}'
rem -- will output: 5