convert string into operators

Jun 29, 2008 at 6:22am
Hi,
I want to design a program that takes string as input and convert it to arithmetic form and give arithmetic output

eg
Input string:1+(49/(14/2))
Output:8

Thus the program should convert the string elements (like +,-,( etc.) into operators and process the input.BUT HOW?HuhHuh

IDEAS PLZ
Jun 29, 2008 at 9:14am
closed account (z05DSL3A)
You can look up "Recursive descent parser" on the net or read the post
http://www.cplusplus.com/forum/general/1116/page2.html ( the post that starts "Here is some code put together from Stroustrups book" has code to do what you want).

HTH
Last edited on Jun 29, 2008 at 9:20am
Jun 30, 2008 at 2:54am
....or you could establish that + and - etc. are not string elements but operators.
a+b is the same as operator+(a,b).

buffbill
Jun 30, 2008 at 4:51pm
Thank you very much I got exactly what I needed!

ARNIE
Jun 30, 2008 at 6:49pm
Google for math parsers :)
Jul 1, 2008 at 11:35am
Hi,
i wrote this simple C++programm in TurboC++ but it Gives me this error:"Declaration syntax error and it's about using namespace std;" i guess :D.
my programm is this :
#include<iostream>
using namespace std;
int main()
{
int a,b;
int result;
a=5;
b=2;
a= a+1;
result=a-b;
cout<<Result;
return0;
}
Jul 1, 2008 at 11:53am
closed account (z05DSL3A)
AFAIR, Turbo C++ is old and does not support namespaces.

You could try removing the using namespace std; line to see what it does. (I'm sure return0; is a typo that should be return 0; and cout<<Result; should be cout << result;)

If it works without the using line, I would consider getting hold of a newer compiler, the forums are full of suggestions.

HTH

EDIT: Looks like I might have been misguided about the aged of Turbo C++ (if you have Turbo C++ Explorer edition). I thought Borland had Kill the Turbo C++ name long ago.
Last edited on Jul 1, 2008 at 12:12pm
Topic archived. No new replies allowed.