J3/06-380 To: J3 From: Malcolm Cohen Subject: Macro Assignment SSE Date: 2006/11/16 1. Introduction This paper contains specifications, syntax and edits for macro assignment. 2. Specifications (1) Assignment of a macro expression to a macro (integer) variable should be possible. The expression shall be an initialization expression of type integer. Comment: This is sort-of possible now, by doing MACRO DO I=, where you repeat the expression. Within the DO block the macro variable I has the value of the expression. That is rather grotty. (2) There should be macro variables that are capable of holding token sequences, not just integer values. Expansion of such a macro variable produces its token sequence. Such macro variables are initially empty. Comment: This is the same as macro dummy arguments. (3) That assignment to a macro "token sequence" variable should be possible. This assignment expands its right-hand-side but does not evaluate it, i.e. it is a token sequence not a macro expression. Comment: This is similar to the way macro argument association works, where an actual argument is a token sequence, and the dummy argument gets associated with that sequence. So this functionality is sort-of available now, but only by doing nested macro expansions. That is rather arcane. 3. Syntax Reminder: Macro local variables of type integer are declared by MACRO INTEGER [kind] :: (1) Macro local variables of "token sequence" type shall be declared by MACRO VARIABLE :: Comment: Since a token sequence doesn't have a type, just saying it is a variable seems reasonable. Alternatively it could be "MACRO TOKEN SEQUENCE :: " but that seems excessively verbose. (2) Assignment to a macro integer variable shall be by MACRO = Constraint: The macro-integer-variable-name shall be a macro local variable of type integer. (3) Assignment to a macro token sequence variable shall be by MACRO = [ ]... Constraint: The shall be a macro local variable that is not of type integer and is not a macro dummy argument. Comment: The difference between these two forms depends only on the type of the macro variable being assigned to. Note that assignment to an empty token sequence is allowed, and sets the variable to being an empty token sequence. 4. Edits [33:15+] Add new production to R317 , "<> " {The new declaration.} [33:18+] Add new production "R320a <> MACRO VARIABLE :: " {The new declaration.} [33:19] In C306, after "R318" insert "R320a". {Same constraint as for MACRO INTEGER, viz that the macro-local-variable-name shall not be a macro dummy argument name.} [33:26] Before "A" insert new sentence "A macro variable declaration statement declares untyped macro local variables; the value of an untyped macro local variable is a token sequence, and its initial value is an empty sequence (no tokens)." [33:27] Append to sentence "or in a macro variable declaration statement". {Allow untyped macro variables.} [33:33+] Add new productions to R322 , "<> <> " [34:24+] Add new productions "R332a <> = C312a (R332a) shall be the name of a macro local variable of type integer R332b <> = C312b (R332b) shall be the name of an untyped macro local variable that is not a macro dummy argument. R332c <> [ ]..." {Syntax for macro assignment.} [36:31] "or" -> ", assignment token sequence, or" {Token replacement operates on the right-hand-side of macro assignment.} [36:39] Append to paragraph "An untyped macro local variable expands to the sequence of tokens that was assigned to it, or to zero-length token sequence if it has never been assigned to." {How untyped macro local variables expand.} [38:6+] Insert new subclause "3.5.2.5a Macro assignment Processing a macro integer assignment statement sets the macro local variable value to that of the macro expression. Processing a macro token assignment statement sets the macro local variable value to be the sequence of tokens following the equals sign. If no tokens appear after the equals sign, the macro local variable is set to the zero-length token sequence." {Define effect of macro assignment.} ===END===