Omni Systems, Inc.

  

Mif2Go User's Guide, Version 55

  

Valid HTML 4.01!

 

Made with Mif2Go

28 Working with macros > 28.6 Using expressions in macros > 28.6.2 Understanding operands and operators


28.6.2 Understanding operands and operators

Operands for macro expressions

An operand can be any of the following:

a macro variable: $$name (see §28.3 Using macro variables)

a number, including hexadecimal numbers starting with 0x or 0X

a double-quoted string: "..."

a single-quoted string: '...'

a single-quoted character, including '\r' and '\n'

an unquoted single word

a parenthesized expression.

Operators for macro expressions

Operators include essentially the whole C-language numeric and logical sets, as well as some Mif2Go string operators; Table 28-4 shows the operators you can use in macro expressions. Most operators participate in binary (two-operand) expressions. Exceptions are the operators used in the ternary conditional expression described in §28.6.4.2 Using conditional expressions, and the unary string operators described in §28.6.5 Specifying substrings in expressions.

Table 28-4 Operators for HTML macro expressions

Type

Operator

Meaning

Comments

Relational

=, ==

equal to

The result is 0 (zero) or 1 (one).

Spaces are optional; you can use any number of spaces around symbol operators.

!=, <>

not equal to

<

less than

<=

less than or equal to

>

greater than

>=

greater than or equal to

Logical

and, &&

both operands are true

The result is 0 (zero) or 1 (one).

Two-word operators must have exactly one space between the two words. You can use any number of spaces elsewhere. Unlike in C, both operands are always fully evaluated.

and not, &&!

first is true, and second is false

or, ||

either is true, or both are true

or not, ||!

first is true, or second is false

xor, ^

one operand is true, the other is false

xor not, ^!

both are true, or both are false

Bitwise

&

1 where both operands have 1

0 everywhere else

These are numeric string operators.

The first six are like the logical operators.

The last two are bitwise shifts with the second operand the count.

For example:

(($$myvar >> 8) & 0xFF)

extracts the second-up byte from a number.

&~

1 where first has 1 and second has 0

0 everywhere else

|

1 where either has or both have 1

0 where both operands have 0

|~

1 where first has 1 or second has 0

0 where first has 0 and second has 1

^

1 where operand bits differ

0 where operand bits are the same

^~

1 where operand bits are the same

0 where operand bits differ

<< N

shift first operand to the left N bits

>> N

shift first operand to the right N bits

Arithmetic

+

plus

These are the usual suspects.

The result of (n / 0) or (n % 0) is 0 (zero), because infinity is hard to represent.

-

minus

*

times

/

divided by

%

modulo

String

is

equal to

is and is not are caseless compares using stricmp()

plus is like strcat()

before and after use strstr() to find the 2nd operand in the 1st:

(doggie before gi) is dog

You can get a strnicmp() effect using “first N” or “last N
with “is” or “is not”:

(($$myvar first 3) is

($$yourvar last 3))

is not

not equal to

plus

concatenated with

before

substring before the 1st (leftmost) occurrence of 2nd string in 1st

after

substring after the first (leftmost) occurrence of 2nd string in 1st

first N

leftmost N characters (default = 1)

last N

rightmost N characters (default = 1)

length

length in characters

Integer result

starts $$str

true if $$str is at the start

Boolean result

ends $$str

true if $$str is at the end

Boolean result

contains $$str

true if $$str occurs anywhere in the string

Boolean result

char N

Nth character, counting from left

First (leftmost) character is number 1

Default value of N is 1

trim first N

all but first N characters

Default value of N is 1

trim last N

all but last N characters

Default value of N is 1

$$str lower

converts $$str to lowercase

 

$$str upper

converts $$str to uppercase

 

$$str replace $$str1 with $$str2

converts each instance of $$str1 in $$str to $$str2

 

Conditional

?

“if” the 1st operand is true,

“then” the 2nd operand is the value of the expression

<$($$myvar ? "yes" : "no")>

is equivalent to:

 

<$_if ($$myvar)> yes

<$_else> no

<$_endif>

:

“else” the 3rd operand is the value of the expression



28 Working with macros > 28.6 Using expressions in macros > 28.6.2 Understanding operands and operators