• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Mathematical expression translator Agamemnus Posting Freak Posts: 3,368 Threads: 195 Joined: Jan 2003 08-06-2008, 01:17 AM (04-29-2008, 10:57 AM)LPG link Wrote:I tried this from QB > C. i made it do this:put spaces between expressions and operators find the ^ search left until it finds a space. if it sees a ) forget spaces until it comes to a ( put "pow(" in do the same going right but add ")" put spaces in again the only error is that it searches from left to right so for: Â  Â  (5^5)^5 it returns: Â  Â  (pow( 5, 5) )pow( ,5) but for something like this: Â  Â  5^5 it returns: Â  Â  pow(5,5) it should look from the inside brackets to the outside brackets but i don't know how to do that. Â  Â  LPGÂ  Â  Â  Â  Â  The way you described it won't work with the second example either. You did do the right thing by going left to right, I think. A few pointers of my own: * Instead of adding spaces you could instead remove them. It is less mess when you try to parse it later. * In the same manner, it's less trouble to parse later when you add ()s between the start and end of numbers that have ^ powers. So 5^2 would become (5)^2. GENERAL pointers: * You can either do an iterative parser or a recursive parser: a recursive parser would try to find whole power sets and recursive deeper for each new one, while an iterative parser would have to keep track of the "tree"... Find the end of the expression (in this case ")^"), then find its end. In either recursive or iterative case, you keep searching for either the start of the expression (a "(") or the "end" of a new one --")^". In either case you need to counting non-power ending parentheses and ignore a corresponding amount of starting parentheses. It gets just a little bit complicated but basically you want to be able to parse something like "(5*(5+2))^5"... Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war." Visit www.neobasic.net to see rubbish in all its finest. « Next Oldest | Next Newest »

 Messages In This Thread Mathematical expression translator - by Frontrunner - 04-21-2008, 06:15 PM Re: Mathematical expression translator - by wildcard - 04-21-2008, 11:48 PM Re: Mathematical expression translator - by Frontrunner - 04-22-2008, 12:08 AM Re: Mathematical expression translator - by wildcard - 04-22-2008, 12:17 PM Re: Mathematical expression translator - by Frontrunner - 04-22-2008, 02:57 PM Re: Mathematical expression translator - by Ralph - 04-23-2008, 05:40 AM Re: Mathematical expression translator - by Frontrunner - 04-23-2008, 11:54 AM Re: Mathematical expression translator - by Ralph - 04-23-2008, 11:09 PM Re: Mathematical expression translator - by Frontrunner - 04-24-2008, 01:25 AM Re: Mathematical expression translator - by wildcard - 04-24-2008, 02:06 AM Re: Mathematical expression translator - by Frontrunner - 04-24-2008, 02:52 AM Re: Mathematical expression translator - by Ralph - 04-24-2008, 02:56 AM Re: Mathematical expression translator - by wildcard - 04-24-2008, 03:19 AM Re: Mathematical expression translator - by Ralph - 04-24-2008, 07:51 AM Re: Mathematical expression translator - by Frontrunner - 04-25-2008, 01:39 AM Re: Mathematical expression translator - by wildcard - 04-25-2008, 02:30 AM Re: Mathematical expression translator - by Frontrunner - 04-25-2008, 03:23 PM 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 Frontrunner - 04-26-2008, 01:59 AM Re: Mathematical expression translator - by Ralph - 04-26-2008, 04:33 AM Re: Mathematical expression translator - by Frontrunner - 04-26-2008, 01:48 PM 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 wildcard - 04-30-2008, 02:53 AM Re: Mathematical expression translator - by Frontrunner - 04-30-2008, 03:06 AM Re: Mathematical expression translator - by LPG - 04-30-2008, 09:06 AM Re: Mathematical expression translator - by Frontrunner - 04-30-2008, 02:27 PM Re: Mathematical expression translator - by Frontrunner - 05-03-2008, 07:16 PM Re: Mathematical expression translator - by yetifoot - 05-07-2008, 07:37 PM Re: Mathematical expression translator - by Frontrunner - 05-08-2008, 03:23 AM Re: Mathematical expression translator - by wildcard - 05-13-2008, 06:26 PM Re: Mathematical expression translator - by Frontrunner - 06-02-2008, 02:23 AM Re: Mathematical expression translator - by wildcard - 06-04-2008, 12:29 PM Re: Mathematical expression translator - by Agamemnus - 08-06-2008, 01:17 AM

Forum Jump:

Users browsing this thread: 2 Guest(s)