home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 May / PCO_5_97.ISO / FilesBBS / OS2 / NETREXX.ARJ / NETREXX.ZIP / NetRexx / netrexx.doc < prev    next >
Encoding:
Text File  |  1997-01-02  |  57.1 KB  |  1,487 lines

  1.                                                             NetRexx 1.00
  2. NetRexx language summary and quick reference
  3. ============================================
  4.  
  5. Copyright(c) IBM Corporation, 1996, 1997.  All rights reserved.
  6.  
  7. Introduction
  8. """"""""""""
  9. NetRexx is a new programming language derived from both Rexx and
  10. Java(tm); the rules of syntax closely follow those of Rexx, while the
  11. semantics often follow Java.  It is a dialect of Rexx that can be as
  12. efficient and portable as Java, while preserving the low threshold to
  13. learning of the original Rexx language.  Further, the language is
  14. intended to be even more keyword safe than Rexx: it should be possible
  15. to re-compile or execute an existing NetRexx program _from source_ at
  16. any time without additions to the keywords known to the language
  17. invalidating an existing program.
  18.  
  19. Like Rexx, NetRexx is designed to allow clear separation of its concepts,
  20. so it may be introduced gradually.  Also like Rexx, sensible defaults
  21. are defined to aid ease of use -- especially for the novice programmer.
  22. These defaults can be turned off for the programmer who needs stricter
  23. type-checking than Java, or other extra checks.
  24.  
  25. The Java virtual machine environment is assumed to be a platform for
  26. NetRexx, and this places some constraints on the NetRexx language.  For
  27. example, the semantics of type resolution are in part determined by the
  28. environment, not the language.
  29.  
  30. The constraints of efficiency, safety, and environment implied that this
  31. language would have to differ in some details of syntax and semantics
  32. from Rexx; it could not be a fully upwards-compatible extension to Rexx.
  33. The need for change, however, has offered the opportunity to make some
  34. important simplifications and enhancements to the language to strengthen
  35. the original Rexx design, and incorporate other additions from ANSI
  36. Rexx, Object Rexx, and Java.
  37.  
  38. The most up-to-date information on NetRexx and Rexx may be found at:
  39.  
  40.   http://www2.hursley.ibm.com
  41.  
  42. Mike Cowlishaw, IBM Fellow
  43. IBM UK Laboratories
  44.  
  45.  
  46. Language Description
  47. """"""""""""""""""""
  48. The following sections describe the various aspects of the NetRexx
  49. language.
  50.  
  51. This summary is intended as a handy reference and is not intended to be
  52. a rigorous definition.  It assumes knowledge of Rexx (and a little of
  53. Java semantics).  Please see the _NetRexx Language Definition_ at
  54. http://www2.hursley.ibm.com/nrl/ for full details of the language.
  55.  
  56.  
  57. Base syntax
  58. """""""""""
  59. Tokenization of NetRexx programs into clauses is the same as Rexx (blanks
  60. adjacent to special characters disappear, strings can be delimited with
  61. single or double quotes, "/*" comments nest, etc.) with the following
  62. differences:
  63.  
  64.   o The sequence '--' (outside a literal string or comment) introduces a
  65.     comment that is terminated by end-of-line, for example:
  66.  
  67.        Say 'Hello World!'   -- displays a message
  68.  
  69.     Similarly, the sequences '++' and '\\' are reserved for future use
  70.     (they are in error, rather than some combination of operators).
  71.  
  72.   o Only '\' is allowed for the 'not' operator.
  73.  
  74.   o A number in exponential notation must have a sign after the 'E'.
  75.     The following are valid:
  76.  
  77.        12E+2 12e-3 12.7E+0  1E-1    /* 1e6 is not a valid number */
  78.  
  79.     A symbol that starts with a digit must have the syntax of a number.
  80.     At present, numbers cannot start with a period.
  81.  
  82.   o A comment is always equivalent to a blank (it does not act as a
  83.     transparent separator).
  84.  
  85.   o A hyphen (minus sign) is used for continuation rather than comma.
  86.  
  87.   o Square brackets are used for array/stem notation, as in Object Rexx
  88.     (and other languages).
  89.  
  90.   o '?', '!', and '.' are not permitted in identifiers (names).
  91.  
  92.   o C-like character encodings are allowed in literal strings,
  93.     introduced by backslash.  Specifically the following are allowed:
  94.  
  95.       \t \n \r \f \" \' \\ \- \0 \xhh \uhhhh
  96.  
  97.     meaning tab, newline (linefeed), carriage return, form feed, double
  98.     quote, single quote, backslash, delete, zero-character, hexadecimal,
  99.     unicode.  In the last two, two or four hexadecimal digits,
  100.     respectively, are required.  The 'zero character' can therefore also
  101.     be written as \x00 or \u0000.  The escape letters (t, n, etc.) and
  102.     the hexadecimal digits may be in lower or upper case.  Rexx-style
  103.     quote-doubling is also accepted.
  104.  
  105.   o A source-level unicode escape is under consideration (currently a
  106.     notation using braces is favoured -- braces, outside literals, could
  107.     wrap sections of code -- or the whole program -- where unicode
  108.     escapes are permitted; a unicode escape might then look like {0012
  109.     0321}, and so on (with optional whitespace at four-character
  110.     boundaries).
  111.  
  112.  
  113. Expressions and operators
  114. """""""""""""""""""""""""
  115. NetRexx expressions follow the rules of Rexx.  All Rexx operators are
  116. valid syntax, with Rexx precedence rules during evaluation.  Parentheses
  117. can be used, as usual, to alter operator precedence by defining
  118. sub-expressions.
  119.  
  120. The semantics of operators may vary as there is more than one data type
  121. and operators can be overloaded (as an implementation detail rather than
  122. a language feature) in NetRexx.  More specifically, in the case of the
  123. 'Rexx' string class provided by NetRexx, the Rexx operators act as
  124. defined by the ANSI standard for Rexx (with the single exception that
  125. non-strict comparisons are case-independent).  For other classes (the
  126. binary 'int' type provided by Java, for example) traditional binary
  127. arithmetic rules apply.
  128.  
  129. Terms (the data descriptors in expressions) may be a sub-expression (an
  130. expression enclosed in parentheses) or one of the following:
  131.  
  132. --- Literals ---
  133.  
  134. Literals are used to express character strings and numbers:
  135.  
  136.   literal strings   e.g.,  "don't"  'Hello'  'x:'  "\x00"
  137.   numbers           e.g.,  1  12  12.4  1e-4  1.066E+3
  138.  
  139. --- References ---
  140.  
  141. References are terms that refer to variables (local variables within
  142. methods, arguments to methods, or properties), methods, arrays, or
  143. classes:
  144.  
  145.   simple symbols    e.g.,  Fred   I   J
  146.   method calls      e.g.,  Start(x,y)  Stop()
  147.   array references  e.g.,  Dallas[rev]  Pooks[12,10]
  148.   types (classes)   e.g.,  Rexx, java.lang.String, int
  149.  
  150. Blanks are not permitted between the name of a method and the '(', or
  151. between the name of an array reference and the '['.
  152.  
  153. Simple symbols found in a program can refer to a property in the current
  154. class, a local variable, a method in the current class (if it takes no
  155. arguments and is not a constructor), a keyword, or a type (class).
  156.  
  157. --- Compound references ---
  158.  
  159. The various forms of reference may be combined together with the '.'
  160. connector to form compound references.  Syntactically, any combination
  161. is valid, though some may be invalid semantically.  The following are
  162. examples of syntactically valid compound references:
  163.  
  164.   myaddress.street
  165.   list[3].length
  166.   is.openstream
  167.   Rexx.x2c('fade')
  168.   "abc".pos('b')
  169.  
  170. In general, the semantics of a compound reference follow the rules of
  171. Java.  A compound reference must start with a string, a sub-expression,
  172. a reference or a type, where the type may be qualified (include a
  173. package name).  Each piece after the next connector can further refine
  174. the term, returning a reference or (optionally, if it is the final part
  175. of a term) a value. The end result of a term is therefore either a type,
  176. a typed object reference, or a typed value.
  177.  
  178. Blanks are not permitted adjacent to connectors.  The parentheses
  179. indicating a method call may be omitted in compound references if the
  180. method takes no arguments and is not a constructor (optionally, they can
  181. be made to be required, using OPTIONS STRICTARGS).
  182.  
  183.  
  184. Types and Variables
  185. """""""""""""""""""
  186. NetRexx variables all follow the same syntax rules, but are used in
  187. different contexts.  These are:
  188.  
  189.   o Properties: variables that are associated with a class or an
  190.     instance of a class (an object).  When an object is constructed, its
  191.     properties are created and are usually initialized to some value.
  192.     Properties may be STATIC, which means that they are associated with
  193.     a class and are initialized when the class is first loaded, or
  194.     CONSTANT, which means that they are static and do not change after
  195.     initialization.
  196.  
  197.   o Method arguments: when a method is invoked, arguments may be passed
  198.     to it.  These arguments are assigned to variables for use within the
  199.     method.  Often, these arguments will be references to objects known
  200.     to the caller.
  201.  
  202.   o Local variables: variables that are local to a method; each time a
  203.     method is invoked a distinct set of local variables is used (as
  204.     when using the PROCEDURE instruction in Rexx).
  205.  
  206. NetRexx includes the concept of types (classes), though substantial
  207. programs and applets can be written without introducing explicit type
  208. declarations.
  209.  
  210. The type of a NetRexx variable is determined by the type of the value of
  211. the expression that is first assigned to it ('first' is determined
  212. statically by position in a program rather than dynamically).  For
  213. subsequent assignments, it is an error to assign a value to a variable
  214. with a type mismatch unless the language processor can determine that
  215. the value can be assigned safely.
  216.  
  217. In practice, this means that the types must match exactly, or they must
  218. be a 'well-known' type such as Rexx, String, int, (etc.) for which
  219. safe conversions are defined.  An object can also always be assigned to
  220. a type which is a superclass of the object's type.
  221.  
  222. Optionally, a stricter rule for assignment (where the types must be
  223. identical) may be applied, using OPTIONS STRICTASSIGN.
  224.  
  225. Objects in NetRexx are created by calling a 'constructor method' which
  226. has the same name as the class.  The syntax for calling a constructor
  227. method is essentially the same as a function call in Rexx and other
  228. languages.
  229.  
  230. For example, if there are classes called 'ibm.util.hex', 'RunKnown', and
  231. 'Window':
  232.  
  233.   hexy=ibm.util.hex(3)   -- 'hexy' has type 'ibm.util.hex'
  234.   rk=RunKnown()          -- 'rk' has type 'RunKnown'
  235.   fred=Window(10, 20)    -- 'fred' has type 'Window'
  236.   s="Hello world"        -- 's' has type 'Rexx'
  237.   j=5                    -- 'j' has type 'Rexx', as if written j="5"
  238.  
  239. The last two examples above illustrate that, by default, the types of
  240. literal strings and numbers are Rexx and so variables tend to be of a
  241. Rexx type.  This allows the language to remain simple and easy to learn,
  242. as many useful programs can be written solely using the Rexx type.
  243. Potentially more efficient (though of course less human-oriented) binary
  244. representations of literals can optionally be selected to be the
  245. default by using OPTIONS BINARY.  In this case, in a Java environment,
  246. the types of 's' and 'j' above would have been 'java.lang.String' and
  247. 'int' respectively.
  248.  
  249. A variable may be introduced ('declared') without giving it an initial
  250. value by simply assigning a type to it:
  251.  
  252.   i=int
  253.   j=Window
  254.  
  255. The type of a value may be overridden (if required) by 'conversions'
  256. (sometimes called 'casting').  This syntax for a conversion is the
  257. same as the Rexx "blank operator": when the left-hand-side of a blank
  258. operator is a type (class name, perhaps with dimensions) then the
  259. operation assigns a type to the right-hand-side term of the operator.
  260. For example:
  261.  
  262.   int 7.0
  263.   int 7.3**5
  264.   Exception e
  265.   Complex vector
  266.  
  267. The priority (precedence) of the conversion operator is the same as when
  268. it means concatenate-with-blank; it is lower than arithmetic operators
  269. but higher than logical operators.
  270.  
  271. You can test whether the type of a given object can be converted to
  272. another type using the '<=' (or '>=') operators.  For example:
  273.  
  274.   if i<=Object then say 'I is an instance of Object'
  275.   if String>=i then say 'I is an instance of String'
  276.  
  277. This also works for testing whether one type is the subclass (or the
  278. same as) another:
  279.  
  280.   if String<=Object then say 'String is an Object'
  281.  
  282. If the conversion is known to be impossible at 'compile time', then an
  283. error will be reported at that time.
  284.  
  285. Certain types (such as 'int' in the examples above) may be defined as
  286. 'primitive' by the underlying environment, and this may affect their
  287. semantics (objects of a primitive type may be passed by value rather
  288. than by reference, for example).  However, NetRexx makes no distinction
  289. of syntax for primitive types.
  290.  
  291. An implementation of NetRexx can determine automatically from knowledge
  292. of primitive types (and other factors) when an object is being
  293. constructed, so there is no 'new' operator.  As in Rexx, both storage
  294. allocation and storage reclamation are automatic.
  295.  
  296. --- The scope of variables ---
  297.  
  298. In order for types to be determined and type-checking to be possible at
  299. 'compile-time', and easily determined by inspection, variable typing is
  300. static in scope:
  301.  
  302.   o Within a class, properties have unique names (they cannot be
  303.     overridden by method arguments or by local variables within
  304.     methods); this avoids error-prone ambiguity.
  305.  
  306.     The type of a property is determined from the expression (which may
  307.     be just a type) that is assigned to it.  Properties can only be
  308.     introduced before the first method in a class.
  309.  
  310.   o Within a method, a method argument acts like a local variable (that
  311.     is, it is in the same name space as local variables); it can be
  312.     considered to be a local variable that is assigned a value just
  313.     before the body of the method is executed.
  314.  
  315.   o Within methods, variables can take only one type, the type assigned
  316.     to them when first encountered in the method (in a strict 'physical'
  317.     sense, that is, as parsed from top to bottom).  Since methods tend
  318.     to be small, there is no local scoping of variables inside the
  319.     blocks within a method.  Thus, unlike in Java, in this example:
  320.  
  321.       method iszero(x)
  322.         if x=0 then qualifier='is zero'
  323.                else qualifier='is not zero'
  324.         say 'The argument' qualifier'.'
  325.  
  326.     the variable "qualifier" is known throughout the method and has a
  327.     value when the SAY instruction is executed.
  328.  
  329. Within a NetRexx program, variable names are caseless (for example, the
  330. names 'Fred' and 'FRED' refer to the same variable).  Where public names
  331. are exposed (for example the names of properties, classes, and methods,
  332. and in cross-reference listings) the case used for the name will be that
  333. used when the name was first introduced.
  334.  
  335.  
  336. Type checking and method resolution
  337. """""""""""""""""""""""""""""""""""
  338. As outlined above, type checking in NetRexx is generally more relaxed
  339. than in Java (String and Rexx classes may be freely inter-assigned, for
  340. example), following the principle that assignments that do not lose
  341. information from data should normally be allowed.  Permitted assignments
  342. are detailed later in this section.
  343.  
  344. For some applications, a discipline of strict type checking may be an
  345. advantage, and for these, NetRexx provides the STRICTASSIGN option.
  346. This strict checking is stronger than in Java, in that types much match
  347. exactly.
  348.  
  349. The type checking (normal or strict) is also carried over into method
  350. resolution (determining which method in a class best fits a given method
  351. invocation).  In summary, this works as follows:
  352.  
  353.   1. The class of the object on which the method is being invoked is
  354.      determined.
  355.  
  356.   2. Candidate methods in the class are selected.  They must have the
  357.      the same name and the same number of arguments as the method
  358.      invocation, and it must be possible to assign the result of each
  359.      argument expression to the corresponding argument in the method
  360.      description (if strict assignment checking is in effect, the types
  361.      must match exactly).
  362.  
  363.   3. If there are no candidate methods then the superclass of the
  364.      current class is chosen and step 2 is repeated.  If there is no
  365.      superclass (that is, all superclasses have been tried), an error is
  366.      reported.
  367.  
  368.   4. If there is just one candidate method, that method is used; the
  369.      search is complete.  Note that in this case superclasses of the
  370.      current class are not searched for methods, even though a
  371.      lower-cost method may exist at a higher level.
  372.  
  373.   5. If there is more than one candidate method, the 'cost' of the
  374.      assignments from expressions to arguments is computed for each
  375.      method (see below).  If one has a lower cost than all others, that
  376.      method is used and the search is complete.  If there are two or
  377.      more with the same minimum cost, and 'ambiguous method invocation'
  378.      error is reported.
  379.  
  380. --- Cost of a method invocation ---
  381.  
  382. The cost of a method invocation is the sum of the costs of the
  383. assignments from each invocation argument expression to the
  384. corresponding method arguments.  The cost of an assignment is 0 if the
  385. types match exactly, 1 if the assignment can be made without invoking a
  386. conversion method, but the types do not match exactly (for example
  387. assigning an 'int' to a 'long'), and 2 if an assignment would require
  388. the invocation of a conversion method (for example, assigning an 'int'
  389. to a 'Rexx' string).
  390.  
  391. More generally, NetRexx 'costs' conversions of all types, where
  392. applicable, and may use those costings in other conversion situations.
  393. Further tuning of the costing algorithms can be expected.
  394.  
  395. --- Permitted assignments (automatic conversions) ---
  396.  
  397. Unless OPTIONS STRICTASSIGN is in effect, the following assignments are
  398. permitted (this list may be expanded in the future):
  399.  
  400.   String         -> Rexx, char[], or char
  401.   char[]         -> Rexx, String, or char
  402.   char           -> Rexx, String, or char[]
  403.   Rexx           -> primitive, char[], String, or char
  404.   primitive      -> Rexx, String, char[], or char
  405.   primitive      -> primitive (if no loss of information can take place)
  406.   Any type       -> exactly matching type
  407.   Any type       -> superclass of type (or an interface implemented by
  408.                     the type or a superclass)
  409.   null           -> any non-primitive
  410.  
  411. In the above:
  412.  
  413.   o 'String' is the class java.lang.String
  414.   o 'char' is a primitive type, treated as a one-character string
  415.   o 'Rexx' is the class netrexx.lang.Rexx
  416.   o 'primitive' means any of the Java primitive binary types (int, char,
  417.      long, etc.)
  418.   o 'null' is a null reference; assigning it to a variable is equivalent
  419.      to making the variable uninitialized.
  420.  
  421. Some of the conversions can cause a run-time error (exception), as when
  422. a Rexx string contains a number that is too large for an int and a Rexx
  423. to int conversion is attempted.
  424.  
  425. The boolean primitive is treated as in Rexx: a boolean is a number that
  426. may only take the values 0 or 1.  A boolean may therefore be assigned to
  427. any primitive type, as well as to String or Rexx.
  428.  
  429. --- Case of method, property, and class names ---
  430.  
  431. In NetRexx, the lookup of public names will be both case-preserving and
  432. caseless.  If a class or method is referenced by the name 'Foo', for
  433. example, an exact-case match will first be tried at each point that a
  434. search is made.  If this succeeds, the search is complete. If it is does
  435. not succeed, a caseless search in the same context is carried out, and
  436. if one item is found, then the search is complete.  If more than one
  437. item matches then an 'ambiguous reference' error is reported.
  438.  
  439. At present, lookup of external names is case-sensitive; when this
  440. restriction is lifted, for applications that require exceptional
  441. robustness, OPTIONS STRICTCASE may be specified to require that all name
  442. matches are exact (case-sensitive).
  443.  
  444.  
  445. Methods and constructors
  446. """"""""""""""""""""""""
  447. Methods all follow the same syntax rules (see the description of the
  448. METHOD instruction, elsewhere), and are usually invoked in context of an
  449. existing object.  A special kind of method, called a constructor method,
  450. is used to actually create an object.
  451.  
  452. Constructor methods always have the same name as the class in which they
  453. are found, and construct an object of that class.  There will always be
  454. at least one constructor if objects are to be created (NetRexx will add
  455. a default constructor that takes no arguments if none are provided).
  456. All constructors follow the following rules:
  457.  
  458.   1. Constructors must call a constructor of their superclass before
  459.      they carry out any initialization of their own (this is so any
  460.      initialization carried out by the superclass takes place at the
  461.      appropriate moment).  Therefore the first instruction in a
  462.      constructor must be either a call to super() (with optional
  463.      arguments), or a call to this() (with optional arguments).  In the
  464.      latter case, another constructor in the same class is called;
  465.      eventually one that explicitly calls super() will be invoked and
  466.      the chain of local constructor calls ends.
  467.  
  468.      As a convenience, NetRexx will add a default call to super() if the
  469.      first instruction in a constructor is not a call to this() or
  470.      super().
  471.  
  472.   2. By definition, constructors create an object of the current class
  473.      and return it.  Therefore, the RETURNS keyword on the method
  474.      instruction is optional (if specified, the RETURNS type must match
  475.      the class), and the only possible forms of the RETURN instruction
  476.      on a constructor are either 'return this' or 'return' -- in the
  477.      latter case, the 'this' is assumed (this form will be assumed at
  478.      the end of a method, as usual, if necessary).
  479.  
  480. Here is an example of a class with two constructors, showing the use of
  481. this() and super(), and taking advantage of the assumptions:
  482.  
  483.   class MyChars
  484.  
  485.     properties private
  486.       value=char[]            -- the data 'in' the object
  487.  
  488.     method MyChars(c=char[])  -- construct the object from a char array
  489.       super()                 -- initialize superclass (in this case Object)
  490.       value=c                 -- record the value (without copying)
  491.  
  492.     method MyChars(s=String)  -- construct the object from a String
  493.       this(s.toCharArray())   -- convert to char[] and use the above
  494.  
  495. Objects of type 'MyChars' could then be created thus:
  496.  
  497.     myvar=MyChars("From a string")
  498.  
  499. or by using an argument that has type char[].  Note that all references
  500. to constructors must be identified by the use of parentheses, to
  501. distinguish them from references to the type (class) of the same name.
  502.  
  503.  
  504. Special names and methods
  505. """""""""""""""""""""""""
  506. For convenience, NetRexx provides some special names for naming
  507. commonly-used concepts within terms.  These are only recognized if there
  508. is no variable of the same name previously seen in the current scope
  509. (this allows the set of special words to be expanded in the future, if
  510. necessary, without invalidating existing variables).  These names are
  511. not reserved; they may be used as variable names instead, if desired.
  512.  
  513. There are also two 'special methods' that are used when constructing
  514. objects, and constructors for the primitive types.
  515.  
  516. --- Special names ---
  517.  
  518. The following special names are allowed in NetRexx programs.
  519.  
  520.   o ask -- returns a Rexx string, read from the standard input stream
  521.     (usually the user's "console").  For example:
  522.  
  523.       if ask='yes' then say 'OK'
  524.  
  525.     In the Java environment, ask is simply a shorthand for 'RexxIO.Ask()'.
  526.  
  527.   o digits -- the current setting of numeric digits, returned as a Rexx
  528.     string.
  529.  
  530.   o form -- the current setting of numeric form, returned as a Rexx
  531.     string.
  532.  
  533.   o length -- represents the length of an array.  For example:
  534.  
  535.       foo=char[7]
  536.       say foo.length     /* would say '7' */
  537.  
  538.     Note that you can get the length of a String or Rexx object with the
  539.     same syntax (unless OPTIONS STRICTARGS is in effect).  In these
  540.     cases, however, a length() method is being invoked.
  541.  
  542.   o null -- the 'empty reference'.  This represents "no value" and may
  543.     be assigned to variables that refer to classes, or may be used in a
  544.     comparison for equality (or inequality).  For example:
  545.  
  546.       blob=int[3]        /* 'blob' refers to an array of 3 ints */
  547.       blob=null          /* 'blob' is still of type int[], but refers to
  548.                             no real object */
  549.  
  550.     The 'null' value may be considered to represent the state of being
  551.     uninitialized.  That is, the state of a variable after DROP in Rexx.
  552.  
  553.   o source -- returns a Rexx string identifying the source of the
  554.     current class.  The first two words of the string are 'Java method',
  555.     identifying the environment, and the third is the name of the
  556.     sourcefile (e.g., 'Fred.nrx').
  557.  
  558.     If 'options binary' is in effect, a java.lang.String is returned.
  559.  
  560.   o super -- refers to the current object, except that a search for
  561.     methods or properties which it qualifies will start from the
  562.     superclass rather than in the current class.  This is used for
  563.     invoking a method or property (in the superclass or one of its
  564.     superclasses) that has been overridden in the current class.  For
  565.     example:
  566.  
  567.       method printit(x)
  568.         say 'it'              -- modification
  569.         super.printit(x)      -- and now the usual processing
  570.  
  571.     super can only appear as the first item in a compound reference
  572.     term.
  573.  
  574.   o this -- refers to the current object.  When a method is invoked, for
  575.     example in:
  576.  
  577.       word="hello"            /* 'word' now refers to "hello" */
  578.       say word.substr(3)      /* invokes substr method on "hello" */
  579.  
  580.     then the method 'substr' in class Rexx is started, with argument
  581.     '3', and with the properties of the object "hello" available to it.
  582.     These may be accessed simply by name, or (more explicitly) by
  583.     prefixing the name with 'this.'.  Using 'this.' often makes a method
  584.     more readable, especially when several objects of the same type are
  585.     being manipulated in a method.
  586.  
  587.     If a property being referenced is in fact owned by a superclass of
  588.     the current class, then then prefix 'this.' is the simplest way to
  589.     indicate that name refers to a property rather than to a local
  590.     variable.  (You could also qualify it by 'super.', or the name of
  591.     the superclass.)
  592.  
  593.   o trace -- the current TRACE setting
  594.  
  595.   o version -- returns a Rexx string identifying the version of the
  596.     language processor that generated the current class.  This consists
  597.     of five words delimited by blanks:
  598.  
  599.     1. A word describing the language.  The first seven letters will be the
  600.        characters 'NetRexx', and the remainder may be used to identify a
  601.        particular implementation or language processor.  This word may
  602.        not include any periods.
  603.  
  604.     2. The language level description.  For example, '1.01'.
  605.  
  606.     3. Three tokens describing the language processor release date in
  607.        the same format as the default for the Rexx date() function.  For
  608.        example, '3 Jan 1997'.
  609.  
  610.     If 'options binary' is in effect, a java.lang.String is returned.
  611.  
  612. With the exception of 'length', the special names may only be used alone
  613. or as the first item in a compound reference.
  614.  
  615. --- Special methods ---
  616.  
  617. Constructors (methods used for constructing objects) in NetRexx
  618. must invoke a constructor of their superclass before making any
  619. modifications to the current object (or invoke another constructor in
  620. the current class).
  621.  
  622. This is simplified and made explicit by the provision of the special
  623. method names 'super' and 'this', which refer to constructors of the
  624. superclass and current class respectively.  These special methods are
  625. only recognized when used as the first, method call, instruction in a
  626. constructor.  See "Methods and constructors".
  627.  
  628. In addition, NetRexx provides special constructors for the primitive
  629. types that allow bitwise construction of primitives.  For example:
  630.  
  631.   i=int 77
  632.   c=char(i)    -- c is now the character 'M'
  633.   j=int(c)     -- j is now the integer 77
  634.  
  635. Note that the conversion
  636.  
  637.   j=int c
  638.  
  639. would have failed, as 'M' is not a number.  The argument to a primitive
  640. constructor must be a primitive.
  641.  
  642.  
  643. Arrays
  644. """"""
  645. NetRexx includes the concept of arrays (ordered references to objects of
  646. the same type, indexed by integers).  In the Java environment, arrays
  647. are constrained to be fixed size, and are indexed by integers with the
  648. first item in the array having the index 0.
  649.  
  650. Individual objects of class Rexx also support an associative array
  651. lookup mechanism (where the index is not constrained to be just
  652. integers), equivalent to Rexx stems; this is described in the next
  653. section.
  654.  
  655. Arrays are indicated in NetRexx syntax by the use of square brackets, [],
  656. and are constructed just like other objects except that brackets are
  657. used instead of parentheses:
  658.  
  659.   arg=String[4]     -- makes an array of four Strings
  660.   i=int[3]          -- makes an array of three 'int's
  661.  
  662. Brackets are used conventionally for referring to a member of an array:
  663.  
  664.   i[2]=3            -- sets the '2'-indexed value of 'i'
  665.   j=i[2]            -- sets 'j' to the '2'-indexed value of 'i'
  666.  
  667. Regular multiple-dimensioned arrays may be constructed and referenced by
  668. using multiple expressions within the brackets, separated by commas:
  669.  
  670.   i=int[2,3]        -- makes a 2x3 array of 'int' type objects
  671.   i[2,2]=3          -- sets the '2,2'-indexed value of 'i'
  672.   j=i[2,2]          -- sets 'j' to the '2,2'-indexed value of 'i'
  673.  
  674. The type of a variable that refers to an array can be set (declared) by
  675. assignment of the type with array notation that indicates the dimension
  676. of an array without an initial size or sizes:
  677.  
  678.   k=int[]           -- one-dimensional array of 'int' objects
  679.   m=float[,,]       -- three-dimensional array of 'float' objects
  680.  
  681. The same syntax is also used when describing an array type in the
  682. arguments of a METHOD instruction or when converting types.
  683.  
  684.  
  685. Indexed variables
  686. """""""""""""""""
  687. All objects of class Rexx which are not fixed-dimension arrays support
  688. an associative array lookup mechanism (where the index is not
  689. constrained to be just integers), equivalent to stems in Rexx.  The
  690. syntax is the same as for arrays, with one or more index expressions
  691. separated by commas within the square brackets.  Each index must be a
  692. Rexx string (if not, it will be converted to a Rexx string).  For
  693. example:
  694.  
  695.   surname='Unknown'           -- default value
  696.   surname['Fred']='Bloggs'
  697.   surname['Davy']='Jones'
  698.   try='Fred'
  699.   say surname[try] surname['Bert']
  700.  
  701. would say "Bloggs Unknown".
  702.  
  703. The indexes in the example are single words, however they may be any
  704. character string.  Index strings are taken 'as-is' -- that is, they must
  705. match exactly in case and length for a reference to find a
  706. previously-set item.
  707.  
  708. Before using associative array indexing on a Rexx object, the object
  709. must exist; the value of the object is used as the default value
  710. whenever an associative reference finds no explicit value.
  711.  
  712.  
  713. Clauses
  714. """""""
  715. A NetRexx program is parsed into clauses (most often delimited by
  716. end-of-line, but also by semicolon and certain keywords), following Rexx
  717. rules.  Recognizing that command strings to environments are now often
  718. replaced by other forms of messages, NetRexx does not assume that any
  719. clause that is an expression is a command string.  This frees several
  720. combinations of syntax for other uses.
  721.  
  722. Forms of clause that are currently defined are:
  723.  
  724.   Null clauses: any empty clause.  These are ignored, as in Rexx, and
  725.     can never affect the execution of a NetRexx program.
  726.  
  727.   Method clause: a clause with the syntax of a single term of which the
  728.     last or only part resolves to a method call.
  729.  
  730.   Assignment: a clause consisting of a single term, followed by an '='
  731.     character and an expression.  An assignment introduces a variable
  732.     and sets its type if the target is a simple symbol and it is the
  733.     first occurrence of that variable name in a context.
  734.  
  735.   Keyword instruction: a clause that is not one of the above and is
  736.     introduced by a simple symbol that is a keyword known to NetRexx.
  737.     The rules for keyword safety are stronger than in Rexx: a keyword
  738.     (or sub-keyword) in NetRexx will only be recognized if it is not the
  739.     name of a known variable.
  740.  
  741. There are no label clauses (e.g., 'fred:') in NetRexx; labels for blocks
  742. are given on the instruction that starts the block.
  743.  
  744.  
  745. Keyword instructions
  746. """"""""""""""""""""
  747. The following short descriptions of keyword instructions show examples
  748. of syntax, not syntax rules.  Keywords are indicated by upper case,
  749. though may be written in lower or mixed case.  Sub-keywords may not be
  750. repeated.
  751.  
  752. CATCH instruction
  753. '''''''''''''''''
  754. Syntax:
  755.  
  756.   CATCH ZeroDivide
  757.   CATCH zd=ZeroDivide
  758.  
  759. (See 'Exceptions' section for details.)   If no variable is specified,
  760. the exception will be caught but not saved for processing.  The variable
  761. used in a CATCH instruction must be a simple name (not an array
  762. reference or other term), and refers to a variable or property in the
  763. current class.
  764.  
  765. CLASS instruction
  766. '''''''''''''''''
  767. Syntax:
  768.  
  769.   CLASS Biped
  770.   CLASS blob   EXTENDS Object
  771.   CLASS ape    EXTENDS Biped  IMPLEMENTS Sitting, Standing
  772.   CLASS calc   EXTENDS Rexx   USES Math
  773.   CLASS RexxOperators INTERFACE
  774.  
  775. Introduces a class.  See 'Program Structure'.
  776.  
  777. EXTENDS names a superclass that this class extends, the default being
  778. the top of the class hierarchy ('Object').  Class 'ape' in the example
  779. is therefore a subclass of 'Biped', which is a subclass of 'Object'.
  780.  
  781. IMPLEMENTS lists one or more interface classes that this class
  782. implements (see Java documentation for a description of interfaces).
  783. The INTERFACE keyword declares a class to be an interface.
  784.  
  785. USES lists one or more classes which will be searched for constants,
  786. static properties, and functions when the first part of a term is
  787. unresolved.
  788.  
  789. Several other keyword options are allowed:
  790.  
  791.   o PUBLIC -- the class is public (visible outside the program).  There
  792.     must be one public class in a program; by default, the first class
  793.     in a program is assumed to be PUBLIC.
  794.  
  795.   o PRIVATE -- the class is only visible inside this program.  This is
  796.     the default for the second and subsequent classes in a program.
  797.  
  798.   o ABSTRACT -- the class is abstract (that is, some or all of its
  799.     methods have no body and must be specified by a subclass).  An
  800.     abstract class cannot have instances.
  801.  
  802.   o FINAL -- the class cannot be subclassed.
  803.  
  804. DO instruction
  805. ''''''''''''''
  806. Syntax:
  807.  
  808.   DO
  809.   DO LABEL frank
  810.   DO PROTECT someobject
  811.  
  812. DO ... END is the simple grouping construct.  Looping forms of the DO
  813. from Rexx use the LOOP keyword in NetRexx.
  814.  
  815. If a LABEL is specified on the DO, then a LEAVE which specifies that
  816. label may be used to leave the DO group, and the END that ends the block
  817. may optionally specify the label of the DO group for additional
  818. checking.  For example:
  819.  
  820.   do label sticky
  821.     ...
  822.     if x then leave sticky
  823.     ...
  824.     end sticky
  825.  
  826. If PROTECT is given it is followed by a term that must resolve to an
  827. object reference; while the DO group is being executed, the object is
  828. protected -- that is, the code in the DO group has exclusive access to
  829. the object.
  830.  
  831. Both PROTECT and LABEL may be specified, if needed.
  832.  
  833. CATCH and FINALLY can be used with DO (see "Exceptions" section for
  834. details).
  835.  
  836. EXIT instruction
  837. ''''''''''''''''
  838. Syntax:
  839.  
  840.   EXIT expression
  841.  
  842. As in Rexx; the expression, if present, is returned to the environment
  843. as a string.  The environment may place further restrictions (such as
  844. requiring that the string be convertible to some small integer), and may
  845. provide a default.  Note that EXIT is global, in that all objects and
  846. classes currently active will be lost; it should normally only be used
  847. in stand-alone applications.
  848.  
  849. FINALLY instruction
  850. '''''''''''''''''''
  851. Syntax:
  852.  
  853.   FINALLY
  854.  
  855. (See "Exceptions" section for details.)  A semicolon is assumed after
  856. FINALLY.
  857.  
  858. IF instruction
  859. ''''''''''''''
  860. Syntax:
  861.  
  862.   IF a=b THEN i=1; ELSE i=2
  863.  
  864. As in Rexx.
  865.  
  866. IMPORT instruction
  867. ''''''''''''''''''
  868. Syntax:
  869.  
  870.   IMPORT ibm.rexx.Rexx
  871.   IMPORT ibm.rexx.
  872.  
  873. Similar to Java; if the term given ends in a name, a single class is
  874. imported.  If it ends in a dot, then an entire package is imported.  In
  875. this latter case, full importation of sub-trees is assumed (that is,
  876. 'IMPORT ibm.' would import all subtrees of the 'ibm.' packages).  In the
  877. Java environment, "import netrexx." and "import java." are assumed.
  878.  
  879. IMPORT is considered to be an 'environment-dependent' instruction at
  880. present.
  881.  
  882. ITERATE and LEAVE instructions
  883. ''''''''''''''''''''''''''''''
  884. Syntax:
  885.  
  886.   ITERATE
  887.   ITERATE name
  888.   LEAVE
  889.   LEAVE name
  890.  
  891. As in Rexx.  These are only allowed within a LOOP construct, except that
  892. LEAVE with a name can also be used to leave labelled DO and SELECT
  893. groups.
  894.  
  895. LOOP instruction
  896. ''''''''''''''''
  897. Syntax:
  898.  
  899.   LOOP
  900.   LOOP FOREVER
  901.   LOOP FOR count
  902.   LOOP i=1 TO 10 BY 3 FOR n
  903.   LOOP j=1 TO 100 WHILE k<7
  904.   LOOP index OVER collection
  905.  
  906.  
  907. LOOP ... END is the NetRexx repetition construct.  LOOP follows the
  908. rules of Rexx and Object Rexx repetitive DO, except that the control
  909. variable must be a simple name (not an array reference or other term)
  910. that does not conflict with a label or control variable at an outer
  911. level.  A control variable must also always be a variable or property in
  912. the current class.
  913.  
  914. WHILE and UNTIL are allowed as in Rexx.  'LOOP' on its own means 'LOOP
  915. FOREVER'.  'LOOP FOR count' replaces 'DO count'.  CATCH and FINALLY can
  916. be used (see "Exceptions" section for details).
  917.  
  918. The FOR keyword accepts any count that can be converted to an integer
  919. (int).  Negative FOR counts are treated as zero.
  920.  
  921. LOOP OVER is used to work through the values in a collection of Rexx
  922. indexed variables or a Java Dictionary (such as a Hashtable).  The LOOP
  923. instruction takes a snapshot of the indexes into the collection, and
  924. then for each iteration of the loop the control variable ('index', in
  925. the example above) is set to the next available index.
  926.  
  927. For example:
  928.  
  929.   mycoll=''
  930.   mycoll['Tom']=1
  931.   mycoll['Dick']=2
  932.   mycoll['Harry']=3
  933.   loop name over mycoll
  934.     say mycoll[name]
  935.     end
  936.  
  937. might display:
  938.  
  939.   3
  940.   1
  941.   2
  942.  
  943. Note that the order in which the values are returned are undefined; all
  944. that is known is that all indexes available at the start of the loop
  945. will be available and assigned to 'name' in turn as the loop iterates.
  946.  
  947. The name of a loop (which may be used on END, LEAVE, and ITERATE for the
  948. loop) is the name of the control variable (if any).  Alternatively, an
  949. explicit name may be specified using the LABEL keyword; this overrides
  950. any name derived from the control variable name (that is, the variable
  951. name cannot be used to refer to the loop if a label is specified).
  952. For example:
  953.  
  954.   loop label pooks i=1 to 10
  955.     loop label hill while j<3
  956.       ...
  957.       if a=b then leave pooks
  958.       ...
  959.       end hill
  960.     end pooks
  961.  
  962. In this example, the LEAVE instruction leaves both loops.
  963.  
  964. As with DO and SELECT, the PROTECT keyword may be used at the start of a
  965. LOOP instruction.  If used, PROTECT is followed by a term that must
  966. resolve to an object reference; while the loop is being executed, the
  967. object is protected -- that is, the code in the loop has exclusive
  968. access to the object.  For example:
  969.  
  970.   loop protect myobject while a<b
  971.     ...
  972.     end
  973.  
  974. Both PROTECT and LABEL may be specified, if needed.
  975.  
  976. METHOD instruction
  977. ''''''''''''''''''
  978. Syntax:
  979.  
  980.   METHOD arca
  981.   METHOD fred(i)
  982.   METHOD kitt(foo, bar)
  983.   METHOD kitt(foo, bar=3)
  984.   METHOD jack(i=int, j=long 3) RETURNS int
  985.   METHOD jill(i=int[,,], j=int) RETURNS int[]
  986.   METHOD soup(i) SIGNALS Exception, DivideByZero
  987.  
  988. Introduces a method.  See "Program Structure" for a description of
  989. methods.
  990.  
  991. The arguments part of a METHOD instruction, in parentheses immediately
  992. following the method name, is optional and defines a list of the
  993. arguments for the method.  In this list, each argument must be given a
  994. name (which must not be the same as the name of any property in the
  995. class).  Each argument is also optionally assigned a type and default
  996. value, using the usual rules of assignment.  If there is no assignment,
  997. the type of the argument is assumed to be 'Rexx' (netrexx.lang.Rexx).
  998.  
  999. If there is no '=', or the expression to the right of the '=' returns
  1000. just a type, the argument is required (that is, it must always be
  1001. specified by the caller when the method is invoked).  If an explicit
  1002. value is given by the expression (as in the second "kitt" example above)
  1003. then the argument is optional; if the caller does not provide it, then
  1004. the value of the expression will be provided to the method instead.
  1005.  
  1006. In the Java implementation of NetRexx, optional arguments may be omitted
  1007. 'from the right' only.  That is, arguments may not be omitted to the
  1008. left of arguments that are not omitted.
  1009.  
  1010. RETURNS describes the type of the result, which must be specified if the
  1011. RETURN instructions in a method are to provide a result other than of
  1012. type Rexx.
  1013.  
  1014. SIGNALS lists the types of exceptions that the method may signal.
  1015.  
  1016. Several other keyword options are allowed:
  1017.  
  1018.  o PUBLIC (the default) -- the method is visible outside the class.
  1019.  
  1020.  o INHERITABLE -- the method is visible outside the class, but only to
  1021.    subclasses of the class.
  1022.  
  1023.  o PRIVATE -- the method is only visible within the class.
  1024.  
  1025.  o STATIC -- the method is a class method (also known as a function).
  1026.    Static methods are invoked by giving the name of the class followed
  1027.    by the method, for example:
  1028.  
  1029.      Math.sin(1.3)  -- calls method sin(..) in class Math
  1030.  
  1031.    (the name of the class may be omitted if it is listed in the USES
  1032.    phrase of the CLASS instruction).
  1033.  
  1034.    Static methods are useful for providing function that is not
  1035.    associated with an object.  They cannot be overridden in a subclass.
  1036.  
  1037.  o PROTECT -- the method will have exclusive access to the current
  1038.    object (or the class, if a static method) while it runs.
  1039.  
  1040.  o ABSTRACT -- the method has no body; the method instruction is just
  1041.    defining a template for the method.  This is the default for methods
  1042.    within an INTERFACE class.
  1043.  
  1044.  o FINAL -- the method cannot be overridden by a subclass.
  1045.  
  1046.  o NATIVE -- the method is implemented by the environment.  NATIVE
  1047.    methods have no body.
  1048.  
  1049. Constructor methods (where the method name exactly matches the class
  1050. name) are allowed; their return type is assumed to be that of the class,
  1051. and they simply create and modify 'this'.  The first non-null clause in
  1052. a constructor method may be a method call instruction where the method
  1053. name is either 'this' or 'super', except if the class name is 'Object'.
  1054. Note that 'this' and 'super' are valid method names only in this one
  1055. context.  See "Methods and constructors" for more details.
  1056.  
  1057. NOP instruction
  1058. '''''''''''''''
  1059. Syntax:
  1060.  
  1061.   NOP
  1062.  
  1063. No operation, as in Rexx.
  1064.  
  1065. NUMERIC instruction
  1066. '''''''''''''''''''
  1067. Syntax:
  1068.  
  1069.   NUMERIC DIGITS n
  1070.   NUMERIC FORM keyword
  1071.  
  1072. Affects operations on objects of type Rexx only; DIGITS sets arithmetic
  1073. precision; FORM sets the format of exponential notation to 'scientific'
  1074. or 'engineering'.
  1075.  
  1076. NUMERIC may appear as a dynamically executed instruction in a
  1077. method.  It may also appear before the first method in a class, in which
  1078. case it forms the default setting for the initialization of subsequent
  1079. properties in the class and for all methods in the class.
  1080.  
  1081. NUMERIC cannot be used if OPTIONS BINARY is in effect.
  1082.  
  1083. OPTIONS instruction
  1084. '''''''''''''''''''
  1085. Syntax:
  1086.  
  1087.   OPTIONS option-word-list
  1088.  
  1089. Sets processor-dependent translator options.  The OPTIONS instruction
  1090. applies to the whole program, and must come before the first CLASS
  1091. instruction (or any instruction that starts a class).  The allowed
  1092. option words, which are case-insensitive, are:
  1093.  
  1094.   BINARY       -- assign literals binary (primitive) or String types,
  1095.                   rather than Rexx types, and use native binary
  1096.                   operations to implement operators.  When NOBINARY is
  1097.                   in effect, terms in expressions are converted to Rexx
  1098.                   types before use by operators.
  1099.   CROSSREF     -- display cross-reference listings of variables, by
  1100.                   class.
  1101.   DIAG         -- display diagnostic information (for development use
  1102.                   only).
  1103.   FORMAT       -- format the output file for better readability.  Note
  1104.                   that if this option is in effect, line numbers from
  1105.                   the input file will not be preserved (so run-time
  1106.                   errors and exception tracebacks may show incorrect
  1107.                   line numbers).
  1108.   REPLACE      -- allow replacement of the output (.java) file.  The
  1109.                   default, NOREPLACE, prevents an existing .java file
  1110.                   being accidentally overwritten.
  1111.   STRICTARGS   -- require that method invocations always specify
  1112.                   parentheses, even when no arguments are supplied.
  1113.   STRICTASSIGN -- only allow exact type matches in assignments (this is
  1114.                   stronger than Java requirements).  This also applies
  1115.                   to the arguments in method calls.
  1116.   STRICTCASE   -- require that name matches be exact in case.
  1117.   STRICTSIGNAL -- require that uncaught checked exceptions be treated as
  1118.                   an error.
  1119.   TRACE        -- enables tracing (use NOTRACE to prevent tracing
  1120.                   overheads, even if TRACE appears in program).
  1121.   VERBOSEn     -- set the 'noisiness' of the processor (n=0 to 5; if
  1122.                   omitted, n=3).  NOVERBOSE and VERBOSE0 both suppress
  1123.                   all informative messages.
  1124.  
  1125. Prefixing any of the above with 'NO' turns the selected option off.  For
  1126. example:
  1127.  
  1128.   options binary nocrossref nostrictassign strictargs
  1129.  
  1130. The default settings of the various options are:
  1131.  
  1132.   nobinary crossref nodiag noformat noreplace nostrictargs
  1133.   nostrictassign nostrictcase trace verbose3
  1134.  
  1135. Multiple OPTIONS instructions are allowed.  When an option word is
  1136. repeated (in the same instruction or not) then the last use of the word
  1137. determines the state of the option.
  1138.  
  1139. All option words may also be set as command line options when invoking
  1140. the processor, by prefixing them with '-', for example:
  1141.  
  1142.   netrexxc -format -verbose4 foo.nrx
  1143.  
  1144. In this case, the options may come before or after file specifications.
  1145. Options set with the OPTIONS instruction override command-line settings.
  1146. For more information, see the installation and use documentation.
  1147.  
  1148. PACKAGE instruction
  1149. '''''''''''''''''''
  1150. Syntax:
  1151.  
  1152.   PACKAGE foo.bar.fly
  1153.  
  1154. As in Java.
  1155.  
  1156. PACKAGE is considered to be an 'environment-dependent' instruction at
  1157. present.
  1158.  
  1159. PARSE instruction
  1160. '''''''''''''''''
  1161. Syntax:
  1162.  
  1163.   PARSE term template
  1164.  
  1165. The term is evaluated and converted (if necessary) to a Rexx string.  It
  1166. is then parsed according to the template and following Rexx rules, as
  1167. defined in the ANSI Standard for Rexx.  Any values that are used in
  1168. patterns during the parse are converted to type Rexx; the results of
  1169. parsing are type Rexx.
  1170.  
  1171. Any variables used by PARSE must be a simple name (not an array
  1172. reference or other term), and refer to a variable or property in the
  1173. current class.
  1174.  
  1175. Here are some examples of PARSE:
  1176.  
  1177.   foo='now is  my time'
  1178.   parse foo a b c              /* (a=='now' & b=='is' & c==' my time')       */
  1179.   parse foo a . . c            /* (a=='now' & c=='time')                     */
  1180.   parse foo a 'my' c           /* (a=='now is  ' & c==' time')               */
  1181.   parse foo 3 a -1 b +3 c +3   /* (a=='w is  my time' & b=='ow ' & c=='is ') */
  1182.  
  1183. Please see Rexx documentation for full details of parse templates.
  1184.  
  1185. By convention (automatically if the 'main' method is generated by the
  1186. NetRexx processor), the 'main' method in a stand-alone NetRexx
  1187. application should place the command string passed to it in the Rexx
  1188. string variable called 'arg'.  Hence the instruction:
  1189.  
  1190.   parse arg template
  1191.  
  1192. will work, in a stand-alone application, in the same way as in Rexx
  1193. (even though ARG is not a keyword in this case).  Note that the command
  1194. string may have been edited by the environment; certain characters may
  1195. not be allowed, multiple blanks may have been reduced to single blanks,
  1196. etc.
  1197.  
  1198. Similarly, the special words 'ask', 'source', and 'version' allow
  1199.  
  1200.   parse ask x       -- like Rexx parse pull
  1201.   parse source x    -- uses 'Java method' followed by filename
  1202.   parse version x   -- uses 'NetRexx' followed by version and date
  1203.  
  1204. These three words may also be used within expressions.
  1205.  
  1206. PROPERTIES instruction
  1207. ''''''''''''''''''''''
  1208. Syntax:
  1209.  
  1210.   PROPERTIES PUBLIC
  1211.   PROPERTIES PRIVATE VOLATILE
  1212.   PROPERTIES CONSTANT
  1213.   PROPERTIES STATIC
  1214.  
  1215. This instruction defines the attributes of following property (instance)
  1216. variables, and therefore must precede the first METHOD instruction.  A
  1217. PROPERTIES instruction cancels previous PROPERTIES instructions (that
  1218. is, the attributes specified on PROPERTIES instructions are not
  1219. cumulative).
  1220.  
  1221. There must be at least one keyword option on PROPERTIES.  Allowed
  1222. options are INHERITABLE (the default, to encourage encapsulation),
  1223. PRIVATE, and PUBLIC, which have the same meaning as on the METHOD
  1224. instruction, and also:
  1225.  
  1226.   o CONSTANT -- the following properties define constants; their value
  1227.     is initialized when the class is loaded and may not be changed
  1228.     thereafter.
  1229.  
  1230.   o STATIC -- the following properties define variables associated with
  1231.     a class (rather than an object).  They are initialized when the
  1232.     class is loaded.
  1233.  
  1234.   o VOLATILE -- the property may change asynchronously, outside the
  1235.     control of the class.
  1236.  
  1237. The VOLATILE keyword should be considered experimental; at present, it
  1238. is only applicable to the Java environment.
  1239.  
  1240. RETURN instruction
  1241. ''''''''''''''''''
  1242. Syntax:
  1243.  
  1244.   RETURN
  1245.   RETURN value
  1246.  
  1247. As in Rexx.  The value is an expression; it must be possible to assign
  1248. the value to the type specified after the RETURNS keyword on the METHOD
  1249. instruction (if no RETURNS type was specified, the value will be
  1250. converted to type Rexx).
  1251.  
  1252. Either all the RETURN instructions in a method must return a value, or
  1253. they must all not return a value.
  1254.  
  1255. SAY instruction
  1256. '''''''''''''''
  1257. Syntax:
  1258.  
  1259.   SAY expression
  1260.  
  1261. The result of the expression is written to the standard output stream as
  1262. a single line.  If the final character of the result of the expression
  1263. is the NUL (null) character ('\-' or '\0') then SAY will write the
  1264. string without adding line termination.
  1265.  
  1266. SELECT instruction
  1267. ''''''''''''''''''
  1268. Syntax:
  1269.  
  1270.   SELECT ... WHEN ... OTHERWISE ... END
  1271.  
  1272. As in Rexx, with the addition of LABEL and PROTECT on the SELECT clause.
  1273. CATCH and FINALLY can be used (see "Exceptions" section for details).
  1274.  
  1275. If a LABEL is specified on the SELECT, then a LEAVE which specifies that
  1276. label may be used to leave the SELECT construct, and the END that ends
  1277. the SELECT may optionally specify the label of SELECT for added
  1278. checking.  For example:
  1279.  
  1280.   select label roman
  1281.     when a=b then say 'egal'
  1282.     when a<b then say 'lo'
  1283.     otherwise
  1284.       say 'hi'
  1285.       if a=0 then leave roman
  1286.       say 'a non-0'
  1287.     end roman
  1288.  
  1289. In this example, if the variable A has the value 0 and B is non-zero
  1290. then just 'hi' is displayed.
  1291.  
  1292. If PROTECT is given on the SELECT it is followed by a term that must
  1293. resolve to an object reference; while the SELECT construct is being
  1294. executed, the object is protected -- that is, the code in the SELECT
  1295. construct has exclusive access to the object.
  1296.  
  1297. Both PROTECT and LABEL may be specified, if needed.
  1298.  
  1299. SIGNAL instruction
  1300. ''''''''''''''''''
  1301. Syntax:
  1302.  
  1303.   SIGNAL IOException
  1304.   SIGNAL Exception("oh no!")
  1305.  
  1306. Used to raise (throw) an exception (see "Exceptions" section for
  1307. details), along with an optional description.  The syntax is 'SIGNAL
  1308. term'; the value of the term must be assignable to type Throwable.
  1309.  
  1310. TRACE instruction
  1311. '''''''''''''''''
  1312. Syntax:
  1313.  
  1314.   TRACE OFF
  1315.   TRACE METHODS
  1316.   TRACE ALL
  1317.   TRACE RESULTS
  1318.  
  1319. Traces nothing, entry to methods in class, all clauses, or all clauses
  1320. and results.  TRACE should be placed before the first method in a class
  1321. to affect all methods, or may be used dynamically within methods.
  1322.  
  1323. Other instructions from Rexx
  1324. ''''''''''''''''''''''''''''
  1325. This lists the Rexx keyword instructions or variations that are not
  1326. included in NetRexx, with NetRexx equivalents where appropriate.
  1327.  
  1328.   ADDRESS -- no equivalent concept.
  1329.  
  1330.   ARG -- obsolete; arguments are now defined on METHOD instructions.
  1331.  
  1332.   CALL -- use a method invocation clause "term(...)".  Any result is
  1333.   discarded.
  1334.  
  1335.   CALL ON/OFF -- replaced by exception handlers (CATCH).
  1336.  
  1337.   DO repetition-count -- use LOOP FOR.
  1338.  
  1339.   DROP -- no direct equivalent; use assignment of 'null' for
  1340.   non-primitive classes.
  1341.  
  1342.   INTERPRET -- no equivalent.
  1343.  
  1344.   NUMERIC FUZZ -- rarely used in Rexx; however, it could be added if
  1345.   demand warranted.
  1346.  
  1347.   PROCEDURE -- replaced by METHOD (local variables are automatically
  1348.   hidden; property variables are EXPOSEd automatically)
  1349.  
  1350.   PULL -- use the keyword ASK with parse, or use Java input streams
  1351.   directly.
  1352.  
  1353.   PUSH and QUEUE -- not part of the language; no 'external data queue'
  1354.   concept.
  1355.  
  1356.   SIGNAL ON/OFF -- replaced by exception handlers (CATCH).
  1357.  
  1358.  
  1359. Exceptions
  1360. """"""""""
  1361. NetRexx follows the block-oriented exception handling model of Java and
  1362. C++.  Instead of introducing a new construct, however (which can
  1363. introduce extra levels of nesting in a program), it extends the DO,
  1364. LOOP, and SELECT constructs to allow any block to include exception
  1365. handlers.
  1366.  
  1367. Specifically, where an END clause can appear in these constructs, zero
  1368. or more CATCH instructions can be used to define exception handlers,
  1369. followed by zero or one FINALLY instructions that describe 'clean-up'
  1370. code for the block.  The whole construct continues to be ended by an END
  1371. clause.  For example:
  1372.  
  1373.   if a=b then
  1374.     do                        /* could be LOOP i=1 to 10, etc. */
  1375.       j=oddone(i, j)
  1376.       say something(7)/j
  1377.     catch ZeroDivide
  1378.       say 'oddone('i','j') returned zero'
  1379.     catch ex=Exception
  1380.       /* catches everything else, probably */
  1381.       /* 'ex' is assigned the exception object */
  1382.       say 'Exception:' ex.getMessage
  1383.     finally
  1384.       say 'Done!'
  1385.     end
  1386.  
  1387. FINALLY, like OTHERWISE in SELECT, implies a semicolon after it, so the
  1388. last SAY in the example could have appeared on the same line as the
  1389. FINALLY without an intervening semicolon.
  1390.  
  1391. The SIGNAL instruction is used to raise (throw) an exception.
  1392.  
  1393.  
  1394. Program Structure
  1395. """""""""""""""""
  1396. A NetRexx program permits the definition of multiple classes and methods,
  1397. and also permits the writing of 'low boilerplate' programs by providing
  1398. a default class and method as appropriate.  The simplest documented
  1399. NetRexx program might therefore be:
  1400.  
  1401.   /* This is a very simple NetRexx program */
  1402.   say 'Hello World!'
  1403.  
  1404. More generally, a NetRexx program consists of:
  1405.  
  1406.   1. An optional prologue (PACKAGE, IMPORT, and OPTIONS instructions;
  1407.      only one PACKAGE instruction is permitted per program).
  1408.  
  1409.   2. One or more class definitions, each introduced by a CLASS instruction.
  1410.  
  1411. A class definition comprises:
  1412.  
  1413.   1. Zero or more property variable assignments (which may just set the
  1414.      type of each variable), along with optional PROPERTIES instructions
  1415.      that can alter their attributes, and optional NUMERIC instructions.
  1416.  
  1417.   2. Zero or more method definitions, each introduced by a METHOD
  1418.      instruction.
  1419.  
  1420. Methods may contain any instructions, except the CLASS, METHOD, and
  1421. PROPERTIES instructions and those allowed in the prologue.
  1422.  
  1423. For example:
  1424.  
  1425.   /* A program with two classes */
  1426.   import java.applet.    -- for example
  1427.  
  1428.   class testclass extends Applet
  1429.     i=int                -- property (instance) variable
  1430.     j=int 3              -- this one is initialized to 3
  1431.  
  1432.     method start
  1433.       say 'I started'
  1434.  
  1435.     method stop
  1436.       say 'I stopped'
  1437.  
  1438.   class anotherclass
  1439.     method testing
  1440.       loop i=1 to 10
  1441.         say '1, 2, 3, 4...'
  1442.         if i=7 then return
  1443.        end
  1444.       return
  1445.  
  1446.     method anothertest
  1447.       say '1, 2, 3, 4'
  1448.  
  1449. Note that a RETURN instruction implies no static scoping; the content
  1450. of a method is ended by a METHOD (or CLASS) instruction, or by the end
  1451. of the source stream.
  1452.  
  1453. The following defaults are provided:
  1454.  
  1455.   1. If, while parsing prolog instructions, some instruction that is not
  1456.      valid for the prolog and is not a CLASS instruction is encountered,
  1457.      then a default CLASS instruction (with the name derived from that
  1458.      of the source file) and a default METHOD instruction (with a name
  1459.      and attributes appropriate for the environment, such as 'main') is
  1460.      inserted.  In this case, it is assumed that execution of the
  1461.      program will begin by invocation of the default method.
  1462.  
  1463.      In other words, a 'stand-alone' application can be written without
  1464.      explicitly providing the class and method instructions for the
  1465.      first method to be executed.
  1466.  
  1467.      In the Java environment, the 'main' method in a stand-alone
  1468.      application is passed the words forming the command string as a
  1469.      String array.  When NetRexx provides the method instruction by
  1470.      default, it also constructs a Rexx string from this array of words,
  1471.      with a blank added between words, and assigns the string to the
  1472.      variable 'arg'.
  1473.  
  1474.      The command string may also have been edited by the underlying
  1475.      operating system environment; certain characters may not be
  1476.      allowed, multiple blanks or whitespace may have been reduced to
  1477.      single blanks, etc.
  1478.  
  1479.   2. If a method ends and the last instruction at the outer level of the
  1480.      method scope is not RETURN then an RETURN instruction is added
  1481.      unless a value is expected for a method, in which case an error is
  1482.      reported.
  1483.  
  1484. Language processors may provide option(s) to prevent, or warn of, these
  1485. defaults being applied, as desired.
  1486.  
  1487.