Re: Evaluate basic arithmatic in a string

From: David Morris (dmorris_at_dynamicquest.com)
Date: 04/02/04


Date: Fri, 02 Apr 2004 10:48:20 -0500
To: Mykola Rabchevskiy <chief@ockhamstyle.com>

Ok, this is an excellent suggestion to start solving the problem.

I have coded your suggestion, sort of.

To do this, correct me if I am wrong, I will still need 5 conditional
tests to hardwire the coding for each restriction level one I decide
which one to use.

I can almost accept that to simple do the casting. However, then I need
to do the evaluation. In the case I gave you is "+=". It could be any
arithmetic function ( a + b / d * c ).

Can I then run a common method to do the evaluation whatever the type
is? I can parse through and set a, b, c, and d to the same type based
on the functionality you have already provided. But how can I
generically to math against the values regardless of their type?

Thanks again for the help.

Mykola Rabchevskiy wrote:

> Order types by restriction level:
>
> type: double float long int short
> level: 0 1 2 3 4
>
> and cast operand with have higher level to type of lover level,
> then perform operation using two operands with same types.
>
>
> David Morris wrote:
>
>> OK, this is for you experienced Java programmers out there.
>>
>> I have a string that contains the following value:
>>
>> "myValue += 5"
>>
>> I need, in Java, to be able to evaluate this expression.
>>
>> Caviots:
>> myValue can be int, float, long, double, or short.
>>
>> Likewise, the 5 could also be a variable of any of the above listed
>> types. ie, "myValue += myValue2".
>>
>> Just so you know the environment, I an writing a java scripting
>> janguage where I can have a user build a template on the fly and I
>> interpret all the java code manually. I am about 75% finished
>> mimicing the JVM in the scripting but am lacking basic math functions.
>>
>> I use a class
>>
>> class ObjDef {
>> Object value;
>> Class className;
>> }
>>
>> to store and pass values throughout the script interpretation process.
>>
>> so I know the value and class of myValue and myValue2 and I know to
>> cast 5 to an int if not otherwise set.
>>
>> The real caviot comes in that if myValue is an int, the className in
>> ObjDef is int but the Object is Integer.
>>
>> How do I get myValue ( which is really ObjDef.value ) to an int so I
>> can do an actully myValue = myValue + 5 and put it back in the ObjDef
>> class?
>>
>> Realize if I do a hard cast, 25 different possible combinations (5^2),
>> so I am looking for a different answer.
>>
>> Thank you for any help you can offer.
>>
>



Relevant Pages

  • Re: Evaluate basic arithmatic in a string
    ... this is an excellent suggestion to start solving the problem. ... this is for you experienced Java programmers out there. ... >> myValue can be int, float, long, double, or short. ...
    (comp.lang.java.developer)
  • Re: Evaluate basic arithmatic in a string
    ... this is an excellent suggestion to start solving the problem. ... this is for you experienced Java programmers out there. ... >> myValue can be int, float, long, double, or short. ...
    (comp.lang.java.help)
  • Evaluate basic arithmatic in a string
    ... this is for you experienced Java programmers out there. ... myValue can be int, float, long, double, or short. ... ObjDef is int but the Object is Integer. ...
    (comp.lang.java.developer)
  • Evaluate basic arithmatic in a string
    ... this is for you experienced Java programmers out there. ... myValue can be int, float, long, double, or short. ... ObjDef is int but the Object is Integer. ...
    (comp.lang.java.help)
  • Evaluate basic arithmatic in a string
    ... this is for you experienced Java programmers out there. ... myValue can be int, float, long, double, or short. ... ObjDef is int but the Object is Integer. ...
    (comp.lang.java)