Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mathematical expression translator
#25
You are very welcome Ralph, I am glad it helped!

Hi LPG,

If I may give you a tip ?
Use an array to split the whole input string in to tokens.
This makes it easier to keep track of symbols like brackets etc. and once you know where to place the pow statement you can simply change the array.

So (5^5)^5 could look like this:
Token$(1) = "("
Token$(2) = "5"
Token$(3) = "^"
Token$(4) = "5"
Token$(5) = ")"
Token$(6) = "^"
Token$(7) = "5"

To become pow((pow(5,5)),5)

Token$(1) = "pow" + Token$(1)
Token$(2) = "(pow(" + Token$(2)
Token$(3) = ","
Token$(4) = "5"
Token$(5) = ")" + Token$(5)
Token$(6) = ","
Token$(7) = Token$(7) + ")"

Note that all tokens which are ^ simply become a comma.
The trick is to take track of the brackets!

I hope that helps.

And then one more tricky example when it comes to unary operators Wink
If -8 - -5 = 1 - -2 ^ 2 Then
Becomes
If -8 - -5= 1- -pow(2,2) Then

Cheers,
Frontrunner

Reply


Messages In This Thread
Re: Mathematical expression translator - by Ralph - 04-23-2008, 05:40 AM
Re: Mathematical expression translator - by Ralph - 04-23-2008, 11:09 PM
Re: Mathematical expression translator - by Ralph - 04-24-2008, 02:56 AM
Re: Mathematical expression translator - by Ralph - 04-24-2008, 07:51 AM
Re: Mathematical expression translator - by Ralph - 04-25-2008, 07:40 PM
Re: Mathematical expression translator - by Ralph - 04-26-2008, 12:40 AM
Re: Mathematical expression translator - by Ralph - 04-26-2008, 04:33 AM
Re: Mathematical expression translator - by Ralph - 04-29-2008, 08:30 AM
Re: Mathematical expression translator - by LPG - 04-29-2008, 10:57 AM
Re: Mathematical expression translator - by Frontrunner - 04-29-2008, 07:49 PM
Re: Mathematical expression translator - by LPG - 04-30-2008, 09:06 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)