Next: 2 Semantics in UML
Up: 1.3 Action semantics and
Previous: 1.3.2 Examples of SDF
From time to time we want to migrate
from an existing language to another and reuse as much as possible. In case
when the two languages share exactly the same semantic features but differ
syntactically, the only thing we have to do is modify the SDF description. This
is because in all the modules which defines the original language, only the SDF
description depends on the concrete syntax. Other modules, of course, must
conform to a certain syntax, but that syntax is defined in action semantics and
is thus universal.
For instance, by changing the action notation example in the last section to:
ActionPrefix "(" Actions ")"
Action {left} |
Action Actions |
Action ","
Actions Actions |
"actlist" ActionPrefix
|
we completely change the action
syntax. actlist(A1), actlist(A1, A2, , An),
actlist(A1, actlist(A2, A3), A4, actlist(A5)) are now acceptable.
(Supposing A1, A2, , An are
actions.)
An other example is to change the data notation in the last section to the
following:
Data Data DataOpPostfix
Data |
"+"|"-"|"*" DataOpPostfix |
to let the language accept postfix expressions.
Note that because a postfix expression has explicit evaluation ordering and is
never ambiguous, we can specify {left} for the first statement, or
{right}, or just ignore this option.
In reality, when the language is modified, it is impossible to keep all the
other modules untouched and just modify the SDF description. Fortunately, our
reason for introducing the SDF level is not to avoid changes in the language
description, but to minimize them.
Without this additional level, in practice people often find rewriting the whole
language description more reasonable than modifying the existing one, because it
is too difficult to find out all the lexical symbols scattering in the whole
description and modify them correctly. Maintainability and readability must also
be considered.
Next: 2 Semantics in UML
Up: 1.3 Action semantics and
Previous: 1.3.2 Examples of SDF
Thomas Feng
2003-04-18