General Syntax Reference of he SARL Language
SARL is designed to facilitate the creation of agent-based systems. It combines agent-specific constructs with several functional, imperative and object-oriented principles, providing a robust framework for developing autonomous and interactive agents. Below is an overview of the core features of SARL.
1. Basic Language Constructs
1.1. Structure of SARL Scripts
- Script: SARL scripts are the basic units of execution, containing a series of types, statements and expressions.
- Naming Convention: SARL has specific rules and conventions for naming variables, functions, and other constructs.
- Statements: Statements in SARL are used to perform actions, including variable declarations, control flow, and more.
- Block Documentation: Blocks in SARL define scopes for variables and control structures.
1.2. Variables and Types
- Variable Declarations: SARL supports various ways to declare variables, including type inference and explicit typing.
- Types: SARL provides a rich type system, including primitive types, custom types, and collections.
- Cast Operator: SARL supports type casting, allowing for explicit conversion between types.
1.3. Literals and Operators
- Literals: These are fixed values that can be directly used in code, such as numbers, strings, and booleans.
- Operators: SARL supports a wide range of operators for arithmetic, logical, and relational operations.
1.4. Feature Access
- Member Access: This feature allows access to the members (fields and methods) of objects and classes.
- Java Interoperability: SARL is designed to interoperate seamlessly with Java, allowing for the integration of Java libraries and frameworks.
2. Control Flow
2.1. Conditional Statements
- If Expression: Conditional logic in SARL is handled through
if
expressions, allowing for branching execution paths.
- Switch Expression: Switch expressions provide a concise way to handle multiple conditional branches.
2.2. Loops
- Loop Expressions: SARL supports various loop constructs for iterative execution, including for, while, and do-while loops.
3. Functions and Lambda Expressions
3.1. Function Declarations
3.2. Lambda Expressions
- Lambda: Lambdas provide a concise way to define anonymous functions, facilitating functional programming patterns.
4. Advanced Features
4.1. Error Handling and Code Quality Improvement
- Exceptions: SARL includes mechanisms for handling exceptions, allowing for robust error management.
- Assertions: Assertions are used to validate assumptions within the code, aiding in debugging and testing.
4.2. Synchronization of Resources
- Synchronization: SARL provides constructs for synchronizing access to shared resources, ensuring parallel execution (thread) safety.
- Extension Methods: SARL supports extension methods to enhance the functionality of types.
- Active Annotations: Annotations in SARL can be used to add metadata and influence the behavior of agents.
- Synthetic Functions: These are automatically generated functions that facilitate common patterns and reduce boilerplate code.
5. References
This documentation is based on documentations from the Xtext and Xtend projects, and from the Java tutorials.
Thank you to the contributors to these documents.
6. Version Specification
- Specification: SARL General-purpose Agent-Oriented Programming Language (“Specification”)
- Version: 0.15
- Status: Stable Release
- Release: 2025-09-11
7. Legal Notice
Copyright © 2014-2025 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0;
you may not use this file except in compliance with CC-BY-SA-4.0.
You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0;
you may not use this file except in compliance with the Apache License.
You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.15.1.