Comments

Single Line Comment

Comment
// comment text

Comments that extend to the end of the line.

Examples:

// This is a comment
let x = 5; // inline comment

Heritage: C++ style single-line comments.

Multi-line Comment

Comment
/* comment text */

Comments that can span multiple lines.

Examples:

/* This is a
   multi-line comment */

Heritage: C-style block comments for longer documentation.

Documentation Comment

Comment
/// documentation text

Special comments for generating documentation.

Examples:

/// Calculates the sum of two numbers
/// Returns: The sum as an integer

Heritage: Documentation comments from Rust and modern documentation tools.

Control Flow

If Expression

Control_structure
if condition {
    // if block
} else {
    // else block
}

Conditional execution based on boolean expressions. In Cyl, if is an expression that returns a value.

Examples:

if x > 0 {
    print("positive");
}
let result = if condition { value1 } else { value2 };

Heritage: If expressions from functional languages combined with C-style syntax.

While Loop

Control_structure
while condition {
    // statements
}

Repeatedly executes the loop body while the condition remains true. Supports variable assignment and complex conditions.

Examples:

while i < 10 {
    print_int(i);
    i = i + 1;
}
while continue_loop {
    process_data();
    continue_loop = check_condition();
}

Heritage: Standard while loop construct from imperative programming languages with C-style syntax.

For Loop

Control_structure
for item in iterable {
    // loop body
}

Iterates over collections or ranges with automatic iteration variable binding.

Examples:

for i in 0..10 {
    print(i);
}
for item in array {
    process(item);
}

Heritage: For-in loops from Python and modern languages with range syntax from Rust.

Match Expression

Control_structure
match value {
    pattern => result,
    _ => default
}

Pattern matching with exhaustive case analysis, similar to switch statements but more powerful.

Examples:

match status {
    "ok" => process(),
    "error" => handle_error(),
    _ => unknown()
}

Heritage: Pattern matching from functional languages like ML and Rust.

Declarations

Variable Declaration

Declaration
let variable_name: type = value;

Declares a new variable with an explicit type and initial value. Variables in Cyl are immutable by default.

Examples:

let count: i32 = 42;
let name: string = "Hello";
let is_active: bool = true;

Heritage: Inspired by Rust's let bindings with mandatory type annotations for clarity.

Mutable Variable Declaration

Declaration
let mut variable_name: type = value;

Declares a mutable variable that can be reassigned after initialization.

Examples:

let mut counter: i32 = 0;
let mut buffer: string = "";

Heritage: Follows Rust's explicit mutability model for memory safety.

Function Declaration

Declaration
fn function_name(param: type) -> return_type {
    // function body
}

Defines a function with parameters and return type. Functions are first-class values in Cyl.

Examples:

fn add(a: i32, b: i32) -> i32 {
    return a + b;
}
fn greet(name: string) -> string {
    return "Hello, " + name;
}

Heritage: Function syntax borrowed from Rust with influences from modern functional languages.

Constant Declaration

Declaration
const CONSTANT_NAME: type = value;

Declares a compile-time constant that cannot be changed.

Examples:

const PI: f64 = 3.14159;
const MAX_SIZE: i32 = 1000;

Heritage: Constant declaration pattern from Rust and C++ traditions.

Expressions

Arithmetic Expression

Expression
operand operator operand

Mathematical operations with standard operator precedence.

Examples:

5 + 3
x * y - z
(a + b) / 2

Heritage: Standard arithmetic operators with C-style precedence rules.

Function Call Expression

Expression
function_name(arg1, arg2, ...)

Calls a function with the provided arguments and evaluates to the return value.

Examples:

add(5, 3)
print("Hello")
max(a, b, c)

Heritage: Function call syntax from C-family languages.

Literal Expression

Expression
literal_value

Direct representation of values like numbers, strings, and booleans.

Examples:

42
"Hello, World!"
true
3.14

Heritage: Standard literal syntax across programming languages.

Variable Expression

Expression
variable_name

References the value stored in a variable.

Examples:

counter
user_name
is_ready

Heritage: Simple variable reference from all major programming languages.

Operators

Arithmetic Operators

Operator
+, -, *, /, %

Basic arithmetic operations: addition, subtraction, multiplication, division, and modulo.

Examples:

5 + 3
10 - 4
6 * 7
15 / 3
17 % 5

Heritage: Standard arithmetic operators from mathematical notation and C.

Comparison Operators

Operator
==, !=, <, >, <=, >=

Operators for comparing values and producing boolean results.

Examples:

x == y
a != b
count < 10
score >= 90

Heritage: Comparison operators from C with logical mathematical symbols.

Logical Operators

Operator
&&, ||, !

Boolean logic operators for combining and negating boolean expressions.

Examples:

x && y
a || b
!condition

Heritage: Logical operators from C-family languages.

Parser Internals

Statement

Parser_rule
// Parsed by parse_statement()

Internal parser rule for statement.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Declare

Parser_rule
// Parsed by parse_declare()

Internal parser rule for declare.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Return

Parser_rule
// Parsed by parse_return()

Internal parser rule for return.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

If

Parser_rule
// Parsed by parse_if()

Internal parser rule for if.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

While

Parser_rule
// Parsed by parse_while()

Internal parser rule for while.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

For

Parser_rule
// Parsed by parse_for()

Internal parser rule for for.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Match

Parser_rule
// Parsed by parse_match()

Internal parser rule for match.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Pattern

Parser_rule
// Parsed by parse_pattern()

Internal parser rule for pattern.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Try

Parser_rule
// Parsed by parse_try()

Internal parser rule for try.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Import

Parser_rule
// Parsed by parse_import()

Internal parser rule for import.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Expression

Parser_rule
// Parsed by parse_expression()

Internal parser rule for expression.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Expression Stop At Left Brace

Parser_rule
// Parsed by parse_expression_stop_at_left_brace()

Internal parser rule for expression stop at left brace.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Expression Internal

Parser_rule
// Parsed by parse_expression_internal()

Internal parser rule for expression internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Assignment Internal

Parser_rule
// Parsed by parse_assignment_internal()

Internal parser rule for assignment internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Logical Or Internal

Parser_rule
// Parsed by parse_logical_or_internal()

Internal parser rule for logical or internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Logical And Internal

Parser_rule
// Parsed by parse_logical_and_internal()

Internal parser rule for logical and internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Equality Internal

Parser_rule
// Parsed by parse_equality_internal()

Internal parser rule for equality internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Comparison Internal

Parser_rule
// Parsed by parse_comparison_internal()

Internal parser rule for comparison internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Term Internal

Parser_rule
// Parsed by parse_term_internal()

Internal parser rule for term internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Factor Internal

Parser_rule
// Parsed by parse_factor_internal()

Internal parser rule for factor internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Unary Internal

Parser_rule
// Parsed by parse_unary_internal()

Internal parser rule for unary internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Postfix Internal

Parser_rule
// Parsed by parse_postfix_internal()

Internal parser rule for postfix internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Primary Internal

Parser_rule
// Parsed by parse_primary_internal()

Internal parser rule for primary internal.

Examples:

// Implementation specific

Heritage: Internal compiler parsing logic.

Statements

Expression Statement

Statement
expression;

Any expression followed by a semicolon becomes a statement that discards its value.

Examples:

print("Hello");
calculate_result();
5 + 3;

Heritage: Statement-expression distinction from C-family languages.

Assignment Statement

Statement
variable = expression;

Assigns a new value to a mutable variable.

Examples:

counter = counter + 1;
name = "New Name";

Heritage: Traditional assignment semantics with mutation restrictions.

Return Statement

Statement
return expression;

Returns a value from a function and exits the function immediately.

Examples:

return 42;
return calculate_sum(a, b);

Heritage: Standard return statement from imperative programming languages.

Block Statement

Statement
{
    // statements
}

Groups multiple statements together and creates a new scope.

Examples:

{
    let x = 5;
    print(x);
}

Heritage: Block scoping from C-family languages with Rust-like scope rules.

Types

Integer Types

Primitive_type
i8, i16, i32, i64, u8, u16, u32, u64

Signed (i) and unsigned (u) integer types with explicit bit sizes.

Examples:

let small: i8 = 127;
let big: u64 = 18446744073709551615;

Heritage: Explicit integer sizing from Rust for predictable memory usage.

Floating Point Types

Primitive_type
f32, f64

IEEE 754 floating point numbers with 32-bit and 64-bit precision.

Examples:

let pi: f64 = 3.14159;
let ratio: f32 = 0.5;

Heritage: Standard floating point types from systems programming languages.

Boolean Type

Primitive_type
bool

Boolean type with true and false values.

Examples:

let is_ready: bool = true;
let finished: bool = false;

Heritage: Standard boolean type from most modern programming languages.

String Type

Primitive_type
string

UTF-8 encoded string type for text data.

Examples:

let message: string = "Hello, World!";

Heritage: String handling influenced by modern languages with UTF-8 by default.

Plugin System
Extending Cyl: You can add new syntax, types, and functions using Python or Rust plugins. Just place your plugin in the plugins/ directory and the compiler will auto-load it at runtime.
Python Plugin Example:
class LanguagePlugin:
    # ... implement plugin methods ...