解决c#中的相似方程 [英] Solve the matematical equation in c#

查看:70
本文介绍了解决c#中的相似方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生



i操作此3(4 * 2)它显示语法错误,我如何检查用户输入表达式的格式是否正确。

如果我替换(用'*('那么如果我有等式3((482/100)* 2)产生问题请告诉我是否有人有解决方案

Dear Sir

i operate this 3(4*2) it shows syntax error and how can i check the user input expression is in correct format.
if i replace ( with '*(' then if i have equation like 3((482/100)*2) create problem please tell me if anyone have solution of it

推荐答案

取决于你如何评估你的表达式 - 你没有这么说我们必须猜测 - 你要么需要重做你的解析器,要么实际实现你自己的。如果你依赖于有效的编译并且在C#中运行表达式来解决这个问题,那么你从一开始就失败了 - 你无法修改编译器。



你可以拿这样的东西:微小的表达评估器 [ ^ ]并调整它允许你的(非标准的)输入格式。



或者只是告诉你的用户添加一个运算符......
Depending on how you are evaluating your expressions - and you don't say so we have to guess - you will either need to rework your parser or actually implement your own. If you are relying on effectively compiling and running expressions in C# to solve this, then you are on a loser from teh start - you can't modify the compiler.

You could however take something like this: A Tiny Expression Evaluator[^] and tweak it to allow your (rather non-standard) input format.

Or just tell your users to add an operator...


只替换'之后的数字序列('with *(

这样 3((482/100) )* 2)将变为 3 *((482/100)* 2)

[而不是 3 *(*(482/100) )* 2)]



Best,H
Replace only a sequence of a digit following '(' with "*("
This way 3((482/100)*2) will become 3*((482/100)*2)
[instead of 3*(*(482/100)*2)]

Best, H


在你解析语法之前,我建议你做它更常规,例如使乘法运算符'*'是必需的。

一旦你有一个好的语法,那么你可能会找到几个建立的选项实际的解析器(你可以找到现成的解析器,使用工具,在你的应用程序中嵌入一个脚本语言)。
Before you parse the grammar, I suggest you to make it more regular, for instance making the multiplicative operator '*' mandatory.
Once you have a good grammar then you may find several options for building the actual parser (you may find ready-to-use one, use a tool, embed a script language in your application).


这篇关于解决c#中的相似方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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