HP 3000 Manuals

Ap B. Expression Evaluator Functions [ MPE/iX Commands Reference Manual Volume I ] MPE/iX 5.5 Documentation


MPE/iX Commands Reference Manual Volume I

Appendix B  Expression Evaluator Functions 

The expression evaluator is a system procedure used by the user interface
to accept a string, number, or Boolean expression, evaluate it, and
return the result.  This procedure is used by the CALC, SETVAR, IF,
ELSEIF, and WHILE commands in the MPE/iX command interpreter (CI). 

The expression evaluator provides the following:

   *   consistent evaluation of expressions

   *   compatibility with MPE V/E job control word evaluation

   *   user flexibility

The expression evaluator uses algebraic notation and supports the
functions defined in table B-1.  The references that appear in this table
in parentheses, for example (8), are defined following the table.

          Table B-1.  Expression Evaluator Functions 

---------------------------------------------------------------------------------------
|                      |              |                          |                    |
|        Symbol        |   Function   |         Example          |       Result       |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| +(numeric)           | addition     | 4 + 5                    | 9                  |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| +(string)            | concatenate  | "abc" + "de"             | abcde              |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| -(numeric)           | subtraction  | 12 - 6                   | 6                  |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| -(string)            | deletion of  | "abc" - "b"              | ac                 |
|                      | first        |                          |                    |
|                      | occurrence   |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| *                    | multiplication 4 * 5                    | 20                 |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| /                    | integer      | 79/ 10                   | 7                  |
|                      | division     |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| ^                    | exponentiation 2^3                      | 8                  |
|                      | (9)          |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| either " or '        | string       | either "abc" or 'abc'    | abc                |
|                      | identifier   |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| ()                   | parentheses  | (3 + 4) * 2              | 14                 |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| <                    | less than    | 5 < 6                    | TRUE               |
|                      | (1)          |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| <=                   | less than or | "abc" <= "abc"           | TRUE               |
|                      | equal (1)    |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| >                    | greater than | "xyz" > "abc"            | TRUE               |
|                      | (1)          |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| >=                   | greater than | "abc" >= "abc"           | TRUE               |
|                      | or equal (1) |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| <>                   | not equal    | 5 <> 6                   | TRUE               |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| =                    | equal        | "xyz"= "xyz"             | TRUE               |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| ABS(integer)         | absolute     | abs(-4)                  | 4                  |
|                      | value        |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| ALPHA(string)        | check if a   | alpha('abcd')            | TRUE               |
|                      | string is    | alpha('ab3d ef')         | FALSE              |
|                      | alphabetic   |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| ALPHANUM(string)     | check if a   | alphanum('abCd')         | TRUE               |
|                      | string is    | alphanum('45abd')        | TRUE               |
|                      | only         | alphanum('3d ef')        | FALSE              |
|                      | alphabetics  |                          |                    |
|                      | and digits   |                          |                    |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| AND                  | logical and  | 7=7 and 5=5              | TRUE               |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| BAND                 | bitwise and  | 7 band 13                | 5                  |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------
|                      |              |                          |                    |
| BNOT                 | bitwise not  | bnot 5                   | -6                 |
|                      |              |                          |                    |
---------------------------------------------------------------------------------------

          Table B-1.  Expression Evaluator Functions (Cont.) 

-------------------------------------------------------------------------------------
|                      |                |                      |                    |
|        Symbol        |    Function    |       Example        |       Result       |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| BOR                  | bitwise or     | 5 bor 2              | 7                  |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| BOUND(varname)       | variable       | bound(HPPATH)        | TRUE               |
|                      | definition     |                      |                    |
|                      | test (2)       |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| BXOR                 | bitwise        | 7 bxor 5             | 2                  |
|                      | exclusive or   |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| CHR(integer)         | ASCII value    | chr(65)              | A                  |
|                      | (integer) ===> |                      |                    |
|                      | character      |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| CSL                  | circular shift | -2 csl 2             | -5                 |
|                      | left (3)       |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| CSR                  | circular shift | -7 csr 1             | -4                 |
|                      | right (3)      |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| DELIMPOS(str,[,delims] returns index  | DELIMPOS('file a=bb, | 5                  |
| [,nth][,start])      | in str of the  | old;rec=40,,f,ascii')|                    |
|                      | nth delimiter  |                      |                    |
|                      | beginning at   |                      |                    |
|                      | start; default |                      |                    |
|                      | delims are a   |                      |                    |
|                      | space, a       |                      |                    |
|                      | comma, a       |                      |                    |
|                      | semicolon, an  |                      |                    |
|                      | equals sign,   |                      |                    |
|                      | left and right |                      |                    |
|                      | parentheses,   |                      |                    |
|                      | left and right |                      |                    |
|                      | brackets,      |                      |                    |
|                      | single quote,  |                      |                    |
|                      | double quote,  |                      |                    |
|                      | and Tab;       |                      |                    |
|                      | default nth is |                      |                    |
|                      | 1; default     |                      |                    |
|                      | start is 1     |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| DWNS(string)         | shift string   | dwns('aBC&#dE')      | abc&#de            |
|                      | to lowercase   |                      |                    |
|                      | (7)            |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| EDIT(string,editstr[,start])rms full  | EDIT(`abcdefg','>dd')| 'abce'             |
|                      | REDO-like      | EDIT('ab cd;g',      | 'cd;g'             |
|                      | editing of a   | 'dwd')               |                    |
|                      | string         |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| FINFO(filename,option) file           | FINFO('x.pub',0)     | TRUE               |
|                      | information    |                      |                    |
|                      | (6)            |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| HEX(integer)         | convert to     | hex(329)             | $149               |
|                      | hexadecimal    |                      |                    |
|                      | string         |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| INPUT([prompt][,wait]) accept user    | input('Enter         | Enter choice:  Y   |
|                      | input (10)     | choice:',20)         | Return "Y"         |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| LEN(string)          | string length  | len("abc")           | 3                  |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| LFT(string, # chars) | left string    | lft('abc',2)         | ab                 |
|                      | extraction     |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| LSL                  | logical shift  | 7 lsl 1              | 14                 |
|                      | left           |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| LSR                  | logical shift  | -7 lsr 1             | 2,147,483,644      |
|                      | right          |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------

          Table B-1.  Expression Evaluator Functions (Cont.) 

-------------------------------------------------------------------------------------
|                      |                |                      |                    |
|        Symbol        |    Function    |       Example        |       Result       |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| LTRIM(string[,trimstr])trim left end  | 'X'+ltrim(' abc')    | Xabc               |
|                      | of string (11) | "X"+ltrim('...abc',  | Xabc               |
|                      |                | '.')                 |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| MAX(num1[,num2...])  | find largest   | max(5,4-3,70,0)      | 70                 |
|                      | of several     |                      |                    |
|                      | integers       |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| MIN(num1[,num2...])  | find smallest  | min(5,4,-3,70,0)     | -3                 |
|                      | of several     |                      |                    |
|                      | integers       |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| MOD                  | modulo (4)     | 25 mod 2             | 1                  |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| NOT                  | logical not    | not(2>1)             | FALSE              |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| NUMERIC (string)     | check if a     | numeric('12345')     | TRUE               |
|                      | string is all  | numeric('$a234ef')   | FALSE              |
|                      | digits         |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| OCTAL(integer)       | convert to     | octal(329)           | %511               |
|                      | octal string   |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| ODD(integer)         | determine if   | odd(233)             | TRUE               |
|                      | integer is odd | odd(-2)              | FALSE              |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| OR                   | logical or     | 5=5 or 2=3           | TRUE               |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| ORD(string)          | ordinal (8)    | ord('AbcD')          | 65                 |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| POS(find str,source  | find nth       | pos('ab','cgabd')    | 3                  |
| str[,n])             | occurrence of  | pos('.','file.grp.acct',2)                |
|                      | find str in    | pos('.','file.grp.acct',-                 |
|                      | source str;    | 1)                   |                    |
|                      | positive value |                      |                    |
|                      | for n begins   |                      |                    |
|                      | search at      |                      |                    |
|                      | left; negative |                      |                    |
|                      | value for n    |                      |                    |
|                      | begins search  |                      |                    |
|                      | at right) (12) |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| PMATCH(pattern,str   | searches for   | PMATCH('f@','fread') | TRUE               |
| [,start])            | pattern in a   | PMATCH('abc','abcd') | FALSE              |
|                      | given string   |                      |                    |
|                      | (str) starting |                      |                    |
|                      | at start;      |                      |                    |
|                      | pattern may    |                      |                    |
|                      | contain        |                      |                    |
|                      | wildcards;     |                      |                    |
|                      | default start  |                      |                    |
|                      | is 1           |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------

          Table B-1.  Expression Evaluator Functions (Cont.) 
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
|        Symbol        |    Function    |       Example        |       Result       |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| REPL(str,oldstr,newstr in a given     | REPL('aaabcaab','aa','X')abcXb'           |
| [,cnt][,start])      | string (str),  | REPL('aaabcaab','ab','',-aabca'           |
|                      | replaces cnt   | 1)                   |                    |
|                      | occurrences of |                      |                    |
|                      | oldstr with    |                      |                    |
|                      | newstr,        |                      |                    |
|                      | beginning at   |                      |                    |
|                      | start; if cnt  |                      |                    |
|                      | is positive,   |                      |                    |
|                      | replacement    |                      |                    |
|                      | begins at the  |                      |                    |
|                      | left end of    |                      |                    |
|                      | str; if        |                      |                    |
|                      | negative,      |                      |                    |
|                      | replacement    |                      |                    |
|                      | begins at the  |                      |                    |
|                      | right end of   |                      |                    |
|                      | str; default   |                      |                    |
|                      | start is 1;    |                      |                    |
|                      | default cnt is |                      |                    |
|                      | zero (meaning  |                      |                    |
|                      | all            |                      |                    |
|                      | occurences)    |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| RHT(string, # chars) | right string   | rht("abc",2)         | bc                 |
|                      | extraction     |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| RPT(string,count)    | repeat a       | rpt('aBc',3)         | aBcaBcaBc          |
|                      | string (-count | rpt('aBc',-3)        | cBacBacBa          |
|                      | reverses       |                      |                    |
|                      | string)        |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| RTRIM(string[,trimstr])trim right end | rtrim('abc ')+'X'    | abcX               |
|                      | of string (11) | rtrim('abc...','.')+"X"abc X              |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| SETVAR(varname,expr) | return result  | setvar(myvar,2*3+5)  | sets variable      |
|                      | of expr and    |                      | myvar to 11 and    |
|                      | set varname to |                      | returns 11         |
|                      | result (13)    |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| STR(string,start     | general string | str('abcde',2,3)     | bcd                |
| pos, # chars)        | extraction     |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| TYPEOF(expression)   | type of        | typeof(HPPATH)       | 2 (string)         |
|                      | variable or    |                      |                    |
|                      | expression (5) |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| UPS(string)          | shift string   | ups('aBc5d')         | ABC5D              |
|                      | to uppercase   |                      |                    |
|                      | (7)            |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------

          Table B-1.  Expression Evaluator Functions (Cont.) 

-------------------------------------------------------------------------------------
|                      |                |                      |                    |
|        Symbol        |    Function    |       Example        |       Result       |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| WORD(string,[,delims]| performs       | WORD('file a=bb,old; | 'file'             |
| [,nth][,end_var][,start])neral word   | rec=40,,f,ascii')    |                    |
|                      | extraction;    | WORD('file a=bb,old; |                    |
|                      | default delims | rec=40,,f,ascii',,-  | '40', j=18         |
|                      | are a space, a | 4,j)                 |                    |
|                      | comma, a       |                      |                    |
|                      | semicolon, an  |                      |                    |
|                      | equals sign,   |                      |                    |
|                      | left and right |                      |                    |
|                      | parentheses,   |                      |                    |
|                      | left and right |                      |                    |
|                      | brackets,      |                      |                    |
|                      | single quote,  |                      |                    |
|                      | double quote,  |                      |                    |
|                      | and Tab;       |                      |                    |
|                      | default nth is |                      |                    |
|                      | 1; the default |                      |                    |
|                      | end_var is no  |                      |                    |
|                      | variable; the  |                      |                    |
|                      | default start  |                      |                    |
|                      | is 1           |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------
|                      |                |                      |                    |
| XOR                  | logical        | 7=7 xor 5=5          | TRUE               |
|                      | exclusive or   |                      |                    |
|                      |                |                      |                    |
-------------------------------------------------------------------------------------



MPE/iX 5.5 Documentation