Eval()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J.B.

    #1

    Eval()

    Hi all.
    I'm rather new to C#, (just learning ;-) and i'm making my own 'helper'
    library, in wich i want to
    have an eval(statement) function.

    Anyone know how to make this / help me out on where to start?
    Thanks.


  • Alex Bendig

    #2
    Re: Eval()

    Something like
    string eval(operand1, operand2, operator) { ... } ?

    Basically, you could have different eval methods for different operand
    types, such as:
    string eval(int1, int2, operator) {}
    string eval(double1, double2, operator) {}
    ....

    Of course you could also use a function that simply takes object arguments:
    string eval(object1, object2, operator) {...}

    Within that particular method you could then simply check for the actual
    type of the arguments (using GetType()) and proceed accordingly.

    The operator would be a value representing any one of the opertors you would
    like to support, such as "+", "-", "/", etc.

    In the method body you then require a switch statement in which you check
    for the actual operator and perform the appropriate operation with the
    operands. You would then return a string representation of the result as the
    result of the Eval() function.

    Does that get you started?

    Regards,
    Alex

    "J.B." <Nospam@spammer .nl> wrote in message
    news:3f179210$0 $49104$e4fe514c @news.xs4all.nl ...[color=blue]
    > Hi all.
    > I'm rather new to C#, (just learning ;-) and i'm making my own 'helper'
    > library, in wich i want to
    > have an eval(statement) function.
    >
    > Anyone know how to make this / help me out on where to start?
    > Thanks.
    >
    >[/color]


    Comment

    Working...