bokarinho - 1 year ago 76

C Question

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 Source

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...