Product SiteDocumentation Site

9.8. Advanced Topics in Parsing

This section includes parsing several strings and flow charts illustrating a conceptual view of parsing.

9.8.1. Parsing Several Strings

Only ARG and PARSE ARG can have more than one source string. To parse several strings, you can specify several comma-separated templates. Here is an example:
parse arg template1, template2, template3
This instruction consists of the keywords PARSE ARG and three comma-separated templates. For an ARG instruction, the source strings to be parsed come from arguments you specify when you call a program or CALL a subroutine or function. Each comma is an instruction to the parser to move on to the next string.
Example:

Example 9.23. Parsing variable strings

/* Parsing several strings in a subroutine                       */
num="3"
musketeers="Porthos Athos Aramis D'Artagnan"
CALL Sub num,musketeers  /* Passes num and musketeers to sub     */
SAY total; say fourth /* Displays: "4" and " D'Artagnan"         */
EXIT

Sub:
  parse arg subtotal, . . . fourth
  total=subtotal+1
  RETURN

Note that when a Rexx program is started as a command, only one argument string is recognized. You can pass several argument strings for parsing if:
  • One Rexx program calls another Rexx program with the CALL instruction or a function call
  • Programs written in other languages start a Rexx program
If there are more templates than source strings, each variable in a leftover template receives a null string. If there are more source strings than templates, the language processor ignores leftover source strings. If a template is empty (two subsequent commas) or contains no variable names, parsing proceeds to the next template and source string.