Hello Tony,
TonyTebby wrote:
I know that 'macro substitution' has nothing to do with macros, but that's the terminology used in FOXPRO's manual.This "macro substitution" in Foxpro is not really anything to do with macros - it is a run-time expression evaluator that parses and evaluates a string.
Please note that my English is rather limited and my progamming 'skills' are limited to Sbasic Archive (a long time ago) and FOXPRO.
But FOXPRO can't run plain text files. (that is what the manual says).If you try to run such a file, FOXPRO will compile it before executing it. I suppose it is a kind of pseudo compilation.Foxpro can do it because it is based on early purely interpreted Bill Gates BASIC which always parses all statements every time they are executed. JavaScript also has an eval() function because javascript is (nearly) purely interpreted. SuperBASIC, SBASIC, VisualBASIC and JAVA cannot because they program is compiled to execute a fixed sequence of pseudo instructions written for a "virtual machine" (Java bytecodes), an "engine" (Pascal p-codes) or a "run-time interpreter" (S*BASIC, VisualBasic).
(could be a stupid remark)
In principle, an Eval could be added to SuperBASIC.
Compilation
1) Detect that a statement includes an eval and do not parse / compile it
but extract the "eval" functions replacing them by special variables (e.g.
&01$, &02$ etc)
2) For each eval in the statement, generate an assignment &xx$ = [eval
parameter] and store it in the program
3) Store the modified statement uncompiled after these assignments.
Runtime, when the uncompiled statement is encountered
1) spawn a new set of SBASIC system variables and tables (in principle this
could be done once only)
2) substitute the values of the eval variables into the statement
3) parse and compile the statement
4) now the tricky bit - return to the main set of SBASIC tables and execute
the statement
This would work (1000s of times slower than normal execution) for simple
cases such as A="Upper": Print Eval( A & "('Hello'))
But imagine the chaos if someone did If xxx: A="": B="End For" Else A="End For": B="" For Index = 1 to 100 ... Exit Index ... Eval (A) ... Eval (B) The end of the loop depends on the value of xxx and can change during execution, but SBASIC compiles the end of the loop before execution. This trick does work in Javascript because it is purely and slowly interpreted. Any suggestions? Tony Tebby ----- Original Message ----- From: "Fran�ois Van Emelen" <[EMAIL PROTECTED]> To: "QL users list" <[EMAIL PROTECTED]>; "Fran�ois Van Emelen" <[EMAIL PROTECTED]> Sent: mardi 18 f�vrier 2003 17:34 Subject: [ql-users] Sbasic and macro substitutionsHi all, I've been using Foxpro v2 (programmable database system) for several years now and 'macro substitution' is one of those powerful functions I use a lot in my programmes. I wonder whether such a function is available (possible?) in Sbasic. Here's an example of a 'macro substitution': l='(' r=')' f='UPPER' v='"ql-smsq"' c=F+L+V+R ? c (?=print) displays as expected UPPER('ql-smsq') cc=&c (&=macro substitution sign) ?cc displays QL-SMSQ Is there a way to achieve this in Sbasic (Qliberated Sbasic) ? How ? Why not? Fran�ois Van Emelen
