Skip to main content

Basic syntax

A Hybrix program is a collection of named files which contain the source code. The source code is generally written in all capital letters.

Tokens

Hybrix syntax is made of tokens such as TYPE or [ or 1234 which are separated by whitespace such as spaces, tabs, and newlines. There are five kinds of tokens:

  • Identifiers: A word made of letters, numbers, and underscore (_), but not starting with a number. Identifiers are mainly used for naming definitions in your program. Example: THE_9_MOONS

  • Keywords: They look like identifiers, but are special system words reserved by the language. The Hybrix keywords are:

    AND, AS, AT, BASE, BREAK, CHOMBIT, CLASS, CLASS_ID, DATA, DO, DROP, ELSE, ELSIF, END, EXTENDS, FALSE, FUNC, HOOK, INTRINSIC, IF, IS, INSET, LIFT, LINK, LOCATED, LOOP, MODULE, NEW, NULL, NOT, OR, RETURN, SELF, THEN, TRUE, TO_ADDRESS, TO_BYTE, TO_INT, TO_PAIR, TYPE, and, VAR.

  • Labels: They look like an identifier but start with @, for example @NAME. Labels are used to refer to parts of data objects.

  • Literals: They can be decimal integers like 1234, hexadecimal integers like $12AB_34DE, or quoted strings like "HELLO, WORLD!".

  • Operators: They are used to form expressions and other punctuation. The Hybrix operators are: *, /, //, +, -, &, %, %%, :, ::, ,, ., ^, <, <=, =, >, >=, <>, [, ], (, ), and also the special arrow assignment operator ---> or <--- which can face either direction and have any number of - characters.

    Unlike all the other kinds of tokens, operators generally do not need to be separated by spaces. For example, you can write 2+2->X instead of 2 + 2 -> X. Your code will be more readable if you add spaces around operators, though.

Code comments

The # character is used to make a code comment, which is a note for human readers. The compiler ignores the # character and everything after it until the end of the line. For example:

# THESE FIRST TWO LINES ARE COMMENTS.  THE THIRD LINE IS
# PROGRAM CODE DEFINING "STRING" TO BE AN ARRAY OF BYTES.
TYPE STRING IS BYTE[]

# AND THIS NEXT LINE DEFINES "AGE" TO BE AN INTEGER.
TYPE AGE IS INT # HERE IS A COMMENT TO THE RIGHT

Whitespace

When you separate tokens with spaces or tabs, the amount of space or indentation generally does not affect the meaning. (In other programming languages such as Python, indentation does affect the meaning.)

Newlines do matter, however. For example, we must NOT write this:

# THE COMPILER REPORTS AN ERROR: "EXPECTING "IS" HERE"
TYPE AGE

IS INT

The error occurs because TYPE AGE IS INT is a single definition and so must appear all on single line. We cannot add a new line between AGE and IS.

Splitting lines

What if you have a really long line? Consider the example below:

MODULE M
FUNC A_VERY_LONG_FUNC_NAME(ONE: INT, TWO: INT, THREE: INT): INT

VAR VALUE: INT
ONE + TWO + THREE + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 --> VALUE

RETURN VALUE
END FUNC
END MODULE

We can improve readability by splitting the FUNC and --> lines across multiple lines. This is done by adding a | prefix, which continues the previous line. It can also enable us to use # to document individual parts of the line. The code below is equivalent to the code above:

MODULE M
FUNC A_VERY_LONG_FUNC_NAME(
| ONE: INT, # FIRST PARAMETER
| TWO: INT, # SECOND PARAMETER
| THREE: INT # THIRD PARAMETER
|): INT

VAR VALUE: INT
ONE + TWO + THREE + 4 + 5
| + 6 + 7 + 8 + 9 + 10
| + 11 + 12 + 13 + 14
| + 15 --> VALUE

RETURN VALUE
END FUNC
END MODULE