Rhea is a simple, type safe, partially type inferred, garbage collected programming language which compiles to C.
Rhea’s grammar is defined in ANTLR v4 EBNF, and the compiler is implemented in C#.
Line comments start with
# and end at the end of the line:
Identifiers begin with a letter and may contain letters, numbers, and underscores.
Rhea uses curly braces to define blocks. You can use a block anywhere a statement is allowed, like in control flow statements. Function bodies are also blocks.
Precedence and Associativity
||Multiply, Divide, Modulo||Left|
||Equal, Not Equal||Left|
A boolean value represents truth or falsehood. There are two boolean literals,
Rhea has eight integer types. Four signed:
int64, and four unsigned:
There are two floating point types:
Strings have a type of
string and are always allocated on the heap.
Strings are technically structs. The Rhea standard library provides a number of methods to make working with strings easier.
string#dup() -> string
Duplicates a string.
string#trim() -> string
Trims leading and trailing whitespace from a string.
string#length() -> int64
Returns the length of a string.
Function are declared using the
This creates a new function which accepts a 32-bit integer as an argument and returns a 64-bit integer.
There is no need to declare functions before calling them.
Variables are declared using the
This creates a new string,
name, in the current scope.
Variables can also be initialized when they’re created. In this case, their type can be inferred:
Methods are special functions which take a struct as an argument.
Calling C from Rhea