Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Phoebus Dokos

On Wed, 19 Feb 2003 19:38:44 -0800, Timothy Swenson <[EMAIL PROTECTED]> 
wrote:


At 05:55 PM 2/19/2003 +0100, you wrote:


Hi Tim,
Thank you for your reply, but my example has mislead you somewhat,I'm 
afraid.
Macro substitution is something completely different from 'IF DEF's'
or '#INCLUDE'( if I do understand your explanation correctly).

I gather from TT's reply that I was not getting what you had expressed.  
I was thinking more of a macro in C terms than the 'eval' that you were 
expressing.

Since I'm replying to this thread, Phoebus is right in that FoxPro is not 
based on anything by M$.  Fox's first product was a code accelerator for 
dBase II.  I believe FoxPro is based on the dBase II/III language (which 
I used to program in many moons ago).


Exactly right. The Rushmore engine is a Super Duper dbase III... exactly 
what dBaseIV should have been if Ashton-Tate hadn't mess up! :-)

Too bad they were bought off by M$. Although their products still live 
somewhere in the core of M$ DB technologies, one can't help but wonder how 
different things would be today if it hadn't (ie no Slammer virus ;-)


Phoebus

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Timothy Swenson

At 05:55 PM 2/19/2003 +0100, you wrote:


Hi Tim,
Thank you for your reply, but my example has mislead you somewhat,I'm afraid.
Macro substitution is something completely different from 'IF DEF's'
or '#INCLUDE'( if I do understand your explanation correctly).


I gather from TT's reply that I was not getting what you had expressed.  I 
was thinking more of a macro in C terms than the 'eval' that you were 
expressing.

Since I'm replying to this thread, Phoebus is right in that FoxPro is not 
based on anything by M$.  Fox's first product was a code accelerator for 
dBase II.  I believe FoxPro is based on the dBase II/III language (which I 
used to program in many moons ago).

Tim Swenson



Re: [ql-users] Turbo Compiled Programs - Parameter passing

2003-02-19 Thread RWAPSoftware
In a message dated 19/02/2003 23:46:08 GMT Standard Time, [EMAIL PROTECTED] writes:

It's a point of view I guess... When you write with intent to compile some 
things need to be taken into account...

You would never assume the same though for VisualBasic though would you? 
(Okay bad example ;-)



Definitely a bad example - got nothing on S*BASIC

--
Rich Mellor 
RWAP Software
35 Chantry Croft, Kinsley, Pontefract, West Yorkshire, WF9 5JH
TEL: 01977 610509
http://hometown.aol.co.uk/rwapsoftware


Re: [ql-users] Turbo Compiled Programs - Parameter passing

2003-02-19 Thread Phoebus Dokos

On Wed, 19 Feb 2003 18:23:50 EST, <[EMAIL PROTECTED]> wrote:


In a message dated 19/02/2003 23:19:29 GMT Standard Time, [EMAIL PROTECTED] 
writes:

I don't believe that is a bug per se. You have to take into account that 
the implicit datatypes that are used are there to create faster code. So 
if

you IMPLICITLY define a datatype to use and you feed it something else 
then

it SHOULD complaine If you therefore 'trick' Turbo, it should not only 
report an error but get a hammer out of the screen and break your QL :-)


Possibly so, but it is the incompatabilities with S*BASIC such as these, 
which make Turbo such a steep learning curve, even for someone who used 
it as my only compiler some 5/6 years ago...

It's a point of view I guess... When you write with intent to compile some 
things need to be taken into account...

You would never assume the same though for VisualBasic though would you? 
(Okay bad example ;-)

Phoebus



--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Re: [ql-users] Turbo Compiled Programs - Parameter passing

2003-02-19 Thread RWAPSoftware
In a message dated 19/02/2003 23:19:29 GMT Standard Time, [EMAIL PROTECTED] writes:

I don't believe that is a bug per se. You have to take into account that 
the implicit datatypes that are used are there to create faster code. So if 
you IMPLICITLY define a datatype to use and you feed it something else then 
it SHOULD complaine If you therefore 'trick' Turbo, it should not only 
report an error but get a hammer out of the screen and break your QL :-)


Possibly so, but it is the incompatabilities with S*BASIC such as these, which make Turbo such a steep learning curve, even for someone who used it as my only compiler some 5/6 years ago...

--
Rich Mellor 
RWAP Software
35 Chantry Croft, Kinsley, Pontefract, West Yorkshire, WF9 5JH
TEL: 01977 610509
http://hometown.aol.co.uk/rwapsoftware


Re: [ql-users] Turbo Compiled Programs - Parameter passing

2003-02-19 Thread Phoebus Dokos

On Wed, 19 Feb 2003 17:29:18 EST, <[EMAIL PROTECTED]> wrote:



The other quirk is that Turbo will report an error if you pass a 
different type of variable to the parameter type listed in the reference, 
for example:

I don't believe that is a bug per se. You have to take into account that 
the implicit datatypes that are used are there to create faster code. So if 
you IMPLICITLY define a datatype to use and you feed it something else then 
it SHOULD complaine If you therefore 'trick' Turbo, it should not only 
report an error but get a hammer out of the screen and break your QL :-)


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


[ql-users] Turbo Compiled Programs - Parameter passing

2003-02-19 Thread RWAPSoftware
I have been exploring one or two 'features' within Turbo which I have passed the comments onto George Gwilt.  However, perhaps someone has an original v2 of Turbo and would like to try out the following:

10 DIM x$(2,50)
20 x$(0)='Hello World'
30 x$(1)='This is a test'
40 x$(2)='Turbo only sees this line within the test function'
50 PRINT DIMN(x$):PAUSE
60 PRINT test (x$)
70 PAUSE
100 DEFine FuNction test (x$)
110 PRINT DIMN (x$)
120 FOR ix=0 to 2:PRINT x$(ix)
130 RETurn 1
140 END DEFine

Change line 50 to PRINT DIMN(x$(1)):PAUSE for a laugh

The other quirk is that Turbo will report an error if you pass a different type of variable to the parameter type listed in the reference, for example:

10 x=1
20 INC x
30 PRINT x:PAUSE
90 REFERENCE a%
100 DEFine PROCedure INC(a%)
110 a%=a%+1
120 END DEFine

Has anyone else noticed any other oddities.

--
Rich Mellor 
RWAP Software
35 Chantry Croft, Kinsley, Pontefract, West Yorkshire, WF9 5JH
TEL: 01977 610509
http://hometown.aol.co.uk/rwapsoftware


Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread P Witte

François Van Emelen writes:

> 100 rem macro_bas
> 110 REMark example of substitution /VAL
> 120 res1$="res1$=" :res2$="res2$="  :REMark res1$ string res2$ num
> 130 L1$='(' :R1$=")": f1$='upper$': string1$="'qdos'"
> 140 num1$="20":num2$="5":f2$="*"
> 150 OPEN_OVER#3,ram1_mac_do
> 160 PRINT#3,res1$&f1$&l1$&string1$&r1$
> 170 PRINT#3,res2$&num1$&f2$&num2$
> 180 CLOSE#3
> 190 DO 'ram1_mac_do'
> 200  PRINT res1$,res2$
> 210 rem lines 200 ... are not executed
> 220 rem because ram1_mac_do doesn't return to mac_bas but to job
> 225 rem 0/command line
> 230 rem type 'print res1$,res2$ on the command line
> 235 rem and 'QDOS', '200' will be displayed

This was the sort devious stuff one was expected to do in Archive. In
SuperBasic it is easiest just to MERGE or MRUN the code. Why go to all this
trouble?

SBasic has other possibilities in that you can run separate SBasics as a
slaves to a master program (SBasic or other). Heres an example program (this
is just a more general version of Marcel's program), just so you can test
the principle. Much more advanced things can be achieved with a little
effort:

100 REMark Get an SBASIC job to work as
110 REMark a slave of another SBASIC.
120 REMark Full programmable interpreter
130 REMark via PRINT statements!
140 REMark By pjwitte January 23rd 2001
150 :
160 REMark Init
170 ch = 1: cu = 0: CLS#ch: CLS#cu
180 pip$ = 'pipe_p' & HEX$(DATE,32)
190 :
200 REMark Plumb in SBAS slave
210 co = FOPEN(pip$ & 'o_2048')
220 ERT co
230 REMark lrun our command stream
240 cm$ = 'lrun "' & pip$ & 'o_1024"'
250 REMark Start SBAS with command
260 EXEP 'SBASIC'; cm$
270 REMark We control command channel
280 PRINT#co; 'ch = fopen(#0;"' & pip$ & 'i_64")'
290 REMark Messages come out here
300 ci = FOP_IN(pip$ & 'i'): IF ci < 0: CLOSE
310 ERT ci
320 :
330 REMark Add some tools (abbreviated here)
340 LIST#co; 1000 TO
350 :
360 REMark Test
370 PRINT#co; 'echo "Hello": beep 2000, 2'
380 IF Answer < 0: CLOSE: STOP
390 :
400 REMark Torment!
410 REPeat sb
420  INPUT#cu; '>'! cm$
430  IF cm$ = '' OR cm$ == 'quit': EXIT sb
440  PRINT#co; cm$
450  IF Answer < 0: EXIT sb
460 END REPeat sb
470 PRINT#co; 'beep 2000, 2: quit'
480 CLOSE
490 :
500 DEFine FuNction Answer
510 ans% = 0
520 REPeat il
530  k$ = INKEY$(#ci; 20)
540  IF LEN(k$) = 0: EXIT il
550  INPUT#ci; l$: echo k$ & l$
560   ans% = 1
570 END REPeat il
580 IF EOF(#ci): ans% = -10
590 IF ans% = 0: echo 'no answer'
600 IF ans% < 0: echo 'Slave died'
610 RETurn ans%
620 END DEFine
630 :
1000 DEFine PROCedure echo(t$)
1010 PRINT#ch; t$
1020 END DEFine
1030 :

Once this program runs you can type your commands in at the > prompt, eg

> print 3 + 2

answer: 5

or

> a=3
> b=3
> echo a+b

answer as expected. The problem is that it is too easy to crash the slave
job in which case it just dies and you have to set up a new one:

> ert -3

answer: insufficient memory. Slave died

The error could be as simple as a syntax error, eg

> prt 5

At least you get an error message which can be passed on to the master
program.

This technique could be used to add SBasic scripting to our (future) web
browser ;)

Per






Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread François Van Emelen



TonyTebby wrote:

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.

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).

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'))


I can't verify that as the source code is compiled before execution. But 
even if it is 1000s of time slower, it will still be a lot faster than 
modifying manually a field in , let's say,  a database of a few 100s of 
records and I would need a calculator to do it.

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.


Yes, I can imagine it. But then the content of the string could be 
controlled by an array, I think.
That array would hold only the operators and/or functions tolerated in 
the string.
Example:
 dim str_allowed$(2,15)
str_allowed$(0)='upper$':str_allowed$(1)='lower$':str_allowed$(2)='proper_name$'
dim num_allowed$(5,5)
num_allowed$(0)='instr':num_allowed$(1)=”<”:num_allowed$(2)=”*”  etc
Of course this would limit the power of such a  'VAL' function, but 
better something than nothing at all.
The above explanation of mine could of course be completely irrelevant 
and/or stupid. If it is, sorry for wasting your time.

Any suggestions?

If Sbasic can't cope with such a 'VAL' function, I know now I've been 
wasting several month of programming in Sbasic and designing windows 
with Easymenu/Easysptr.

If we (well, some clever programmers, I mean) would/could enhance the 
features/possibilities of  'DO'-files.
If we could force a 'DO'-file to return to the calling job instead of 
returning to Job 0/command line, a big step ('Quantum Leap?) would be 
made, because a 'macro-substitution' is already possible  with a  'DO'-file.

100 rem macro_bas
110 REMark example of substitution /VAL
120 res1$="res1$=" :res2$="res2$="  :REMark res1$ string res2$ num
130 L1$='(' :R1$=")": f1$='upper$': string1$="'qdos'"
140 num1$="20":num2$="5":f2$="*"
150 OPEN_OVER#3,ram1_mac_do
160 PRINT#3,res1$&f1$&l1$&string1$&r1$
170 PRINT#3,res2$&num1$&f2$&num2$
180 CLOSE#3
190 DO 'ram1_mac_do'
200  PRINT res1$,res2$
210 rem lines 200 ... are not executed
220 rem because ram1_mac_do doesn't return to mac_bas but to job
225 rem 0/command line
230 rem type 'print res1$,res2$ on the command line
235 rem and 'QDOS', '200' will be displayed

Thank you for reading this .
Kind regards
François Van Emelen

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 substitutions




Hi 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











Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread François Van Emelen

Hello Tony,


TonyTebby wrote:

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.


I know that 'macro substitution' has nothing to do with macros, but 
that's the terminology used in FOXPRO's manual.
Please note that my English is rather limited and my progamming 'skills' 
are limited to Sbasic Archive (a long time ago) and FOXPRO.

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).


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.
(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 substitutions




Hi 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











Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread François Van Emelen

Hi Tim,
Thank you for your reply, but my example has mislead you somewhat,I'm 
afraid.
Macro substitution is something completely different from 'IF DEF's'
or '#INCLUDE'( if I do understand your explanation correctly).
It is rather a function that acts upon the content of a string variable 
as if it had been typed in on the command line.
example:
100 my_string$="qdos"
120 my_new_string$=XYZ("upper$"&"("&my_string$&")")
130 rem XYZ => name of the function that would do the trick
140 print my_new_string$
150 rem line 140 would not display "upper$"&"("&my_string$&")"
160 rem but "QDOS"

Sorry for the disturbance and thanks for your explanation
François Van Emelen

Timothy Swenson wrote:

I don't believe there is a way of performing macro substitution in 
S*BASIC programming.  Now, it can probably be implemented in one form or 
another.

The most obvious is a pre-processor that takes a macro and expands it 
before the program is actually sent to a compiler or parser.  C has a 
pre-processor that does exactly this.

Another way to do it is to create a macro in a text editor that does the 
substitution for you.  Either as a form of pre-processor, or as a 
keyboard shortcut.

I don't think it is possible inside S*BASIC, as this would require a 
change in the S*BASIC code.

Structured SuperBasic (SSB) is a form of pre-processor that does things 
like conditional compilation (IF DEF's), combining S*BASIC modules into 
one program (#INCLUDE statement), and so on.  Some form of substitution 
could be implemented.  If you feel adventure some, the SSB source code 
comes in the package and you can take it as a start and go from there.

Tim Swenson







RE: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Norman Dunbar

Hi Phoebus,

>> Recently someone at the university asked me why I still used SBasic (and
I 
>> usually bring to the labs a QPC Zip disk)... I challenged him to do a 
>> vector addition program (with Graphics) in any Basic and it to be under 5

>> lines of code and it to be precise enough for the results to be used as 
>> scientific-grade data guess what? He couldn't ;-)

I don't even understand the question 

Cheers,
Norman.

-
Norman Dunbar
Database/Unix administrator
Lynx Financial Systems Ltd.
mailto:[EMAIL PROTECTED]
Tel: 0113 289 6265
Fax: 0113 289 3146
URL: http://www.Lynx-FS.com
-

This email is intended only for the use of the addressees named above and
may be confidential or legally privileged.  If you are not an addressee you
must not read it and must not use any information contained in it, nor copy
it, nor inform any person other than Lynx Financial Systems or the
addressees of its existence or contents.  If you have received this email
and are not a named addressee, please delete it and notify the Lynx
Financial Systems IT Department on 0113 2892990.



Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Phoebus Dokos

On Wed, 19 Feb 2003 12:18:29 +0100, TonyTebby <[EMAIL PROTECTED]> 
wrote:


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.

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).


Hello Tony,
My only comment regarding FoxPro is historical. FoxPro is NOT based on M$ 
Software (ie it did that way before FoxBase was bought off my Microsoft 
so they could use the Rushmore engine for Access. Many of the scripting 
technologies M$ uses now incorporated Fox technologies (As per usual if 
they can't replicate it, they buy it :-)

Phoebus

P.S. On the other hand S(uper) Basic does things most languages can't even 
dream of doing (In that aspect it would be rather interesting to see a .NET 
implementation of S*Basic) like for example the power of its coercive 
features is unknown anywhere!
Try to add floating point numbers (of a standard S*Basic size) with a 
number string and integers in ANY other language... The results are rather 
interesting ;-) (If not incomprehensible ;-))) C++ is such an example :-). 
Not to mention that creation of strings that can make parts of commands 
that are almost impossible to do (without a lot of extra code) anywhere 
else.
Recently someone at the university asked me why I still used SBasic (and I 
usually bring to the labs a QPC Zip disk)... I challenged him to do a 
vector addition program (with Graphics) in any Basic and it to be under 5 
lines of code and it to be precise enough for the results to be used as 
scientific-grade data guess what? He couldn't ;-)

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Marcel Kilgus

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




Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread Marcel Kilgus

TonyTebby wrote:
> Preprocessor macros, however, provide a great way of writing C programs so
> that they are not nearly undecipherable as usual, but totally
> incomprehensible.

Some guy once said that checking whether the syntax of a C source is
valid is equivalent to the Touring machine halt problem. I think he
had a point.

Marcel




Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread TonyTebby

Macro substitution would be very easy to implement as a pre-parser pass but
this would not provide run-time evaluation of run-time generated statements
(e.g expressions typed in by the user or the example given by François Van
Emelen).

Preprocessor macros, however, provide a great way of writing C programs so
that they are not nearly undecipherable as usual, but totally
incomprehensible.

Tony Tebby


- Original Message -
From: "Timothy Swenson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: mercredi 19 février 2003 05:50
Subject: Re: [ql-users] Sbasic and macro substitutions


>
> I don't believe there is a way of performing macro substitution in S*BASIC
> programming.  Now, it can probably be implemented in one form or another.
>
> The most obvious is a pre-processor that takes a macro and expands it
> before the program is actually sent to a compiler or parser.  C has a
> pre-processor that does exactly this.
>
> Another way to do it is to create a macro in a text editor that does the
> substitution for you.  Either as a form of pre-processor, or as a keyboard
> shortcut.
>
> I don't think it is possible inside S*BASIC, as this would require a
change
> in the S*BASIC code.
>
> Structured SuperBasic (SSB) is a form of pre-processor that does things
> like conditional compilation (IF DEF's), combining S*BASIC modules into
one
> program (#INCLUDE statement), and so on.  Some form of substitution could
> be implemented.  If you feel adventure some, the SSB source code comes in
> the package and you can take it as a start and go from there.
>
> Tim Swenson
>




Re: [ql-users] Sbasic and macro substitutions

2003-02-19 Thread TonyTebby

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.

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).

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 substitutions


>
> Hi 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
>