我将如何评价某个公式? [英] How would I Evaluate a certain formula?

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

问题描述

我有一个多维ArrayList和我要求用户提供一个公式比我评价它。问题是,我得到用户输入的是这样的:

I have a multidimension arrayList and I ask the user for a formula and than I evaluate it. The problem is that I get user input like this:

  ((a1+a2)/12)*a3

问题是,A1和A2和A3引用列,我必须把它计算到一定值时给它,我完全失去了对如何处理这个问题的任何意见或指导意见将是巨大的。还这个计算值具有更新每次在任何列更新的值。问题是,这个公式并不难codeD。

the problem is that a1 and a2 and a3 refer to columns and I have to evaluate it to a certain value to it and I am totally lost on how to approach this problem any advice or guidance would be great. Also this calculate value has to update every time the value in any of the columns Update. The thing is the formula isn't hard coded.

推荐答案

一个可能性是写一种解析器。这是更好地使用二叉树结构重新present一个前pression,而不是一个列表

A possibility is write a sort of parser. It's better to use a binary tree structure to represent an expression, rather than a list.

每个非叶结点是一个操作,每一个叶是操作数。

Each non-leaf node is an operation and every leaf is operand.

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

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