Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Consider an expression like E:
Java
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.

Java
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
System.out.println("result = " + engine.eval(expr, new SimpleBindings(vars)));
Posted
Updated 20-Nov-16 21:46pm
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900