Sign in to follow this  
Deltasquadron2

Store Mathematical expression into a String

Recommended Posts

Deltasquadron2    121
Does anyone know how to put a mathematical expression into a string, including variables, and have it parsed? In otherwords, I want to put my math into an external file and then be able to read it back in. I'm working with C#. Thanks! [Edited by - Deltasquadron2 on August 19, 2006 11:34:30 PM]

Share this post


Link to post
Share on other sites
CTar    1134
A string would be an extremely bad representation for an expression. As I think Zahlman is refering to, you should study some of the technologies used for parsing normal programming/scripting languages. After that, depending on what you need to do, you need to look up some algorithms used for this kind of stuff. Or if you need some fun, try to make them yourself, then look up the real algorithms to see how much you can improve yours.

Share this post


Link to post
Share on other sites
ToohrVyk    1595
Simple method 1: mark your entire expression tree as serializable, write it to file (results in a binary file).

Simple method 2: mark your entire expression tree as XML-serializable, write it to file (results in an XML file).

Harder method 1: perform a prefix-traversal of your expression tree with spaces between each node (this will result in prefix polish notation storage). Reloading is then a simple recursive algorithm.

Harder method 2: reuse or implement a full-scale parser for a script language that suits your needs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this