Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Java] Class Hierarchy Design - Serious Help Needed!
#1
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*
Reply
#2
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.
Reply
#3
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)