
The macro processor provides several string handling functions. The concatenation operator (#) mentioned above can be used to concatenate strings. In addition, the 'substr function can be used to extract substrings of a given string. The 'substr function requires three operands. The first is the string from which the substring is to be extracted. The second operand is the starting position of the substring. The first character of the string is in position zero. The third operand is the length of the substring. If the length is specified as zero, the substring from the starting position to the end of the subject string is returned. Some examples of this function are given below.
'substr("abcdef",0,3) returns "abc"
'substr("abcdef",3,1) returns "d"
'substr("abcdef",2,3) returns "cde"
'substr("abcdef",2,0) returns "cdef"
A negative starting position is treated as zero. A starting position greater than or equal to the length of the string causes the null string to be returned. A negative length is treated as a zero. If there are not enough characters in the string to create a substring of the specified length, the substring from the starting position to the end of the string is returned. If the 'substr function is specified with fewer than three arguments, the omitted arguments are treated as zeros. Any of the three arguments may be expressions.
The 'len function can be used to count the characters in a string. The 'len function requires one argument which should be a string. It returns the number of characters in a string. The following macro fragment can be used to process the characters of a string one at a time.
'int 'i
'str 'char
'assign 'i,0
'while 'i'<'len('0)
'assign 'char,'substr('0,'i,1)
... process 'char ...
'assign 'i,'i+1
'endwhile
The macro preprocessor provides several "read only" built-in string variables. The variable 'null can be used in place of "" to represent the null string. The variables 'callt and 'label have already been discussed. In addition, the variable 'opcode contains the opcode of the macro call. (As will be explained below, a macro can be given more than one name, so this variable does have some use.) The value of the variable 'run can be set from the UNIX command line. Its default value is "alogic".