Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: General Purpose Eval

  1. #11
    Member JosephE's Avatar
    Join Date
    Jul 2010
    Age
    21
    Posts
    85
    Blog Entries
    5
    Rep Power
    12

    Re: General Purpose Eval

    Thanks Eros, I wasn't too familiar with the Format$() function.

    Why does this return 1? Eval_Math() returns 0 correctly. In my implementation, I'm blind as to what we're evaluating. So how do I tell which evaluator is right?

    Your code checks to see if the number from string and the string are the same thing. If they are, it assumes it's a number. But in this case, it's different (for some reason unknown to me), so it's throwing it off.

    Uses "Console"
    Uses "Eval"
    
    PrintL Evaluate("1 = 0")
    
    WaitKey
     
    Function Evaluate(strng As String) As String
     Return Eval_String(strng)
    End Function
    
    Last edited by ErosOlmi; 10-05-2011 at 21:23.

  2. #12
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,551
    Blog Entries
    2
    Rep Power
    10

    Re: General Purpose Eval

    Mainly because all logical comparisons are numerical expressions and not string expressions.

    "1 = 0"
    is a numerical expression and has no meaning for a string expression.

    STR$(1 = 0)
    is a string expression and here 1 = 0 will correctly be evaluated as 0 because STR$() expect a numerical expression.

    Of course I can improve Eval module but I would go far behind its purpose and creating a full interpreter inside an interpreter would require too much time.
    In any case if necessary I can think about it.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #13
    Member JosephE's Avatar
    Join Date
    Jul 2010
    Age
    21
    Posts
    85
    Blog Entries
    5
    Rep Power
    12

    Re: General Purpose Eval

    Don't worry about it for now, I'll survive without it for the time being. Although I probably will need this when development gets further along.

  4. #14
    Member JosephE's Avatar
    Join Date
    Jul 2010
    Age
    21
    Posts
    85
    Blog Entries
    5
    Rep Power
    12

    Re: General Purpose Eval

    This here produces the correct result on string, number, and comparison results:

    I'm happy.

    Uses "Console"
    Uses "Eval"
    
    PrintL Evaluate("Str$(1 = 1)")
    PrintL Evaluate("1=0")
    PrintL Evaluate("""1""")
    PrintL Evaluate("Format$(Len(Parse$(""hello, world"","" "", 1)))")
    PrintL Evaluate("Parse$(""hello, world"","" "", 1)))")
    PrintL Evaluate("15>5")
    PrintL Evaluate("15+sin(15)/(10^2)")
    
    WaitKey
     
    Function Evaluate(strng As String) As String
     Dim expression, original As String
     expression = ("Str$(" & strng & ") & """"")
     expression = Eval_String(expression)
     original = Eval_String(strng)
     If Format$(Val(Trim$(original))) <> Trim$(original) Then Return original
     Return expression
    End Function
    
    Last edited by ErosOlmi; 10-05-2011 at 21:23.

  5. #15
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    64
    Posts
    54
    Rep Power
    9

    Can EVAL be extended to include all thinbasic functions?

    Hello,

    Is there any way that EVAL can be extended to work with any of the thinbasic functions?

    Or can I create functions that EVAL will work with (in addition to the ones already there)?

    - Mike Peralta

  6. #16
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,551
    Blog Entries
    2
    Rep Power
    10
    No, I'm sorry.

    Eval is just a small interpreter inside an interpreter.

    Maybe in future I will be able to extend in such a way script functions can be used inside Eval but at the moment not.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •