Assignment syntax
When inheriting from a model it is fundamental to be able to override the expressions of the variables in the base class. In OpenPLX you can add assigments to a model to update variables in the base class. An assignment is added indented under a model by specifying the variable name followed by :
and the new value/expression.
BaseModel:
x is Real: 0.0
ModelA is BaseModel:
x: 2.0
y is Real: 1.0
ModelB is ModelA:
y: x + 2.0
This results in ModelB.x
being 2.0 inherited from ModelA
Nested assignments
Often you will have variables of model type which in turn has variables of model type, which creates a tree of variables that are potential targets for assignment. There are two ways to assign a nested variable, either through an indented block of assignments or specifying the path to the specific variable my separating variable names with a dot (.
).
NestedModel:
x is Real: 0.0
y is Real
MemberModel:
nested is NestedModel:
x: 1.0
BaseModel:
member is MemberModel:
nested.x: 3.0
member.nested.y: 5.0
MyModel is BaseModel:
member.nested:
x: 4.0
MyModel.member.nested.x
will be 4.0
. Note also the alternative Syntax of BaseModel.member.bested.y
which MyModel
inherits to MyModel.member.nested.y
Grammar
assignment → INDENT (IDENTIFIER ".")* IDENTIFIER ":" expression