Next: Builtin functions, Previous: Patterns, Up: Top [Contents][Index]
In the previous chapters the flexibility of macro names and patterns with multiple values on a single character position and the use of one or more characters has been explained. This flexibility is normally sufficient for most tasks.
In this part further possibilities are explained. These further possibilities described in this part give the names the same functionality as regular expressions known from some programming languages or software.
In this text the multiple parts that are linked together are called pattern expressions, because the name regular expression is mostly used for a notation to describe sets of character strings.
Regular expressions are normally implemented with algorithms specially made for these.
In m0 the bitap algorithm is still used for macros and patterns consisting of multiple parts.
The use of this has an influence on the way to construct a name from the multiple parts.
The multiple parts are constructed in the same way as the normal macros or pattern parts, but they are not started by the first character of the part. The parts are started when another part has been detected. By linking the parts together, the second part is activated when the first part has triggered.
Thus to define multiple parts you have to:
The name of a part has all the possibilities mentioned under the variable length macros.
The difference is that a starting or intermediate part will not do a macro expansion. Normally only the last part is defined as a macro and will do the expansion. It will normally replace the whole piece of text of the different parts with the definition. However this can be defined differently.
If a part will start at the first character (starting part) or not (intermediate part), can be set during the definition of the part.
In conclusion three types of parts exist:
There is no limit to the number of starting, intermediate or end parts. However the performance will be influenced if the total number of characters used by the parts become large. The parts are placed in the algorithm for vlm macros and every time a 64 character border is exceeded, an extra word / register is needed that will slow down the execution speed of the vlm algorithm.
The linking of parts make the parts work as a pattern expression.
Linking defines which part will start or activate another or other parts.
The following example is a figure of the linking of a small pattern expression. This example has:
aa
bb and cc, these are alternatives of each other.
dd that will do the macro expansion.
A regular expression for this would be e.g.: aa(bb|cc)dd.
In the figure the arrows (-->) indicate the links:
start part: |a|a|
|
link aa to +---+
bb and cc | |
| v
intermediate part | |b|b|
v |
intermediate part |c|c| |
| |
link bb to dd +---+
link cc to dd |
v
end part |d|d|
|
v
macro expansion
The aa start part will start on the first character. If the aa is in the text, this part
will trigger the start of intermediate parts bb and cc using the links aa to bb and cc.
If the text contains an aabb or aacc
the intermediate part bb or cc will trigger the start of end part dd using the link bb to dd or cc to dd.
If the text further contains a dd the end part will trigger a macro expansion.
This example thus shows that using parts and links to create pattern expressions a same functionality as using regular expressions can be achieved.
The example shows only a very basic linking. The linking can be more elaborate to have e.g. zero or one time a part, or one or more times a part, or more complicated OR and AND combinations.
The text that matches the pattern expression should be replaced by the definition of the macro.
The algorithm in m0 uses backtracking when a pattern expression for a macro is matched.
The way the backtracking runs
can be set during the definition of the parts.
There can sometimes seem to be ambiguities what the pattern expression exactly should match. Therefore the following points should bring clarity in the matching of the pattern expression:
[]+).
The first moment a character matches this, the macro expansion is triggered and further possible matching
characters are not included in the match. A way to overcome this is defining a different character
(like e.g. a white-space) after the one or more character. This different character can be excluded from
the macro expansion using the post-size of the macro.
Using the multiple parts in patterns (for argument collection or substitution) does not increase the functionality of patterns. Every part will start the related program irrespective of the type of part.
The use of multiple parts in patterns can however reduce repeated matching parts. With a large number of parts it will therefore reduce memory use and increase execution speed. The effort for coding the pattern will probably decrease.
Next: Builtin functions, Previous: Patterns, Up: Top [Contents][Index]