convert string into operators

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
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
....or you could establish that + and - etc. are not string elements but operators.
a+b is the same as operator+(a,b).

buffbill
Thank you very much I got exactly what I needed!

ARNIE
Google for math parsers :)
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;
}
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
Topic archived. No new replies allowed.