Page 1 of 1

[AHK v2] Evaluate Function

Posted: 30 Oct 2018, 04:26
by oif2003
Hi, here's something I have been toying with. It can evaluate functions/methods and can access/define global variables/arrays/objects. It can only access array/objects through a[1][2][3]... form (does not support a.b.c.d form or a[1,2,3...] form). It does not recognize operators, so everything needs to be wrapped in a function. The ones I wrote can be found inside class f (f.add, f.mul, f.div ...). I have also written some basic Boolean logic functions (AND, OR) and they support short-circuiting (f.and, f.or). There is also a simple if/else function (f._if). If everything is working properly you should be able to nest functions/arrays inside each other.

I originally built this with the intention of using this over WM_COPYDATA so I can remote control my scripts and not have to write extra wrapper functions.

edit1: Having trouble with indentation. GitHub: https://github.com/oif2003/AHK_v2_64bit ... r/eval.ahk
edit2: Added support for nested variadic functions. ie: f( g( h( param* )* )* )

Re: [AHK v2] Evaluate Function

Posted: 31 Oct 2018, 16:45
by oif2003
Added support for operator notations. The script now does the following:
1) User input string for evaluation
2) Save all string literals (stuff inside quotation marks) and replace them with tokens
3) Convert Infix operators to Prefix (functions)
4) Parse the functions based on its type:
  • a) string - get rid of quotation marks
    b) function / method - evaluate
    c) object / array - get its value
    d) number - convert it from string to value (=> number + 0)
    e) variable - %variable%
    f) keep parsing until we get one of the above
Supported operators: ** , ! , * , / , // , + , - , . (string concat) , ~= (regex) , > , < , >= , <=, = , == , != , && , || , ?:(ternary), :=(assignment)

Currently, arrays and objects must be referred to in a[1][2][3]... form
Assignments such as a:=[1,2,3] is not supported. Use a:=Array(1,2,3) instead

Edit: Added Ternary operator support

Re: [AHK v2] Evaluate Function

Posted: 10 Nov 2018, 06:05
by Helgef
A few simple tests works fine, nice work. Thanks for sharing.

Cheers :wave:.