Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I convert String to an executable statement 1

Status
Not open for further replies.

gismo

Technical User
Jul 24, 2002
35
US
I'm passing an mathematical equation as a string from visual basic to a C function the contents of the LPCSTR would look like

SI0=(SI1 + SI2) * SI3 / SI4;
Where SI1,SI2,SI3, and SI4 are variables that exist in the function. How do I convert the string into an executable line of code.
 
1) Parse the expression and convert it to reverse polish notation (RPN)
2) Execute the expression in reverse polish

The simplest method of parsing is recursive descent. Work out the grammar of your expression and write the rules (in BNF). Then write one routine for every rule.

As you are parsing, you can convert the expression into RPN. eg

SI0=(SI1 + SI2) * SI3 / SI4

becomes

SI1 SI2 + SI3 * SI4 / SI0 =

 
Thanks xwb for your suggestion. I was hoping it would be simpler than that After reading your response I searched the web again based on the information you gave me and found some code at that will do it for me.Thanks again for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top