Posted: 25th Aug 2003 8:50
I've been working on it for the past 15 minutes...it's not too good at all yet all it can do is add stuff like 1+x and 2+2 and stuff or do 2^x or 2*x...oh well just look at the code you'll get it...I'll work on it some more later and post a better version
Posted: 25th Aug 2003 14:24
keeblerElf, just a suggestion but you may want to lookup recursive descent algorithms. They are used for interpreted multiple expressions in some parsers.
Posted: 25th Aug 2003 16:44
Sorry to sound like a newbie (I assure you im not) but you only learn by finding out so :

What is a parser?

Ive heard it mentioned but i am unsure what it does.
Posted: 25th Aug 2003 18:35
When DB compiles your code, it (Parses) your source code to compile it into the .EXE that you run. When you Spell check a document, the Word processor Parses your document to find the spelling mistakes. There are many types of parsers, but they all have a common function of scanning the input media and generating an output stream based on the parser's function.
Posted: 25th Aug 2003 19:35
Thanks APEXnow...I've been having trouble figuring out how to evaluate more than 3 terms in the expression...I'm looking up recursive decent algoritms now
Posted: 25th Aug 2003 19:36
Moonshine...the parser I'm trying to make will evaluate an expression like "2^x" when x=1 or 2 or 3....
Posted: 25th Aug 2003 21:53
Thanks for clearing that up guys.
Posted: 26th Aug 2003 15:16
I once manged to get a VB app to interface with a DB app and evaluate expressions - you could write something like so:

+ Code Snippet
print eval("(1 + (4+5))*10")


and 100 would be printed. The only downside is it's really slow, 0.2s to evaluate one phrase

I'll post a demo tonight.
Posted: 1st Sep 2003 6:37
I couldn't find anything on the internet to help me so I went on with mine...so far it allows you to use any positive or negative real number and +,-,/,*,^ and sin and cos. I'm still having trouble with the damned parenthesis I'll post it once I can get the parenthesis to work
Posted: 5th Sep 2003 19:02
There was an article in the last couple of months in a UK magazine that showed you exactly how to do this. You could take an expression with an unlimited number of operations and evaluate it.

Just wish I could remember the mag date. It was by that Wilf Hey guy in PC Plus.
Posted: 12th Sep 2003 0:19
Yeah I've figured it out already and it works fine...decimals and fractions and parentheses and sin cos tan ln all that stuff...I'll put it up here once I get back to my comp at home
Posted: 22nd Sep 2003 8:03
Sorry it took so long...computer was broken...anyways there are 4 functions, but you only really need two. The other two functions are so you can use the natural logarithm command...The parser allows you to evaluate expressions like

(sin(x)/cos(x))*2+1

and so on and so on...it ignores "white space". Sorry if you try to read the code and figure it out, I'm not very organized and my coding shows that very well. If you need me to explain something just ask. Also I took the Midstr$ function off TDK's website, I needed the old qbasic Mid function and I found it on his website, thanks.
Posted: 22nd Sep 2003 8:05
Oh there are only two constants in it right now..."pi" and "e", and if you want to use radians instead of the normal darkbasic degrees than you would use the "rad" command. If I wanted to find the cosine of pi radians I would type

cos rad pi

or

cosradpi

or

cos(rad(pi))

or anything along that sort
Posted: 27th Sep 2003 4:04
Okay, here is my situation. I am writing a code to allow a user to enter a formula using three variables (X,Y,Z). The program will then use this formula, along with other properties to draw a graph on the screen. I have everything coded for the calucations and the drawing, however, I cannot get the user inputted formula to be used in the calculations. I have to enter it in manually into the code. Is there a way to modify your code to do this? And if so, how?

Thanks.
Posted: 27th Sep 2003 4:07
Oops, I tried to add a small section of my code as an example.
I will try again.
+ Code Snippet
Y#=YU
While Y#>YL
	X#=XL
	B=0
	While X#<XR
		Z#=(Y#-1)*(X#+2)*X#*X# 
		IF Z#>H OR Z#<HL THEN B=0:GOTO 34
		XX#=X#*XINC#
		YY#=XX#*ISO#
		XX#=XX#-Y#*YINC#
		YY#=YY#+Y#*YINC#*ISO#
		YY#=YY#+Z#*ZINC#
		YY#=191-YY#-DBG#
		XX#=XX#+159
		IF B=1 THEN LINE XX2#,YY2#,XX#,YY#:Goto 34
		DOT XX#,YY#:B=1
34:
		XX2#=XX#:YY2#=YY#
		X#=X#+RES#
	Endwhile
	Gosub Refill
	Y#=Y#-RES#
Endwhile
Posted: 27th Sep 2003 9:14
Ok try this...I just added a few lines of code to my parser and it should work for f(x,y,z) although I don't know how you would graph that because it would be a 4-d graph...are you sure you didn't want to graph z=f(x,y)?
Posted: 27th Sep 2003 21:30
Actually, you are right. The formula will need to be structured:
Z=(Any function with X & Y), i.e.: Z=sin(x)*cos(y)

Thanks for the code, I will try it, and let you know how it works.
If it works, I may be able to release a beta of my program within a week.

If you think the difference in how the formula is structured to one that may be 4D (The misinterpretation based on my vague describtion). Feel free to let me know.

Thanks again for you help.
Posted: 29th Sep 2003 0:04
I am attempting to use your code in my program. I seem to be having some problems. Question: what version of DarkBasic are you using? I am getting a lot of syntax errors with it.
Posted: 29th Sep 2003 22:43
I'm using darkbasic Pro...it worked fine on my computer and my sister's computer...where does it say the error is occuring?
Posted: 29th Sep 2003 22:46
If you want a z=f(x,y) equation than just change the

+ Code Snippet
for x1=1 to len(fx$)
      temp$=mid$(fx$,x1)
      if temp$="x" then fxs$(x1)=str$(x#)
      if temp$="y" then fxs$(x1)=str$(y#)
      if temp$="z" then fxs$(x1)=str$(z#)
      if (temp$<>"x" or temp$<>"y" or temp$<>"z") then fxs$(x1)=temp$
      if temp$="e" then fxs$(x1)="2.7182"
   next x1


to

+ Code Snippet
for x1=1 to len(fx$)
      temp$=mid$(fx$,x1)
      if temp$="x" then fxs$(x1)=str$(x#)
      if temp$="y" then fxs$(x1)=str$(y#)
      if (temp$<>"x" or temp$<>"y") then fxs$(x1)=temp$
      if temp$="e" then fxs$(x1)="2.7182"
   next x1


and just change the name of the function to fxyeval#(fx$,x#,y#)