Macros are defined under the MACRO descriptor. The descriptor is followed by the macros, each of which is written in a separate line. There may be multiple MACRO descriptors in the same text file.
Sometimes the definition of a macro is too long to be understandable in a single line. In that case, the designer may use a line break ``'' at the end of a line to connect it with the next line (preceding spaces and tabs are preserved in the next line).
macro1.des demonstrates the use of macros:
MACRO: NEWSTATE = B DUMP_STATE(state) = print "Current state:", "[state]" STATECHART: A [DS] B C TRANSITION: S: A N: [NEWSTATE] E: e O: [DUMP_STATE([NEWSTATE])]
In this example, two macros are defined: NEWSTATE is defined to be B and DUMP_STATE is defined to dump the current state to the console. Once defined, the macros can be used throughout the model description, with their names placed in square brackets.
In the definition of DUMP_STATE, print is a Python command and prints a message to the console. This macro has a parameter state. In the left-hand side, the parameter is placed between parentheses. In the right-hand side, the value of the parameter can be referred to with the name of the parameter between square brackets. Designers must keep in mind that parameters are literally substituted by their values when they are used in other parts of the model description. For example, in this case, [states] is substituted with [NEWSTATE] in the output of the transition. [NEWSTATE] refers to the value of macro NEWSTATE, which is B. Because [state] is substituted by B in the right-hand side, to print out this current state as a Python string, [state] must be placed between quotes.
To execute this example in textual mode, use the following command:
svm -t macro1.desHere is the result:
['A'] > e Current state: B ['B'] > exit