This website is under construction.
An expression is formed from primary expressions by applying operators. Each expression has a type and evaluates to a value of the type when executed.
A primary expression can be either a literal value, or an identifier of the following
a constant,
a variable of the agent,
a visible state variable of another agent,
an agent parameter,
an action parameter.
When an identifier is modified by an agent name (i.e. an identifier of an agent type) in the form of AgentName # Variable, it refers to the visible state variable of that agent.
PrimaryExpression ::=
(Literal | Identifier | StateExpression | "(" Expression ")" )
{ ElemenetExpression }
StateExpression ::= AgentName "#" Identifier
The identifier in a primary expression can be followed by an ElementExpression to obtain the element or feature of the data that it refers to, or to convert the value to a different data type.
When the type of a primary expression is a structured data type, a primary expression can be followed by an ElementExpression to obtain the element or feature of the data that it refers to, or to convert the value to a different data type. An element selection expression can be in one of the following forms.
[expr] to select the element of a list, where expr is an integer type expression and its value is the index of the element in the list.
.FieldName to select a field of a record.
.length to get the number of elements in a list or the length of a string value.
.has_field(FieldName) to test if the field in the record is defined or not.
.is_defined to test if the value of the expression is defined.
.to_string to convert the data into a string.
.to_real to convert a string or integer data into a real number data.
.to_int to convert a string into an integer data.
.value_of(TypeName) to convert a string value into a value of the type.
.starts_with(exp) to test if the string value starts with the string of the exp.
.ends_with(exp) to test if the string value ends with the string of the exp.
.contains(exp) to test if the string value contains the string of the exp.
The syntax of ElementExpression in EBNF follows.
ElementExpression ::=
{ "[" AdditiveExpression "]"
| "." FieldName
| "." ⟨LENGTH⟩
| "." ⟨HAS_FIELD⟩"(" FieldName ")"
| "." ⟨IS_DEFINED⟩
| "." ⟨TO_REAL⟩
| "." ⟨TO_STRING⟩
| "." ⟨TO_INT⟩
| "." ⟨VALUE_OF⟩"(" TypeName ")"
| "." ⟨STARTS_WITH⟩"(" Expression ")"
| "." ⟨ENDS_WITH⟩"(" Expression ")"
| "." ⟨CONTAINS⟩"(" Expression ")"
| "." ⟨REPLACE⟩"(" Expression "," Expression ")"
| "." ⟨ADD_ELEMENT⟩"(" Expression ")"
| "." ⟨REMOVE_ELEMENT⟩"(" Expression ")" }
Operators have different execution priorities when they are applied to form expressions. This is reflected in the syntax definition of expressions.
Expression ::= ConditionalOrExpression
ConditionalOrExpression ::=
ConditionalAndExpression { "||" ConditionalAndExpression } ConditionalAndExpression ::=
EqualityExpression { "&&" EqualityExpression }
EqualityExpression ::=
RelationalExpression [ ("==" | "!=" ) RelationalExpression ] RelationalExpression ::=
AdditiveExpression [ ("<" | ">" | "<=" | ">=" ) AdditiveExpression ]
AdditiveExpression ::=
MultiplicativeExpression { ("+" | "-" ) MultiplicativeExpression }
MultiplicativeExpression ::=
UnaryExpression { ("*" | "/" | "%" ) UnaryExpression }
UnaryExpression ::= "!" UnaryExpression | PrimaryExpression
The types of operants in an expression must be compatible with the type of the operator although many of the operators are overloaded. Table 6.1 list the types of the operators, where T represents any given type.
The postfix operators ".to_string" , ".to_real" , ".to_int" and ".value_of(T)" are type conversion operators. They convert a value of one data type into another.
Table 6.1. Type Constraints on Operators