tough question for powerbasic 
Author Message
 tough question for powerbasic

i have a program that needs a kind of interactive mode. You can call it an
interpreter if you want.

my program does it's stuff wihout interaction of the user.
I want to build in a testmode.
if you enter this testmode then you can execute any subroutine inside the
program.

'program checkit
on key (F12) gosub testmode
quit=0
do
blahblahblah ....

loop until quit=1

end.
testmode :
input "command";cmd$

if  exist(cmd$) then                        
     call ''cmd$""
 else
     print "unknown command"
end if

sub function1
end sub
sub function2
end sub
sub function3
end sub
'end program

if the user were to enter function1 at the prompt the program would execute
subroutine function1
if he would enter function4 the program would say :unknown command.

Now i know that the fisrt suggestion would be to write an select case tree to
execute the commands.
problem is that such a tree would be way to large.And for every program a new
tree needs to be designed.
I have a huge library with standard routines which i link to my program.
now the compiler only includes the one used in the program. All other routines
are not used.

I was thinking of an approach where you can detect if a routine exists (during
runtime) , detect the adress of it and call it.
There must be a way to do this ?. Or not ??

Then i want to take it even a step further.
I want to implement an interpreter that can execute basic BASIC commands like
print,cls,input,save,load,goto,open a file , write to a file etc ...
That way the user can write small programs inside my program.( Look at them as
scripts or macros)

This program of mine controls equipment attached to the pc. normally the program
is interacting with the user via menus.
For serviceing purposes i want to give the operator the possibility to write
small programs that make the machine do something. But i do not want to give him
control of the entire machine. He would onyl be able to execute the standard
functions of the control library. This will prevent him form executing commands
that could{*filter*}up the whole machine.That is the reason why i will not write my
program in an interpreted basic nor give him a compiler where he can patch the
program ,recompile and run it.

ANy ideas ???



http://www.*-*-*.com/ ~ping0751

:: No user-serviceable parts inside. Warranty void if opened !



Thu, 11 Jun 1998 03:00:00 GMT  
 tough question for powerbasic

Quote:

>I was thinking of an approach where you can detect if a routine exists (during
>runtime) , detect the adress of it and call it.
>There must be a way to do this ?. Or not ??

Tom Werry Writes Back:

---------------
Frohliche Weinachten yourself Vincenzo !
---------------

I usually read very skeptically these newsgroup answers that merely
suggest a method without providing an example/solution, but now I am
about to offer one.

Would a more general approach, if not actually easier to implement, be
to supply at the link map file along with the .exe.  Do a rudimentary
check on dates/times to make sure the map applies to THIS .EXE.

Get any routine entry/offset address required from the map, add the
required program load address offset, and jump to the routine, if it
is there.

This solution is elegent in that it goes to the correct source for the
information you are seeking.  This will probably avoid anything more
serious than a reformatting problem should you wish to utilize this
method with upgraded compilers or even complete different languages or
development systems.

Quote:
>Then i want to take it even a step further.
>I want to implement an interpreter that can execute basic BASIC commands like
>print,cls,input,save,load,goto,open a file , write to a file etc ...
>That way the user can write small programs inside my program.( Look at them as
>scripts or macros)

Cannot help here - I usually do this bit as a machine specific
"language" and interpreter for each different machine - and for the
actual operation of the machine, not for debugging purposes.

Quote:
>This program of mine controls equipment attached to the pc. normally the program
>is interacting with the user via menus.

Just out of interest, what kinds of machines are you making here.  I
have done this as a sideline for some large milling machinery to make
what are called "charge-carrier gun bodies" for tubing-conveyed
perforator guns - strings of oil well casing pipe loaded with shaped
charges.  These are used to punch holes in well casings to begin oil
flow production from the reservoir outside the casing.

My machine looks like a huge long (30')  lathe with a moveable milling
head which can scallop end-mill cuts in any pattern along/around the
outside of the carrier casing.

What has this got to do with basic programming?  Who cares, its REAL.


 Programmer's Logic:  "PUSH ENTER TO EXIT"



Fri, 12 Jun 1998 03:00:00 GMT  
 tough question for powerbasic


Quote:
>I was thinking of an approach where you can detect if a routine exists
>(during runtime) , detect the adress of it and call it.
>There must be a way to do this ?. Or not ??

There are probably several ways to do this, but you're asking for an optimized
method of implementing an extremely inefficient coding design (a
self-interpretive program).

One thing you could do is put at the top of each subroutine some assignment
statement that looks like:

 LET A$="wierdlyconfiguredstring"

Then, you can look at the executable file at run-time for this string value.  
I suppose the logical thing to make these strings would be the names of the
subroutines, but if you use short subroutine names, there is a chance that you
might accidentally "duplicate" those values in your compiled code (somehow,
though I doubt it would be very likely).

Note that this method would require a lot of vicious disk I/O, though you
could build a string at run-time that contained the name of each routine
previously invoked and use INSTR() to decide whether you've already found it.

You could also build a string to indicate which routines were NOT present, to
minimize disk I/O for repeated failures.

However, you might waste a lot of precious memory by doing this.

Here are some less desirable ideas to consider, in case they can be
implemented more easily than I think is possible:

You might look at using numeric variables as boolean indicators.  For
instance, suppose you have a subroutine named GOOP and you want to know if
GOOP is available at run-time.  Do:

  if GOOP then GOOP(params...)

You would have to include a line at the top of the program that says:

  LET GOOP = 1

Of course, this is impracticle with hundreds of subroutines, but you could
probably organize them in some sort of collating sequence and then assign a
string of 1s and 0s to a single variable at the top of the program.  If the
corresponding "1" is in the string, you know the subroutine is there.

Quote:
>Then i want to take it even a step further.
>I want to implement an interpreter that can execute basic BASIC commands like
>print,cls,input,save,load,goto,open a file , write to a file etc ...
>That way the user can write small programs inside my program.( Look at them
>as scripts or macros)

What a pity that powerbasic and the other Microsoft BASICs don't implement the
Business BASIC EXECUTE command.  This command takes a string and treats it as
if it were keyboard input.  You could, in theory, write a Business BASIC
program that would make use of the subroutine name and place a GOSUB in front
of it to "execute" a GOSUB to that routine.

This still doesn't tell you whether the routine is present in the program, but
you could always put an error branch on the EXECUTE line to pass control of
the program to some routine that could say: "This routine is not present."

Quote:
>This program of mine controls equipment attached to the pc. normally the
>program is interacting with the user via menus.
>For serviceing purposes i want to give the operator the possibility to write
>small programs that make the machine do something. But i do not want to give
>him control of the entire machine. He would onyl be able to execute the
>standard functions of the control library. This will prevent him form
>executing commands that could{*filter*}up the whole machine. That is the reason
>why i will not write my program in an interpreted basic nor give him a
>compiler where he can patch the program ,recompile and run it.

Well, you could get a run-time module for some of the interpretive BASICs,
which doesn't provide a READY> prompt for the user.  That effectively locks
them out of messing with your code.

What you might want to look at, however, is writing a two-stage program that
interprets your subroutines as well as the user input.  This will not execute
as fast as you may want it to, but if you code it well, and depending on what
the routines are expected to do, you may not have any complaints.

The subroutines should be written in a macro language for which all the
appropriate subroutines are present in your "interpreter".  Try to keep the
command set small.  Also, use as many paramter lists as you can, so you can
dynamically create "variables" at run-time and associate the names used in
your sub-routines with the specific addresses you create through VARPTR (my
syntax is rusty, so check me here) or a similar method like use of data types
with pointers.

For instance, suppose your macro language supports an "ADD" command.  You
could make the syntax to be:

  ADD(one,two,three)

Now, let's say you always store the result in the first parameter.

So, you parse the line to see how many parameters there are, creating a
"stack" of the secondary parameters.

You should get three parameters from the parse:

  "one", "two", and "three"
  "two" and "three" will be in your secondary stack

Then you check your variable table for the name "one".  If it's there, you get
the address for that variable and use it.  If it's not there, you create the
"variable" and set it to 0.  "Creation" implies adding the variable into the
table.

Then you parse your stack and for each item in it you retrieve the associated
variable (or create a new one, initializing it to zero) and add that value to
the variable for "one".

NOTE:  If you want to use constants, your parser will either have to look for
something that tags them as constants or you will have to restrict variable
names to start only with letters, and assume anything else is a constant.

You can also implement a label table so that your macro language can support
labels.

Frankly, I think I would try what I suggested at the start of this article,
and if that didn't work, I'd just invest in an interpretive BASIC that lets
me lock out the user (assuming you have the money for that).

--
  ++   ++   "Well Samwise: What do you think of the elves now?"


  ++   ++------------------------------------------------------



Sun, 14 Jun 1998 03:00:00 GMT  
 tough question for powerbasic

Quote:

> Subject: [News] tough question for powerbasic
> Date: Sun, 24 Dec 95 19:23:23 GMT

...... snip .......

Quote:

> ANy ideas ???

Hi, Vincent !

Your question is very interesting. I'd recommend you my solution
(little hint):

   1. Define complete set of functions you need.
   2. Compile them into separate _CHAIN_ modules.
   3. .... - your imagination here.

Now you are ready to solve The Task, using your main module.
It is very short advise, but I think you can solve all your
problems yourself now.

Good luck,
Alexander.



Mon, 15 Jun 1998 03:00:00 GMT  
 tough question for powerbasic

Quote:

>Of course, this is impracticle with hundreds of subroutines, but you could
>probably organize them in some sort of collating sequence and then assign a
>string of 1s and 0s to a single variable at the top of the program.  If the
>corresponding "1" is in the string, you know the subroutine is there.

That's my problem. This program compiles to around 400K of exe code and uses a
huge set of libraries which i am barely able to control.

I cannot swap to an interpreter because of the nature of my program language
(Powerbasic). Lots of routines include Inline assembler, bitbanging, interrupt
rerouting and handling. Arrays of pointers etc. It uses EMM/XMS memory to store
runtime variables etcetera ...

All these features are not available in other basic compilers. So i have to
stick with Powerbasic.

I got some other mails that give me a solution to this problem.
Apparently it is possible to do that in Powerbasic Versnio 3.2.

Regards
Vincent



http://www.ping.be/~ping0751

:: No user-serviceable parts inside. Warranty void if opened !



Wed, 17 Jun 1998 03:00:00 GMT  
 tough question for powerbasic

Quote:


>> Subject: [News] tough question for powerbasic
>> Date: Sun, 24 Dec 95 19:23:23 GMT
>...... snip .......

>> ANy ideas ???

>Hi, Vincent !
>Your question is very interesting. I'd recommend you my solution
>(little hint):
>   1. Define complete set of functions you need.
>   2. Compile them into separate _CHAIN_ modules.
>   3. .... - your imagination here.

Nope , Can't use that approach. This would leave with approx over 500 chain
files  which would hae vto call each other. This would make the system
tremendously slow.

Quote:
>Now you are ready to solve The Task, using your main module.
>It is very short advise, but I think you can solve all your
>problems yourself now.
>Good luck,
>Alexander.



http://www.ping.be/~ping0751

:: No user-serviceable parts inside. Warranty void if opened !



Wed, 17 Jun 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. tough question for gurus!

2. Tough questions...

3. Mathmatical Genious Needed for this tough question

4. TOUGH Question - Late Bound COM objects and VB.NET

5. a few tough questions

6. a few tough questions

7. REALLY TOUGH QUESTION

8. A tough question - but interesting...

9. tough textbox question

10. Animated GIF's - Tough Question

11. I think this is a TOUGH question...

12. Winamp VB Tough Question

 

 
Powered by phpBB® Forum Software