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

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

问题描述

我有一个多维数组列表,我向用户询问一个公式,然后对其进行评估.问题是我得到这样的用户输入:

 ((a1+a2)/12)*a3

问题是 a1 和 a2 和 a3 指的是列,我必须将其评估为某个值,我完全不知道如何解决这个问题,任何建议或指导都会很棒.此外,每次更新任何列中的值时,此计算值都必须更新.问题是公式不是硬编码的.

解决方案

一种可能性是编写一种解析器.最好使用二叉树结构来表示表达式,而不是列表.>

每个非叶子节点都是一个操作,每个叶子节点都是操作数.

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

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.

解决方案

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天全站免登陆