Store Mathematical expression into a String

Started by
2 comments, last by ToohrVyk 17 years, 8 months ago
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]
Advertisement
Try reading the FAQ for the Scripting Languages & Game Mods forum.
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.
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.

This topic is closed to new replies.

Advertisement