(j3.2006) (j3.2005) Re: question on token replacement/concatenation

Dick Hendrickson dick.hendrickson
Mon Jan 22 12:31:26 EST 2007


On 12/6/2006, Malcolm Cohen wrote:
> Dick Hendrickson said:
>>>>  3 %% .14159 %% E %% + %% 0
> ...
>>   I've asked this before, but I don't remember the answer.  What sort of
>>   lexical token is the "E"?  It doesn't seem to match anything in the list.
> 
> Before macro token concatenation, it's a name.
> 
>   <letter> [ <digit> | <letter> | _ ]...
> 
> After macro token concatenation, the 5 tokens ( "digits", "decimal",
> "name", "operator", "digits" ) combine to form one token, so the "E"
> no longer maps to a whole token but is merely one character in a token.
> 
> Cheers,
OK, but this sort of limits how we can use the %% to build up things.
The syntax for "names", and the other lexical tokens, is fairly
restrictive.  The two cases I think might be hard to do are
building up structure names and adding kinds to constants.

Suppose I want to build up component names, so that sometimes I
refer to A%B and sometimes to A.  My niave attempt would be
       A%%p1
to get A, I'd invoke the macro with p1 as a null macro argument
for A%B, I'd try to set p1 to %B.
But, I can't do that because %B isn't a name, nor any other
lexical token.

Similarly for constants, if I sometimes want to postfix a kind parameter
I'd try
       3.14%%kind
where "kind" would sometimes be null and other times be _4 or
_workingprecision.  Again, I can't do this.

So, is it worth trying to add some sort of "except leading underscores
and %s are allowed in the names" condition to the concatenation
rules?  Or are these cases too small to worry about this time?
Or, have I misunderstand something?

Dick



More information about the J3 mailing list