MathML has both a semantic and a presentation bonus. Thus, a common MathML analyzer for evaluation is not possible.
I donβt know about the real implementation, some quick Googling did not find any reasonable results, but basically it comes down to writing your Polish expression interpreter (as an example that you gave in Polish notation). Steps:
- get the XML parser and read in the document
- go through a tree
- if you encounter a known operation or item, put it on the stack
- when the subexpression is complete, analyze it (or better: wait for the entire expression to complete, find the last operation, execute it with the number of arguments that its attribute prescribes and execute it until no operations are left)
In the end, you will get the result on the stack.
Pieter
source share