Condition/Action language

The statements in conditions and actions must follow general JavaScript (JS) rules. Conditions, like used in JavaScript conditional statements, must evaluate to some truth value. Expressions typically evaluate some variable(s) or call a method.

Conditions and actions are parsed before program synthesis to extract the variable names that must be passed to the JS engine before executing the program and reading from it after the execution. JS keywords are not to be used. In the following we describe in more detail the restrictions and extensions available in the current implementation.

Conditions

Conditions are to be presented as JS comparisons (expressions). An expression is a formula or a mix of formulas and method calls that computes/returns a single value.

The following operators are supported: <, >, ==, !=, <=, >=, +, -, *, /, %, ||, &&, !, &, |, ~, ^, <<, >>.

Typical conditions look as follows:


i < limit

gateIsOpen

(a + b > c / d) && a < d

See Language description in BNF for more detailed description.

Actions

Actions are to be presented as JS programs (sequence of JS statements, separated by a semicolon). A typical statement is an evaluation: x = expression;, where x is a variable that is evaluated with the result of the expression. In addition to the standard evaluation with the operator "=" the following evaluating statements are allowed:


x++;
x--;
x += expression;
x -= expression;
x *= expression;
x /= expression;
x %= expression;
[x,y]=[Model |- in1, in2 -> out1, out2](arg1,arg2);

The latter is called an (independent) subtask and represents a method to be synthesised by CoCoViLa. The method computes out1 and out2 from given in1 and in2 on a Model. The Model could be a CoCoViLa visual class or scheme. When called, the arg1 and arg2 are passed to the method as in1 and in2. The values of out1 and out2 are assigned to x and y. When a subtask is used as an expression, only the first output is passed on.

See Language description in BNF for more detailed description

Language description in BNF

The following is the description of the language used in conditions and actions in BNF.

<condition> ::= <expression> <action> ::= <program> <arithmetic-op> ::= "+" | "-" | "*" | "/" | "%" <binary-op> :== <arithmetic-op> | <logic-op> | <comparison-op> <comparison-op> ::= "==" | "!=" | "<" | ">" | "<=" | ">=" <eval-op> ::= "=" | "+=" | "-=" | "*=" | "/=" | "%=" <evaluation> ::= <name> <eval-op> <expression> <expression> ::= <name> | <value> | <expression> <binary-op> <expression> | "(" <expression> ")" | <subtask-expression> <expression-list> ::= <expression> | <expression> "," <expression-list> <logic-op> ::= "||" | "&&" | "!" | "&" | "|" | "~" | "^" | "<<" | ">>" <method-call> ::= <name> "(" <expression-list> ")" <name> ::= <alpha-num> | <name> "[" <expression> "]" | <name> "." <name> <name-list> ::= <name> | <name> "," <name-list> <program> ::= <statement> | <statement> ";" <program> <statement> ::= <evaluation> | <unary-evaluation> | <method-call> | <subtask-evaluation> <subtask-evaluation> ::= "[" <name-list> "]" "=" <subtask-expression> <subtask-expression> ::= "[" <alpha-num> "|-" <name-list> "->" <name-list> "]" "(" <expression-list> ")" <unary-evaluation> ::= <name> "+" "+" | <name> "-" "-" <value> ::= <number> | '"' <text> '"' <alpha-num> - sequence of letters and numbers that starts with a letter <number> - a number in the form JS accepts it <text> - any sequence of characters

Next: Hands-on