如何评估 MathML 表达式? [英] How to evaluate MathML expressions?

查看:35
本文介绍了如何评估 MathML 表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到一些 MathML 内容:

Given some MathML content:

<apply>
  <eq/>
  <ci>c</ci>
  <apply>
    <plus/>
    <ci>a</ci>
    <ci>b</ci>
  </apply>
</apply>

std::map<std::string,std::double> cal;
cal["a"] = 1.;
cal["b"] = 2.;
cal["c"] = 0; // does not matter what c is

我希望评估 MathML 并检索结果.有没有办法做到这一点?

I wish to evaluate the MathML and retrieve the results. Is there any way to do this?

推荐答案

MathML 既有语义标记,也有表示标记.因此,用于评估的通用 MathML 解析器是不可能的.

MathML has both semantic and presentational mark-up. So a generic MathML parser for evaluation is not possible.

我不知道实际的实现,一些快速的谷歌搜索没有找到任何合理的结果,但它基本上归结为编写你的波兰语表达式解释器(因为你给出的例子是波兰语表示法).步骤:

I don't know of an actual implementation, some quick Googling did not find any reasonable results, but it basically boils down to writing your Polish expression interpreter (as the example you gave is in Polish notation). The steps:

  1. 获取 XML 解析器并读取文档
  2. 穿过树
  3. 如果遇到已知操作或元素,将其弹出堆栈
  4. 当子表达式完成时,解析它(或者更好:等待整个表达式完成,查找最后一个操作,用它的arity规定的参数数量执行它并执行此操作,直到没有任何操作)

最后你的结果会出现在堆栈中.

At the end you'll have your result on the stack.

这篇关于如何评估 MathML 表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆