[AHK v2] Evaluate Function

Post your working scripts, libraries and tools.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

[AHK v2] Evaluate Function

30 Oct 2018, 04:26

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* )* )* )
Last edited by oif2003 on 31 Oct 2018, 16:52, edited 1 time in total.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: [AHK v2] Evaluate Function

31 Oct 2018, 16:45

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
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [AHK v2] Evaluate Function

10 Nov 2018, 06:05

A few simple tests works fine, nice work. Thanks for sharing.

Cheers :wave:.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 35 guests