bokarinho bokarinho - 1 year ago 82
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.

x + sin(2*x)

return x + sin(2x);

Thanks in advance.

Answer Source

You can parse the expression based "Shunting-Yard Algorithm" You will need to extend to handle the function calls such as sin, cos etc...