Contents | Index | < Browse | Browse >
PARSE
usage: PARSE [UPPER] input-source [template] [template...]
-extracts one or more substrings from a string and assigns them to
variables. Various forms:

1)UPPER - input string made uppercase before parsing
2)ARG - retrieves argument string supplied when program was invoked
3)EXTERNAL - input string is read from STDERR stream so as not to
disturb PUSHed or QUEUEd data. If multiple templates are supplied, each
template will read a new string. This source options is the same as PULL
4)NUMERIC - current numeric options placed in a string in the order
DIGITS, FUZZ, FORM separated by a single space.
5)PULL - reads a string from the input console
6)SOURCE - the source string for the program is retrieved, formatted as:
{COMMAND | FUNCTION} {0|1} called resolved ext host
The first token shows whether invoked as a command or function; the
2nd is a boolean flag indicating whether a result string was requested
by the caller; the called token is the name used to invoke this
program; resolved is the final resolved name of the program; ext is
the file extension to be used for searching (default "rexx"); host is the
initial host address for commands
7)VALUE expression WITH - input string is the result of the supplied
expression. The WITH keyword is required to separate the expression
from the template.
8)VAR variable - the value of the specified variable is used as the
input string.
9)VERSION - information about the ARexx interpreter is supplied in the
form: "the version cpu mpu video freq"

Example code #1:
---------------
[Note: this format puts the arguments into CALL Function() form which places call parameters as separate, comma-separated arguments: (arg1,arg2, etc.) which have to be retrieved with parsing arg(1), arg(2), etc.]

Var=56.4446
say var
Call Round(var,2) /* ask function to round to two decimal places */
Var=result
say Var
Exit

Round:
procedure
/* parse and round decimal number to specified decimal precision */
parse value arg(1)*1.0 with integer '.' fraction
Precision=arg(2)
Parse numeric NumDigits .
numeric digits 2
fraction=trunc('.'||fraction,precision)
numeric digits NumDigits
RETURN integer+fraction

Example code #2:
---------------
[Note: this format puts the arguments into "CALL function var1 var2, etc." form which places call parameters as space delimited arguments, and which then have to be retrieved with parsing format PARSE ARG arg1 arg2 arg3 .]

Var=56.4446
say var
Call Round var 2 /* ask function round to two decimal places */
Var=result
say Var
Exit

Round:
procedure
/* parse and round decimal number to specified decimal precision */
parse arg integer '.' fraction precision
Parse numeric NumDigits . /* discover current setting for precision */
numeric digits precision
fraction=trunc('.'||fraction,precision)
numeric digits NumDigits /* restore precision */
RETURN integer+fraction