Currently, I am in the process of developing a program that can solve matrix equations. My main focus right now is on making sure the parser functions correctly. However, I am feeling lost and unsure of where to begin.
In my program, I utilize an array of strings to keep track of both matrices and operators. For instance, if we take the equation
[[0, 0],[4, 5]] + [[4, 8], [12, 6]]
it would be organized as:
variables = ["$", "+", "$"]
matrices = [[[0, 0],[4, 5]], [[4, 8], [12, 6]]
Here, each "$" symbol represents a distinct matrix stored in a separate array. Additionally, I aim to encapsulate matrices within different expressions like so:
det([[0, 0],[4, 5]]) + inv([[0, 0],[4, 5]] + [[4, 8], [12, 6]])
where "det" and "inv" signify determinant and inverse operations respectively.
If represented in code, the above expression would look like this:
variables = ["d", "e", "t", "(", "$", ")", "+", "i", "n", "v", "(", "$", "+", "$", ")"]
matrices = [ [[0, 0],[4, 5]], [[0, 0],[4, 5]], [[4, 8], [12, 6]] ]
My initial thought is to utilize context-free grammars for constructing a parse tree, as regular expressions may not be suitable due to the presence of parentheses... (?). Another idea I have is to convert the expressions into postfix notation and test its feasibility.