Alf may be used as a scripting language to write simple expressions without the need to compile the script. Scripts can be used in the body of Opaque Actions, Opaque Behaviors, Opaque Expressions, State Machine Guards, or even directly in the Simulation Console.
Simple Alf scripts used in State Machine diagram
Using Alf as a scripting language
Alf-Library must be loaded into the project to use as a scripting language.
To load the Alf-Library
- In the modeling tool main menu, click Tools and select Alf > Load Library.
In the script editor window, the language must be set to "Alf Script". The scripting window has an automatic syntax and constraint check, the same as the Alf editor window.
Alf scripts do not support the interpretation of all Alf language expressions. Currently supported expressions are:
- Literal expressions
- Name expressions
- "this" expressions
- Parenthesized expressions
- Property access expressions (dot notation, e.g., "expr.feature")
- Instance creation expressions for objects (Constructorless, using the class name, e.g., "new C()")
- Class extent expressions ("C.allInstances()")
- Sequence construction expressions (e.g., "Integer[]{1,2,3}")
- Sequence access expression (e.g., "a[i]")
- Boolean unary expressions ("!")
- BitString unary expressions ("~")
- Numeric unary expressions ("+", "-")
- Cast expressions
- Isolation expressions (but with no isolation semantics)
- Arithmetic Expressions ("*", "/", "%", "+", "-")
- Shift Expressions ("<<", ">>", ">>>")
- Relational Expressions ("<", ">", "<=", ">=")
- Classification Expressions ("instanceof", "hastype")
- Equality Expressions ("=", "!=")
- Logical Expressions ("&", "^", "|")
- Conditional logical expressions ("&&", "||")
- Null-coalescing expressions ("??")
- Conditional test expressions ("… ? ... : … ")
- Assignment expressions
- Increment and decrement expressions ("++", "--")