1 05/20/81  Version 2 exec_com  (initial implementation)
  2 
  3 
  4 This info seg describes the features to be incorporated in the first
  5 installation of the V2 exec_com language.
  6 
  7 
  8 Version change:
  9 Version 2 exec_com's are recognized by having "&version 2" as the
 10 first line of the ec.  Anywhere else, this line is an error.  The
 11 effect of this line is to switch interpreters, making it unnecessary
 12 to have an incompatible change in exec_com command usage.
 13 
 14 However, there are two incompatible changes to the language syntax.
 15 The first concerns the interpretation of unrecognized strings, and the
 16 second concerns the order of expansion and execution.
 17 
 18 
 19 In Version 1, any strings beginning with & that are not recognized as
 20 language keywords are left intact, ie., not expanded. In Version 2, any
 21 unrecognized &string causes an error. The reason for this change is as
 22 follows: It is impossible to add new keywords to the V1 language, for
 23 example to add the keyword &foo. Since the V1 interpreter doesn't
 24 recognize &foo today, it leaves it as &foo. Therefore, &foo already has
 25 a meaning: itself. Any change to make &foo mean something different is
 26 an incompatible change. A good example is the &(k) construct, where k
 27 is an integer. Users of V1 use this construct, not recognized by ec, to
 28 pass parameter references to imbedded instances of the do command or
 29 active function. For clarity, do and ec should have the same
 30 interpretation of the constructs they share; unfortunately, V1 ec
 31 cannot be changed. Version 2, on the other hand, rejects all
 32 unrecognized keywords so that they remain open for later definition.
 33 
 34 
 35 The second incompatible change is to parse keywords and arguments to
 36 exec_com statements, before expanding the arguments themselves.
 37 For example:
 38           &set foo &(bar)
 39 sets the value of foo to be the entire value of the variable bar,
 40 whether or not that value contains spaces or ampersands. Version 1
 41 does all expansion first, then parses into arguments. The result is
 42 that &then in a parameter value can change the syntax of an &if
 43 statement, and so on.
 44 
 45 
 46 Another very visible change is that--  &if [ACTIVE STRING]
 47 is changed to--                       &if &[ACTIVE STRING]
 48 so that the new &[...] construct is uniformly required to expand
 49 active functions in control lines. The obsolete syntax will
 50 continue to work as a special case, but is discouraged.
 51 
 52 
 53 Variables:
 54 Automatic variables are assigned values by the &set statement,
 55 which takes pairs of arguments:
 56           &set var_name1 value1 var_name2 value2 ...
 57 There is no restriction on the syntax of variable names or values,
 58 except that variable names are not allowed to start with an &.
 59 Spaces and ampersands inside arguments to &set have to be enclosed in
 60 the ec quotes &"...", for example:
 61           &set all_3 &"(x y z)" &"my name" Russell Russell &"yours truly"
 62 which assigns values as follows:
 63           VAR NAME            VALUE
 64           all_3               (x y z)
 65           my name             Russell
 66           Russell             yours truly
 67 
 68 
 69 Variables are referenced by &(...) where the contents of the
 70 parentheses either is or expands to the name of a variable that has
 71 been assigned a value by &set.  In the above example, expansions take
 72 place as follows:
 73           EXPRESSION          EXPANDS TO
 74           &(all_3)            (x y z)
 75           &(my name)          Russell
 76           &(&(my name))       yours truly
 77 The V2 interpreter expands from left to right, expanding whenever it
 78 encounters a ) matching a previous (.
 79 
 80 
 81 The integer variable names are reserved for arguments to the exec_com
 82 command, and currently cannot be set by &set. The parameter reference
 83 &(1) expands to the value of the first argument, &r(3) to the value
 84 of the third argument requoted, and so on.
 85 
 86 As in Version 1, a reference to a nonexistent argument, such as &5 or
 87 &(5) if there is no fifth argument to ec, is replaced by a null string.
 88 Conversely, reference to a variable that has not been assigned a value
 89 by &set is an error.
 90 
 91 
 92 Argument defaults:
 93 The &default statement is used to set default values in case certain
 94 arguments are not specified to the exec_com command. Its syntax is:
 95           &default default1 default2 ...
 96 where any of the defaults can be &undefined or &undef to hold a place
 97 for the jth argument without assigning a default. A parameter reference
 98 &k or &(k) where k is an integer expands to the kth arg to exec_com
 99 if one is specified, else to the kth default assigned by &default,
100 else to null string.
101 
102 
103 Active function expansion:
104 The &[...] construct is used to expand an active string anywhere in an
105 exec_com line, whereas [...] is only expanded in command lines by the
106 command processor. The new construct can be used, for example, to do
107 loop arithmetic by expanding withinn a &set statement:
108           &set arg_index &[plus &(arg_index) 1]
109 The inner &(arg_index) is expanded first to yield a value (say 4),
110 then the active string [plus 4 1] is expanded and the value 5 is
111 assigned to arg_index.
112 
113 
114 Literals:
115 The first one is &"..." which encloses an arbitrary string not to be
116 expanded. It ends with the matching double-quote character.
117 
118 The second is the && sequence, which expands to a single ampersand.
119 Either this or &"..." can be used, for example, to pass parameter
120 strings to the do command:
121           &&1     is the same as     &"&1"
122 
123 
124 The rest of the literal escapes are for inserting one or more of a
125 certain character. If followed immediately by a number in parentheses
126 (no intervening space), the character is repeated the specified number
127 of times. If not followed immediately by an open paren, one character
128 is inserted. The following literal escapes are provided:
129           &AMP      same as && if not followed by an open paren.
130           &SP       space character
131           &HT       horizontal tab
132           &NL       newline character
133           &VT       vertical tab
134           &FF       form feed
135           &BS       backspace
136           &QT       double-quote
137 For example, &QT(5) expands to """"" and &AMP(3) to &&&.
138 
139 
140 Indenting:
141 The V2 interpreter strips white space (the four characters space,
142 horizontal tab, vertical tab, and form feed) from the beginning and
143 end of each line. Stripping white space from the beginning of each
144 line allows the user to indent the text of the ec. Literal escapes
145 such as &HT(2) can be used to explicitly insert white space, for
146 example at the beginning of editor input lines.
147 
148 
149 Comments:
150 The character sequence used to begin comments is changed from &<WHITE>
151 (where <WHITE> is any white space character) to &- since the latter
152 is less likely as the result of a simple typing error. Everything
153 following this character sequence on a line is ignored by the
154 interpreter, except when comments are being traced by &comment_line.
155 
156 
157 Stripping white space from the ends of lines allows the user to put
158 comments in-line:
159           &if &[equal &1 foo] &then     &-Test for "ec foo"
160 The white space preceding the comment is stripped from the executable
161 line, therefore the formatting of comments is left up to the user.
162 See "Continuation" below to see how comments and line continuation
163 interact.
164 
165 
166 Continuation:
167 A line beginning with the character sequence &+ (white space before it
168 is ignored) continues the text of the previous line, for example:
169           &set one hen two ducks three squawking_
170           &+geese
171 Since white space is stripped from the end of each line including the
172 one being continued, any white space to be inserted at the break must
173 follow the &+. In the example above, squawking_geese is a single
174 argument. White space is not stripped after &+.
175 
176 
177 Since trailing white space and comments are stripped, comments can be
178 interspersed with continuation:
179           mbx_set_acl Database adros *.Elite.*    &-Maintainers
180           &+ ao *.*.*                             &-all others
181 Note that the space after &+ is necessary to separate the third and
182 fourth command line arguments.
183 
184 The complementary sequences &+ and &- can be thought of as saying
185 "this is part of the executable line" and "this isn't" respectively.
186 
187 
188 Tracing:
189 The &command_line and &input_line statements are replaced with the new
190 &trace statement, whose syntax is:
191      &trace TYPES STATE {&prefix STR} {&osw SWITCHNAME}
192 which sets tracing for one or more types of lines.
193 TYPES can be any combination of:
194      &command       command lines.
195      &comment       comments, including those sharing other lines.
196      &control       control lines such as &print....
197      &input         lines being read as input by some command.
198 
199 
200 STATE can be one of the following:
201      off, false     disables tracing entirely.
202      on, true       enables tracing, in whichever of the following
203                     modes was last specified. The default is
204                     "unexpanded".
205      &unexpanded    prints lines as they appear in the exec_com
206                     segment. Implies "on".
207      &expanded      prints lines after all expansion has been done.
208                     Implies "on".
209      &all           prints at each stage of expansion. Implies "on".
210      &both          prints each line as it appears in the exec_com,
211                     then again after all expansion. Implies "on".
212 
213 
214 PREFIX specifies a character string to be printed at the beginning
215 of traced lines. Prefixes are all null string by default.
216 
217 SWITCHNAME specifies an I/O switch on which to write the trace.
218 
219 
220 Return values:
221 The &return statement operates like &quit but returns the (expanded)
222 rest of the line as a value if exec_com was invoked as an active
223 function.  If exec_com was invoked as a command, the return value is
224 printed rather than returned.  Correspondingly, an exec_com invoked as
225 an active function that executes a &quit statement returns null
226 string.  In summary:
227                     COMMAND             ACTIVE FUNCTION
228      &quit          just quits          returns null string
229      &return        prints value        returns value