This article is an introduction to the Cyrus Programming Language. It assumes you already have a basic understanding of programming concepts such as variables, statements, and types. Here, you’ll see how familiar ideas are expressed in Cyrus, while also being introduced to new concepts that make the language unique.
If you haven't installed Cyrus yet, start with the Getting Started guide before continuing.
Comments are pieces of text ignored by the compiler. They're useful for explaining code, leaving notes, or temporarily disabling parts of a program. Cyrus supports both single-line and multi-line comments.
// This is a single-line comment
#msg: char* = "Hello, Cyrus!"; // You can also place it after code
/*
Outer comment start
/* Nested comment inside */
Outer comment end
NOTE: Multi-line comments can also be nested!
*/
String literals in Cyrus are enclosed in double quotes "xxx", while character literals are enclosed in single quotes 'x'. Both forms represent sequences of Unicode characters, but they differ in intent and usage:
#greeting: char* = "Hello, Cyrus!";
#letter: char = 'A';
Special characters that are difficult to type directly or would otherwise break the syntax can be written using escape sequences. All escape sequences begin with a backslash ().
Common escapes include:
Example:
#poem: char* = "Line one\nLine two\nLine three";
#quote: char* = "She said: \"Cyrus is great!\"";
#backslash: char = '\\';
#paragraph: char* = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
Cyrus supports Unicode characters directly in string and character literals. You can type emojis, accented letters, or any other Unicode characters inside quotes:
#letter: char = 'A'; // ✅ Works
#smile: char* = "😇"; // ✅ Works in a string
#rocket: string = "Let's go! \u{1F680}"; // ✅ Works, 🚀
#greek_alpha: char* = "\u03B1"; // ✅ Works, α
#emoji_char: char = '😇'; // ❌ Does NOT work
#multibyte_char: char = '\u263A'; // ❌ Does NOT work
Numeric constants in Cyrus can be written in decimal, hexadecimal, octal, or binary formats:
#a = 1234;
#b = 0x42EDAA02;
#b = 0x42EDAA02;
Numeric literals may include underscores _ between digits for readability; these are ignored by the compiler:
#million = 1_000_000;
#hex_val = 0xDE_AD_BE_EF;
Cyrus allows explicit type suffixes on numeric literals to specify their type. This is useful when the compiler cannot infer the type or when you want to guarantee a specific type.
Valid integer suffixes include:
Valid float suffixes include:
Example:
#a = 1234int64;
#b = 3.14float64;
If you don't specify a type suffix, Cyrus assigns int as the default type for integer literals, and float64 as the default type for floating-point literals.
Type suffixes can be used to explicitly control the size and signedness of an integer literal, or to select a different floating-point precision.
Arrays in Cyrus are fixed-size sequences of elements. Their size must be known at compile time, similar to C arrays.
#name = Type[capacity]{element1, element2, ..., elementN};
Example:
#a = int[3]{1, 2, 3};
#b = const float64[4]{3.14, 2.71, 1.618, 0.577};
printf("%d\n", a[0]);
Pointers in Cyrus behave like C pointers. They store the memory address of another variable.
#ptr: Type* = &variable;
Example:
#a: int = 10;
#b: int* = &a;
printf("%d\n", *b); // prints 10
Pointer arithmetic behaves like C (e.g., incrementing a pointer moves it by sizeof(Type) bytes).
Coming soon...