I’m currently working on a project involving source-to-source translation from a DSL (defined in C++) to Dezyne. I’m currently stuck at a point where the code I generate does not throw a syntax error but fail validation. Here’s the Dezyne interface below:
interface file_11799190314668254898{
out void demo_wrapper_2();
in void demo_wrapper_1();
enum State {A,B};
subint int {0..5};
behavior {
State state = State.A;
bool y = false;
int x = 0;
// this works
on demo_wrapper_1: {
[x<3] {
state = State.B;
y = true;
}
[x>=3] state = State.A;
demo_wrapper_2;
}
}
}
I’ve read in the reference that only one imperative statement is allowed per combination of guard and on statements. However, the code provided above can be verified when demo_wrapper_2 out event is removed.
The lack of braces is intentional as I’m trying to signify that the action will take place regardless of the guard statements. My confusion arises from the following: In the reference manual, under lexical analysis, it is stated that
unless i’m missing something, an on block should only accept a single declarative statement and should not accept a mix of imperative and declarative statements in a single block. In the fix you suggest, under on demo_wrapper_1:, there exist two declarative statements. So I would like to clarify my questions:
1 - Can we mix imperative and declarative statements under a single statement ?
2 - How are multiple declarative statements under on demo_wrapper_1: allowed ?
3 - If what I’m doing is not syntactically valid, is there a way of signifying that an action occurs regardless of the guard conditions?
Mixing declarative and imperative statements is not allowed. And yes, indeed, one statement is only allowed after a “on”; but that statement can be a compound statement ("{…}”) which can consist of many statements; and that compound should be either a declarative compound or a imperative compound.
(Note that the “fix” I proposed, does contain two imperative statements; not declarative as you mentioned)
Also, it is not allowed to have a imperative statement without an “on” statement in front of it. (Which is what you want as I understand now). It looks to me you want to have some “entry/exit” actions as known for classical statemachine. Those can be modeled in Dezyne using functions:
Instead of writing
state = <next-state>
make a function, e.g., “goto” and call that function:
goto(<next-state>)
with function “goto”:
void goto(State new_state) {
<exit actions for leaving state 'state'>
state = new_state;
<entry actions for entering state 'new_state'>
}
Thanks for the help. Almost all my questions have been clarified. The only problem left in my mind is that I was referring to the following structure when I talked about multiple declarative statements: