Reference Manual
manual://syntax

Syntax

bunnyBASIC has a small, strict syntax. The biggest difference from classic BASIC is that the implemented language is expression-driven and type-aware instead of relying on lots of special-case statements.

Program structure

Programs are line-numbered:

10 PRINT "first"
20 PRINT "second"
30 PRINT "third"

The editor can manage those numbered lines for you, but the runtime model is still line-based. You can also pop open the full editor with the ~ key for a quake-console-style editing pass.

Comments

Comments begin with ' and run to the end of the line:

10 PRINT "hello" ' inline comment
20 $VALUE = 42     ' another comment

Names and casing

  • Variables always start with $
  • Variable names must start with a letter
  • Variables and function names are case-insensitive in practice
  • Function names do not use $
10 $COUNT = 10
20 PRINT $count
30 PRINT DOUBLE($COUNT)
40 FUNCTION DOUBLE($N)
50   RETURN $N + $N
60 END FUNCTION

Value types

The runtime currently works with these value kinds:

Type Example Notes
INTEGER 42, -7 Whole numbers
DECIMAL 3.14, -0.5 Decimals are explicit, not automatic
STRING "bunny" Double-quoted
BOOLEAN TRUE, FALSE Used in conditions
ARRAY [1, 2, 3] Typed by contents
VECTOR2 <10.0, 20.0> Both components must evaluate to decimals
SHAPE RECT(), CIRCLE() Used with DRAW
VOID VOID Mostly useful for advanced expression work

Strings

Strings use double quotes. Escape a quote with \" if needed.

10 $GREETING = "hello"
20 PRINT $GREETING, "world"

Numbers and conversions

bunnyBASIC does not freely mix integers and decimals. If an operation expects decimals, give it decimals.

10 $COUNT = 12
20 $SCALE = DECIMAL($COUNT) / 2.0
30 PRINT $SCALE

Use:

  • DECIMAL($INTEGER_VALUE) to convert integer to decimal
  • INT($DECIMAL_VALUE) to convert decimal to integer

Operators

Arithmetic

Supported numeric operators:

  • +
  • -
  • *
  • /
  • MOD
10 $A = 8
20 $B = 3
30 PRINT $A + $B, $A - $B, $A * $B, $A / $B, $A MOD $B

Comparison

Documented comparison operators are:

  • =
  • <
  • <=
  • >
  • >=

Comparisons require matching types. 1 and 1.0 are different types, so convert explicitly when needed.

For "not equal", prefer:

10 IF NOT ($A = $B)
20   PRINT "different"
30 END IF

Boolean logic

  • AND
  • OR
  • NOT
10 $READY = TRUE
20 $ARMED = FALSE
30 IF $READY AND NOT $ARMED
40   PRINT "go"
50 END IF

Special mixed-type behavior

Some combinations have custom meanings:

  • STRING + STRING concatenates
  • STRING * INTEGER repeats the string
  • SHAPE + SHAPE unions shapes
  • SHAPE - SHAPE subtracts shapes
  • VECTOR2 + SHAPE translates a shape
  • DECIMAL * SHAPE scales a shape uniformly
  • VECTOR2 * SHAPE scales a shape independently in x and y
  • SHAPE ^ DECIMAL rotates a shape

Examples:

10 PRINT "ha" * 3
20 $SHIP = <256.0, 256.0> + (48.0 * RECT())
30 DRAW $SHIP

Arrays

Arrays are literal-first and zero-based.

10 $NUMS = [1, 2, 3]
20 PRINT $NUMS[0]
30 $NUMS[] = 4
40 $NUMS() = 0
50 PRINT LEN($NUMS)

Array forms:

  • [1, 2, 3] create an array
  • $A[0] read an element
  • $A[0] = 99 overwrite an element
  • $A[] = 99 push to the end
  • $A() = 99 insert at the front
  • $A[] pop from the end as an expression
  • $A() shift from the front as an expression

Current array limitation:

  • arrays can hold INTEGER, DECIMAL, STRING, and SHAPE

Vectors and shapes

Vectors are written as <x, y> and are meant for decimal-valued coordinates:

10 $POS = <128.0, 96.0>

Shapes are expression values returned by built-ins:

10 $RECT = RECT()
20 $CIRCLE = CIRCLE()

Shapes become useful once transformed:

10 $BAR = <256.0, 256.0> + ((<200.0, 24.0> * RECT()) ^ DEG(20.0))
20 DRAW $BAR

Helpful rules:

  • use decimal literals like 40.0, not 40, when scaling or building vectors
  • DEG(45.0) converts degrees to the decimal angle expected by shape rotation
  • CIRCLE() the shape builder is different from CIRCLE (...) the immediate drawing statement

Blocks and scope

IF, FOR, WHILE, and FUNCTION all use explicit end markers:

10 IF $OK
20   PRINT "yes"
30 END IF

Inside a function, variables are local by default. Use GLOBALS (...) when the function should read or write top-level variables:

10 $COUNT = 0
20 CALL BUMP()
30 PRINT $COUNT
40 FUNCTION BUMP() GLOBALS ($COUNT)
50   $COUNT = $COUNT + 1
60 END FUNCTION

Current practical notes

These docs intentionally describe the stable, implemented surface. If you do not see a construct documented here, treat it as unsupported for now.

That is especially important if you are expecting classic BASIC features or syntax from another dialect.