Parsing Instructions
The REXX parsing instructions are PULL, ARG, and PARSE. (PARSE has several variants.)
PULL instruction
PULL is an instruction that reads input and assigns it to one or more variables. If the
program stack contains information, the PULL instruction takes information from the program stack.
When the program stack is empty, PULL takes information from the current terminal input device. See
Getting information from the program stack or terminal input device for information about the data stack.
/* This REXX program parses the string "Knowledge is power." */
PULL word1 word2 word3
/* word1 contains 'KNOWLEDGE' */
/* word2 contains 'IS' */
/* word3 contains 'POWER.' */
PULL translates character information to uppercase before assigning it into variables. If you do not
want uppercase translation, use the PARSE PULL instruction.
/* This REXX program parses the string: "Knowledge is power." */
PARSE PULL word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
You can include the optional keyword UPPER on any variant of the PARSE instruction. This
causes the language processor to translate character information to uppercase before assigning it
into variables. For example, using PARSE UPPER PULL gives the same result as using
PULL.
ARG instruction
The ARG instruction takes information passed as arguments to a program, function, or
subroutine, and puts it into one or more variables. To pass the three arguments
Knowledge is power. to a REXX program named sample : - Call the program and pass the arguments as a string following the exec name:
REXX sample Knowledge is power. - Use the ARG instruction to receive the three arguments into variables.
/* SAMPLE -- A REXX program using ARG */ ARG word1 word2 word3 /* word1 contains 'KNOWLEDGE' */ /* word2 contains 'IS' */ /* word3 contains 'POWER.' */
ARG translates character information to uppercase before assigning the arguments into variables.
If you do not want uppercase translation, use the PARSE ARG instruction instead of ARG.
/* REXX program using PARSE ARG */
PARSE ARG word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
PARSE UPPER ARG has the same result as ARG. It translates character information to uppercase before assigning it into variables.
PARSE VALUE … WITH instruction
The PARSE VALUE…WITH instruction parses a specified expression, such as a literal string,
into one or more variables whose names follow the WITH subkeyword.
PARSE VALUE 'Knowledge is power.' WITH word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
PARSE VALUE does not translate character information to uppercase before assigning it into
variables. If you want uppercase translation, use PARSE UPPER VALUE. You could use a variable
instead of a string in PARSE VALUE (you would first assign the variable the value):
string='Knowledge is power.'
PARSE VALUE string WITH word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
Or you can use PARSE VAR to parse a variable.
PARSE VAR instruction
The PARSE VAR instruction parses a specified variable into one or more variables.
quote = 'Knowledge is power.'
PARSE VAR quote word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
PARSE VAR does not translate character information to uppercase before assigning it into variables. If you want uppercase translation, use PARSE UPPER VAR.