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" label2: 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:" loop: print t1, " " let nx = t1 + t2 let t1 = t2 let t2 = nx if nx < max then goto loop end
Whitespace is not required between keywords and identifiers, though it's recommended for readability. The following is a valid statement:
forindex=0to255
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.
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:
a A _myVar myVar2
The following are not valid identifiers:
remark 2pac letter
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
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}
Example:
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.
Since version 1.2, a character enclosed in single quotes (') evaluates to its PETSCII code. Escape sequences are supported in character literals as well.
Example:
print 'a' + 1 rem -- will output: 66 print '{white}' rem -- will output: 5