Southperry.net
[Java] Class Hierarchy Design - Serious Help Needed! - Printable Version

+- Southperry.net (https://www.southperry.net)
+-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14)
+--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58)
+--- Thread: [Java] Class Hierarchy Design - Serious Help Needed! (/showthread.php?tid=7917)



[Java] Class Hierarchy Design - Serious Help Needed! - Conciente - 2009-02-02

This one... I have NO CLUE how to even start. I hate the teacher because he doesn't want us to ask any questions to him so I'm back here requesting help.

Design a class hierarchy that allows to determine the type of result of an expression following the precedence and combination rules of the C language. The expression is to be supplied as a String using, instead of variables, the type corresponding to each one of them.

For example, assuming the following group of declarations and expression:

int a;
float b;
char c;

b= a / c + (c + 25)

the corresponding String would be supplied as:

float = int / char + (char + int)
resulting in a float.




--------------------------


*lost*


[Java] Class Hierarchy Design - Serious Help Needed! - Spaz - 2009-02-02

This is a classic problem, although the more typical form is to evaluate a numeric expression without any variables.

1. Parse the expression into tokens.
2. Convert from infix to postfix.
3. Evaluate.

Google is your friend if any of those steps confuse you.


[Java] Class Hierarchy Design - Serious Help Needed! - GummyBear - 2009-02-02

Its a basic parsing problem. What you need is a tokenizer to break the string into "tokens", a parser to parse the string for correct syntax and objects creation. The class hierachy should be something like this:

basic
class Char
class Int
class Float

expressions
class Add
class Divide
class Bracket

As you can see, Add and Divide take in 2 arguments, Bracket takes 1, etc. The rest you should learn for yourself.