Syntax

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

Each line may contain a label, a statement, or both:

label1: print "hello world"
label2:
print "hello again"

Whitespace

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

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

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

Includes

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

Comments

The only way to add comments is the REM statement.

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}

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.

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.

Example:

print 'a' + 1
rem -- will output: 66
print '{white}'
rem -- will output: 5
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies

Discussion

Marcelo Cabral, 2019/07/05 17:44

Very nice work!

I have a couple of suggestions:

  1. Make a way (switch) to disable globally the case sensitive mode for identifiers, most BASIC flavors are case insensitive.
  1. Please make single quotes or semi-colon an alternative for REM
Csaba Fekete, 2019/07/05 21:08

Thanks for your feed back!

To make identifiers optionally case-insensitive is a good idea, I'll consider implementing it in v2.1.

As for the comments syntax, single quotes are reserved for character literals, which will come in a future version, but maybe the semicolon could be used for this purpose. I'll consider for v2.1 as well.

Csaba Fekete, 2019/07/08 12:30

From version 2.1 you can use

PRAGMA civars = 1

to make variable names case insensitive.

Enter your comment. Wiki syntax is allowed:
O Q A​ Y T