Frank Heckenbach wrote:
Adriaan van Os wrote:
Frank Heckenbach wrote:
Adriaan van Os wrote:
Some more in Apple UCSD Pascal (just for the record)
SCAN( LIMIT, PEXPR, SOURCE)
PEXPR is a "partial expression" which specifies the target of the scan. PEXPR takes one of the following forms:
= CH <> CH
You mean `Scan (42, <> 'A', Foo)'???
<rant subject="syntax" level="200%"> ...
Oh dear, I'm quite shocked. Why do people make up such strange things? They could easily have made two separate routines (say `ScanEQ' and `ScanNE' -- this might be what can be implemented reasonably in GPC, with different syntax (*)) -- it would have taken them just one more predefined identifier instead of a completely irregular new syntax rule ...
I'm not sure where in the chain from Apple's UCSD Pascal to MPW Pascal the change was made, but in MPW Pascal `ScanEQ' and `ScanNE' is provided instead of Scan. (The parameter types for LIMIT and SOURCE are also slightly different and the PEXPR "partial expression" is replaced with an expression of type char.)
(*) Just a thought. Perhaps the syntax could be handled with more-advanced preprocessor features, in particular string handling. Something like:
{$define Scan(A, B, C) {$if MacroIsPrefix (<>, MacroTrim (B))} ScanNE (A, MacroRemovePrefix (<>, MacroTrim (B)), C) {$else} ScanEQ (A, MacroRemovePrefix (=, MacroTrim (B)), C) {$endif} }
How about:
{$define Scan(A, B, C) repeat var ScanExpression : string(4) value (#B); if (Length(ScanExpression) = 4) and_then (index(ScanExpression, '<>') = 1) then ScanNE((A),ScanExpression[4],(C)) else if (Length(ScanExpression) = 3) and_then (index(ScanExpression, '=') = 1) then ScanEQ((A),ScanExpression[3],(C)) else ParameterError; until true; }
Note: The above assumes the preprocessor treats #B like the C preprocessor does (i.e., string quotes the macro parameter) and that PEXPR parameter is required to be in the exact form that Adriaan cited - without quotes for CH. If the CH part is a quoted char constant, some adjustments are needed to take into accout the embedded quote characters. If the CH part can be any expression of char type, forget it - I don't think a macro hack is possible for that.
Gale Paeper gpaeper@mpirenet.com