bokarinho bokarinho - 12 days ago 9
C Question

Evaluate Mathematical Function from String

Can you give me some ideas about how can I make a simple mathematical expression parser in C?

User enters a mathematical function in a string and from the string I want to create the function in C.
eg.

x + sin(2*x)


->
return x + sin(2x);


Thanks in advance.

Answer

You can parse the expression based "Shunting-Yard Algorithm" http://en.wikipedia.org/wiki/Shunting-yard_algorithm. You will need to extend to handle the function calls such as sin, cos etc...

Comments