java中的数学表达式解析器

编程入门 行业动态 更新时间:2024-10-18 06:12:57
本文介绍了java中的数学表达式解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑像E这样的表达式:

123 * x + 456 * y * 12 - 200 / z

遵循以下规则: 1.可能包含操作数:+, - ,*,/ 2.可能包含变量(如'x') 3.可能包含常量(如'123') 4.不包含括号。 应该充分利用OOP原则。 有人可以帮我写一套Java类来完成这个吗? 什么我试过了: 我尝试过使用ScriptEngine。但是我不能使用那些ScriptEngine。

ScriptEngine engine = new ScriptEngineManager ()。getEngineByName( JavaScript); System.out.println( result = + engine.eval(expr, new SimpleBindings(vars)));

解决方案

这是一项任务:这样你就可以学习编程语言,OOP,数据结构的概念。 我不确定为什么要使用ScriptEngine,因为你需要制作解析器,而不是显示它的用法。 数学表达式解析简单指南 [ ^ ],这篇文章有很好的表达材料解析。

Consider an expression like E:

123 * x + 456 * y * 12 - 200 / z

which follows the rules: 1. may contain operands: +,-,*,/ 2. may contain variables (like 'x') 3. may contain constants (like '123') 4. does not contain parenthesis. Focus should be put on good use of OOP principles. Can someone help me to write a set of Java classes to accomplish this? What I have tried: I have tried using ScriptEngine. However I cant use those ScriptEngine.

ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); System.out.println("result = " + engine.eval(expr, new SimpleBindings(vars)));

解决方案

This is an assignment: so that you can learn concepts of programming language, OOP, data structures. I am unsure why ScriptEngine is being used since you are required to make the parser, not show its usage. Simple Guide to Mathematical Expression Parsing[^], this article has good material on expression parsing.

更多推荐

java中的数学表达式解析器

本文发布于:2023-11-10 16:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   数学   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!