Skip to the content.

Language Reference

This section provides a comprehensive reference for the Flexa programming language. It covers the syntax, rules, and features of Flexa in a concise and organized manner. Use this guide as a quick reference while writing Flexa code.


Table of Contents

  1. Program Structure
  2. Variables and Constants
  3. Data Types
  4. Operators
  5. Control Structures
  6. Functions
  7. Structs
  8. Arrays
  9. Error Handling
  10. Built-in Functions
  11. Built-in Libraries

Program Structure

A Flexa program consists of:

Example

namespace my_program;

using flx.core.console;

include namespace flx;

fun main() {
  println("Hello, Flexa!");
}

main();

Variables and Constants

Variables

var name: type = value;

Constants

const name: type = value;

Data Types

Primitive Types

Composite Types

Special Types


Operators

Value Reference Operators

Increment Operators

Ternary Operator

Arithmetic Operators

Comparison Operators

Logical Operators

Bitwise Operators

Assignment Operators


Control Structures

Conditionals

Loops

Flow Control


Functions

Function Declaration

fun name(parameter: type, ...): return_type {
  // Function body
}

Lambda Functions

var lambda: function = fun (parameter: type, ...): return_type {
  // Function body
};

Structs

Struct Declaration

struct Name {
  var field1: type;
  var field2: type;
}

Struct Instance

var instance: Name = Name{field1=value1, field2=value2};

Arrays

Array Declaration

var array[]: type = {value1, value2, ...};

Array Access

var element = array[index];

Error Handling

Try-Catch

try {
  // Code that may throw an exception
} catch (var error) {
  // Handle the exception
}

Throw

throw string_expression;
// or
throw Exception{error=string_expression};

Built-in Functions


Built-in Libraries

Flexa provides a rich set of built-in libraries for tasks like file handling, networking, and data manipulation. Some of the key libraries include:


What’s Next?

If you have questions or run into issues while using Flexa, check out the FAQ and Common Issues section for solutions and tips.


← Back to Advanced Examples Next: FAQ and Common Issues →