Re: Calculator


[ Follow Ups ] [ Post Followup ] [ WWWBoard for 308-203A ] [ FAQ ]

Posted by Will Renner on November 06, 19100 at 18:32:28:

In Reply to: Calculator posted by Steve on November 06, 19100 at 18:16:58:

: Hi.
: This is pertaining to the computeParens method inside the calculator.

: If I find that the operator in question .equals("if"),

: i know that I must evaluate the boolean, and then either compute the nextToken after that, or somehow skip to the location of the second "ifnot" argument.

: How do I find/skip to this second location if the boolean when the boolean is indeed false?


For this phase of the project, at least, it is perfectly acceptable
(and easiest to implement) if you don't explicitly skip the true
(or false) part of the if statement. You evaluate both the "then" and
the "else" and then throw away whichever one you don't
want.

Think of it like this, where x = 3:

(if (> x 5) (+ x 1) (* x 2))

->

(if no 4 6)

->

6

You actually evaluate the first part as well to get 4,
but then throw it away.

In the second phase it will be handy to have a solution
which really does skip the unnecessary computation, but
I'd wait to handle that.



Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ WWWBoard for 308-203A ] [ FAQ ]