Abstract
We are creating an application where a user creates a formula with data sent in by labs.
I am currently creating a heavily parsed string to determine if the numbers are variables, constants, or a math function.
For example,
If the user makes a formula that is:
Constant_Id_2^(5 + Model_Alpha) / (Constant_Id_1 * 2)
I would parse it like:
'POW(|2|,((5+{1})/(|1|*2)))'
I would then save that and parse it back out. Where my parser knows that
'string()' or 'string(,)' = Math function
{m_id} = Model Reference
|c_id| = Constant Reference
Models need to be able to go get the model variable from the correct group and check if it has a defined coefficient based on the value.
Constants are just that, values that don't change but represent something.
As you may have guessed, this can become error prone with nesting or other things I cannot anticipate. The code is complicated not the easiest to understand. Even with comments. I want less error prone and easier to understand/read code.
This brought me to thinking about something I saw in my Data Structures Class
Binary Tree
Carrano, Frank M., and Timothy Henry. Data Abstraction & Problem Solving with C : Walls and Mirrors. 6th ed., Pearson, 2013. FIGURE 15-3 Binary trees that represent algebraic expressions
My question is:
With this tree, do I want it to be a Binary Search Tree? I don't think so because this does not have to be searched. Just traversed.
Do I care about the balance of the Tree? Meaning, if there will be nesting, will balancing out the tree mess with the expression? Or is there a way to keep it balanced and maintain the expressions order of operations?
I just started learning about trees and I only just made a Binary Tree and then a Binary Search Tree the other day.
I know of other trees such as a 2-3 tree, 2-3-4 tree, and a red-black tree.
Would any of those be better for this kind of application?