TonyTebby wrote:
First of all, thank you for your work on SBasic. After having had a
look at the code (and, hear hear, documentation ;-) ) I must say I
think its design is very elegant and despite the complexity the code
is comparatively easy to read, which is amazing really.
> 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
Very well, but except you I don't really know anybody who has the
skills and knowledge to do this.
> But imagine the chaos if someone did
Well: ouch.
> Any suggestions?
What about this quick&moderately dirty approach of employing the
existing SBasic parser?
100 r$= '('
110 l$ = ')'
120 f$ = 'UPPER$'
130 v$ = '"ql-smsq"'
140 c$ = f$ & r$ & v$ & l$
150 PRINT Eval$(c$)
160 STOP
990 :
1000 DEFine FuNction Eval$(e$)
1010 LOCal C%, ev$
1020 C% = FOP_OVER('ram1_eval_bas')
1030 PRINT#C%, "OPEN_NEW#3,PIPE_eval"
1040 PRINT#C%, "a$ = "; e$
1050 PRINT#C%, "PRINT#3,a$"
1060 PRINT#C%, "CLOSE#3"
1070 CLOSE#C%
1080 C% = FOP_IN('PIPE_eval')
1090 EX ram1_eval_bas
1100 INPUT#C%, ev$
1110 CLOSE#C%
1120 RETurn ev$
1130 END DEFine
Not as mighty as your solution but good enough for most cases, I
guess.
Marcel