aBC logo

ABC Language Reference

1. Identifiers

2. Dynamic binding

3. Keywords/Primitives

3.1 Special forms

3.2 I/O Primitives

3.3 Graphic primitives

3.4 Numeric Primitives

3.5 String Primitives

3.4 Miscellaneous Primitives

1. Identifiers

Identifiers are alphanumeric strings starting with a nonnumeric character and ending :

  • With nothing for identifiers
  • With '$' for string-identifiers
  • With '#' for boolean-identifiers

2. Lexical binding

The interpreter uses a lexical binding, i.e. free variables in functions are bound to the functions' compilation environment.

3. Keywords/Primitives

3.1 Special forms

DIM

DIM identifier ( numeric-expression ) = numeric-expression
DIM string-identifier ( numeric-expression ) = string-expression
DIM boolean-identifier ( numeric-expression ) = boolean-expression

Declares an array of the given size. The array type is determined by the expression type.

FOR ... TO ... STEP ... NEXT

FOR identifier = numeric-expression TO numeric-expression [STEP numeric-expression] instructions NEXT [identifier]

A standard for loop, using an index and optionally a step, which can be negative. If no identifier is found after the NEXT statement, it refers to the previous FOR loop.

GOTO

GOTO identifier

Jumps to the given LABEL.

IF ... THEN ... ELSE

IF boolean-expression THEN instruction [ELSE instruction]

Evaluates the boolean-expression and executes the instruction following the THEN keyword if the result is TRUE. Otherwise, it executes the instruction following the ELSE keyword if any, or jumps to the next instruction.

LABEL

LABEL identifier

Declares a LABEL, which can be accessed with a GOTO statement.

LET

LET identifier = numeric-expression
LET string-identifier = string-expression
LET boolean-identifier = boolean-expression
LET identifier ( numeric-expression ) = numeric-expression
LET string-identifier ( numeric-expression ) = string-expression
LET boolean-identifier ( numeric-expression ) = boolean-expression

Stores the rightmost expression's value into the given variable or array cell.

SUB ... ENDSUB

SUB identifier ( arguments ) instructions ENDSUB
SUB string-identifier ( arguments ) instructions ENDSUB
SUB boolean-identifier ( arguments ) instructions ENDSUB

Declares a subroutine. The return type is determined by the identifier type.

3.2 I/O Primitives

INPUT

INPUT string, identifier
INPUT string, string-identifier
INPUT string, boolean-identifier

Prompts the user for either a number, string or boolean, displaying a string. The result is then stored into the right identifier.

PRINT

PRINT print-arguments
PRINT print-arguments;

Prints the concatenation of the print-arguments, where print-arguments is a list of numeric-expressions, string-expressions, or boolean-expressions separated with commas. The string-expressions and boolean-expressions are converted to strings before they are displayed. If the PRINT instruction line ends with a semicolon, then no new line is appended at the end of the printed string.

3.3 Graphic primitives

GRAPHICS

GRAPHICS numeric-expression, numeric-expression

Initializes a graphic window of the given width (first parameter) and height (second parameter).

RESIZE

GRAPHICS numeric-expression, numeric-expression

Resizes the graphic window to the given width (first parameter) and height (second parameter).

MOVE

MOVE numeric-expression, numeric-expression

Moves the current coordinates to the given x (first parameter) and y (second parameter).

PLOT

PLOT

Draws a point at the current coordinates in the graphic window.

LINETO

LINETO numeric-expression, numeric-expression

Draws a line from the current coordinates to the given (first parameter, second parameter) coordinates, and sets the current coordinates to (first parameter, second parameter).

COLOR

COLOR numeric-expression, numeric-expression, numeric-expression
COLOR string-expression

Sets the current drawing color, using three values between 0 and 255 which represent respectively the values of RED, GREEN, BLUE, or using a string representing the color, which can be:

  • "BLACK"
  • "WHITE
  • "RED"
  • "GREEN"
  • "BLUE
  • "YELLOW"
  • "GRAY"

RECTANGLE

RECTANGLE numeric-expression, numeric-expression

Draws an empty rectangle with the given width (first parameter) and height (second parameter) at the current coordinates.

FILLEDRECTANGLE

FILLEDRECTANGLE numeric-expression, numeric-expression

Draws a filled rectangle with the given width (first parameter) and height (second parameter) at the current coordinates.

ELLIPSE

ELLIPSE numeric-expression, numeric-expression

Draws an empty ellipse with the given width (first parameter) and height (second parameter) at the current coordinates.

FILLEDELLIPSE

FILLEDELLIPSE numeric-expression, numeric-expression

Draws a filled ellipse with the given width (first parameter) and height (second parameter) at the current coordinates.

3.4 Numeric Primitives

RND

RND ( numeric-expression )

Returns a random decimal number between 0 and the given value (first parameter).

INT

INT ( numeric-expression )
INT ( string-expression )

Returns the integer value of the given expression.

EXP

EXP ( numeric-expression )

Returns the exponential of the given expression.

LOG

LOG ( numeric-expression )

Returns the logarithm of the given expression.

SIN

SIN ( numeric-expression )

Returns the sine of the given expression.

COS

COS ( numeric-expression )

Returns the cosine of the given expression.

ASIN

ASIN ( numeric-expression )

Returns the arc sine of the given expression.

ACOS

ACOS ( numeric-expression )

Returns the arc cosine of the given expression.

ABS

ABS ( numeric-expression )

Returns the absolute value of the given expression.

SQR

SQR ( numeric-expression )

Returns the squared value of the given expression.

MOD

MOD ( numeric-expression, numeric-expression )

Returns the first expression modulo the second expression.

LEN

LEN ( string-expression )

Returns the length of the given string.

3.4 String Primitives

ASC

ASC ( string-expression )

Returns the ASCII value of the first character from the given string.

LEFT$

LEFT$ ( string-expression, numeric-expression )

Returns a string containing the leftmost characters of the given string. The wanted length is the second parameter.

RIGHT$

LEFT$ ( string-expression, numeric-expression )

Returns a string containing the rightmost characters of the given string. The wanted length is the second parameter.

STR$

STR$ ( numeric-expression )
STR$ ( numeric-expression, numeric-expression )

Returns the string representation of the given number. If a second parameter is given and the return value would be shorter than this value, the string is padded with spaces to be as long as this value.

MID$

MID$ ( string-expression, numeric-expression, numeric-expression )
STR$ ( string-expression, numeric-expression )

Returns a substring of the first parameter starting at the position given by the second parameter, with a length of the optional parameter. If no third parameter is given, the substring ends at the end of the initial string.

3.5 Miscellaneous Primitives

WAIT

WAIT ( string-expression )

Waits for the given amout of time (in seconds).