 |  Terms A term in NetRexx is a syntactic unit which describes some value (such as a literal string, a variable, or the result of some computation) that can be manipulated in a NetRexx program. Terms may be either simple (consisting of a single element) or compound (consisting of more than one element, with a period and no other characters between each element). Simple terms A simple term may be: - A literal string -- a character string delimited by quotes, which is a constant.
- A symbol. A symbol that does not begin with a digit identifies a variable, a value, or a type. One that does begin with a digit is a numeric symbol, which is a constant.
- A method call, which is of the form
symbol([expression[,expression]...]) - An indexed reference, which is of the form[1]
symbol'['[expression[,expression]...]']' - A sub-expression, which consists of any expression enclosed within a left and a right parenthesis.
Blanks are not permitted between the symbol in a method call and the '(', or between the symbol in an indexed reference and the '['. Within simple terms, method calls with no arguments (that is, with no expressions between the parentheses) may be expressed without the parentheses provided that they refer to a method in the current class (or to a static method in a class used by the current class) and do not refer to a constructor. An implementation may optionally provide a mechanism that disallows this parenthesis omission. Compound terms Compound terms may start with any simple term, and, in addition, may start with a qualified class name or a qualified constructor. These last two both start with a package name (a sequence of non-numeric symbols separated by periods and ending in a period). This first part of a compound term is known as the stub of the term. Example stubs: "A string" Arca 12.10 paint(g) indexedVar[i+1] ("A" "string") java.lang.Math -- qualified class name netrexx.lang.Rexx(1) -- qualified constructor All stubs are syntactically valid terms (either simple or compound) and may optionally be followed by a continuation, which is one or more additional non-numeric symbols, method calls, or indexed references, separated from each other and from the stub by connectors which are periods. Example compound terms: "A rabbit".word(2).pos('b') Fluffy.left(3) 12.10.max(j) paint(g).picture indexedVar[i+1].length ("A" "string").word(1) java.lang.Math.PI java.lang.Math.log(10)Within compound terms, method calls with no arguments (that is, with no expressions between the parentheses) may be expressed without the parentheses provided that they do not refer to a constructor. For example, the term: Thread.currentThread().suspend() could be written: Thread.currentThread.suspend An implementation may optionally provide a mechanism that disallows this parenthesis omission. Evaluation of terms Simple terms are evaluated as a whole, as described below. Compound terms are evaluated from left to right. First the stub is evaluated according to the rules detailed below. The type of the value of the stub then qualifies the next element of the term (if any) which is then evaluated (again, the exact rules are detailed below). This process is then repeated for each element in the term. For instance, for the example above: "A rabbit".word(2).pos('b')the evaluation proceeds as follows: - The stub ("A rabbit") is evaluated, resulting in a string of type Rexx.
- Because that string is of type Rexx, the Rexx class is then searched for the word method. This is then invoked on the string, with argument 2. In other words, the word method is invoked with the string 'A rabbit' as its current context (the properties of the Rexx class when the method is invoked reflect that value).
This returns a new string of type Rexx, 'rabbit' (the second word in the original string). - In the same way as before, the pos method of the Rexx class is then invoked on the new string, with argument 'b'.
This returns a new string of type Rexx, '3' (the position of the first 'b' in the previous result).
This value, '3', is the final value of the term. The remainder of this section gives the details of term evaluation; it is best skipped on first reading. Simple term evaluation All simple terms may also be used as stubs, and are evaluated in precisely the same way as stubs, as described below. For example, numeric symbols are evaluated as though they were enclosed in quotes; their value is a string of type Rexx. In binary classes, however, simple terms that are strings or numeric symbols are given an implementation-defined string or primitive type respectively, as described in the section on Binary values and operations Stub evaluation A term's stub is evaluated according to the following rules: - If the stub is a literal string, its value is the string, of type Rexx, constructed from that literal.
- If the stub is a numeric symbol, its value is the string, of type Rexx, constructed from that literal (as though the literal were enclosed in quotes).
- If the stub is an unqualified method or constructor call, or a qualified constructor call, then its value and type is the result of invoking the method identified by the stub, as described in Methods and Constructors.
- If the stub is a (non-numeric) symbol, then its value and type will be determined by whichever of the following is first found:
- A local variable or method argument within the current method, or a property in the current class.
- A method whose name matches the symbol, and takes no arguments, and that is not a constructor, in the current class.[2] If the stub is part of a compound symbol, then it may also be in a superclass, searching upwards from the current class.
- A static or constant property, or a static method,[3] whose name matches the symbol (and that takes no arguments, if a method) in a class listed in the uses phrase of the class instruction. Each class from the list is searched for a matching property or method, and then its superclasses are searched upwards from the class in the same way; this process is repeated for each of the classes, in the order specified in the list.
- One of the allowed special words described in Special words and methods, such as this or version.
- The short name of a known class or primitive type (in which case the stub has no value, just a type).
- If the stub is an indexed reference, then its value and type will be determined by whichever of the following is first found:
- The symbol naming the reference is an undimensioned local variable or method argument within the current method, or a property in the current class, which has type Rexx. In this case, the reference is to an indexed string; the expressions within the brackets must be convertible to type Rexx, and the type of the result will be Rexx.
- The symbol naming the reference is a dimensioned local variable or method argument within the current method, or a property in the current class. In this case, the reference is to an array, and the expressions within the brackets must be convertible to whole numbers allowed for array indexes. The type of the result will have the type of the array, with dimensions reduced by the number of dimensions specified in the stub.
For example, if the array foo was of type Baa[,,,] and the stub referred to foo[1,2], then the result would be of type Baa[,]. It would have been an error for the stub to have specified more than four dimensions. - The symbol naming the reference is the name of a static or constant property in a class listed in the uses phrase of the class instruction. Each class from the list is searched in the same way as for symbols, above. The reference may be to an indexed string or an array, as for properties in the current class.
- The symbol naming the reference is the name of a primitive type or the short name of a known class, and there are no expressions within the brackets (just optional commas). In this case, the stub describes a dimensioned type.
- The symbol naming the reference is the name of a primitive type or is the short name of a known class, and there are one or more expressions within the brackets. In this case, the reference is to an array constructor; the expressions within the brackets must be convertible to non-negative whole numbers allowed for array indexes, and the value is an array of the specified type, dimensions, and size.
- If the stub is a sub-expression, then its value and type will be determined by evaluating the expression within the parentheses.
- If the stub starts with the name of a package, then it will either describe a qualified type or a qualified constructor. Its type will be same in either case, and if a constructor then its value will be the value returned by the constructor.
If the stub is not followed by further segments, the final value and type of the term is the value and type of the stub. Continuation evaluation Each segment of a term's continuation is evaluated from left to right, according to the type of the evaluation of the term so far (the continuation type) and the syntax of the new segment: - If the segment is a method call, then its value and type is the result of invoking the matching method in the class defining the continuation type (or a superclass or subclass of that class), as described in Methods and Constructors. Note that method calls in term continuations cannot be constructors.
- If the stub is an indexed reference, then it will refer to a property in the class defining the continuation type (or a superclass of that class). That property will either be an undimensioned NetRexx string (type Rexx) or a dimensioned array. In either case, it is evaluated in the same way as an indexed reference found in the stub, except that it is not necessarily in the current class, cannot be an array constructor, and cannot result in a dimensioned type.
- If the segment is a symbol, then it refers to either a property or a method in the class defining the continuation type (or a superclass of that class).[4]
The search for the property or method starts with the class defining the continuation type. If a property name matches, it is used; if not, a method of the same name and having no arguments (or only optional arguments) will match. If neither property nor method is found, then the same search is applied to each of the continuation class's superclasses in turn, starting with the class that it extends. As a convenient special case, if the property or method is not found, then if the segment is the final segment of the term and is the simple symbol length and the continuation type is a single-dimensioned array, then the segment evaluates to the size of the array. This will be a non-negative whole number of an appropriate primitive type (or of type Rexx if there is no appropriate type).
The final value and type of the term is the value and type determined by the evaluation of the last segment of the continuation. |  |
|