PDA

View Full Version : function: eval


Tolnaftate2004
03-24-2008, 05:33 AM
eval()

eval(str) - evaluates/executes a string of GScript.

You asked for it and you got it. eval is a function available in other scripting languages. Its only parameter is a string of code to be executed. This is not so much to show off the script, but rather I hope I can get some input into what this function should do. Useful? Sure. You could save expressions such as "player.hp += this.hpgain;" in mudlib files, or similar. The possibilities are probably endless, but I'm just the guy doing the coding.

Currently supports: strings, arrays, variables, functions, comments, operators
error catching, garbage collection
variable assignment toggling, protection

To be added: flow structures
temp.- variables of calling function accessible
To be limited in final release: for, while, do-while loops
'new' operator
script complexity

If there's something you want to fix/write, go ahead and post your update in this thread. Questions, comments, critique, and requests are welcomed. Please try it and report issues!

I have included an "unstable" version of the parser. It may have some debug messages, etc. This file will be updated more regularly.

Updates: April 16
fixed small bug with constructs like a(2) [the 2 turned into 0].
added support for dynamic variable names this.(@blah).
added support for the [] operator.
April 19
added support for special concatenation operators (SPC, TAB, NL), oops!
tested @ array; it works
April 26
fixed a bug with inserting operators with constructs like h = f(g(x)).
the script is accurately finding functions (there may be some issues). It is not yet calling the functions, though.
April 28, 29, 30
Made the dot operator a LOT faster, yay!
added support for functions, woo!
added comma operator (that should be all of them!)

cbk1994
03-24-2008, 05:41 AM
That's truly amazing, far beyond what I could do.

Inverness
03-24-2008, 05:58 AM
You know once you declare a variable as temp you don't need the temp. for the rest of that function right?

All the temp. is melting my eyes :(

But damn fine job on that eval().

Tolnaftate2004
03-24-2008, 09:12 AM
You know once you declare a variable as temp you don't need the temp. for the rest of that function right?
I know, this is my preference, though.

Tigairius
03-24-2008, 09:41 AM
I know, this is my preference, though.

Mine too, and you always amaze me with your scripts :)

Dan
03-24-2008, 10:44 AM
Nice :)

Tolnaftate2004
03-24-2008, 11:37 AM
Question: should eval be able to access temp. variables declared within the scope that eval is called? e.g.,

temp.a_variable = 74;
eval("this.ihaveadream=temp.a_variable+1");

Otherwise, it would be written to allow the access to only those temp. variables declared within the executed string.
eval("temp.a=37.694; this.oridont = temp.a/6;");

e: I have updated the first post with a new version (actually, several times tonight, so far...)
e2: in and ',' operators are conflicting by precedence (',' < in). Inspire me to solve the problem that is 'in |a,b|'! It's tough to say that ',' could have enough foresight to see it's part of in.

Dan
03-24-2008, 12:43 PM
Read line 242.

Tolnaftate2004
03-24-2008, 12:52 PM
Read line 242.

... Are you getting an error?

xXziroXx
03-24-2008, 01:38 PM
You know once you declare a variable as temp you don't need the temp. for the rest of that function right?

I've encountered several variable names that once set with temp., refuses to work without the prefix.


Nice job pfa. :)

zokemon
03-24-2008, 05:53 PM
Looks good PFA. I'm still going to post mine though when I'm not so busy ^^.

Inverness
03-24-2008, 07:33 PM
I've encountered several variable names that once set with temp., refuses to work without the prefix.That would be because of a static this. variable with the same name, which takes priority.

cbk1994
03-24-2008, 10:37 PM
I know, this is my preference, though.

That's how I do it too, though I will probably stop. I just found out recently you don't need the temp after declaring.

Tolnaftate2004
03-24-2008, 11:52 PM
I have updated the script, it now supports strings. Next I hope to tackle arrays, then variables should follow, should be quite the challenge. :)
@Zero: Stop being lazy. :p

Rapidwolve24
03-25-2008, 12:48 AM
Really nice work.

zokemon
03-25-2008, 10:18 PM
There, I'm not lazy anymore.

cbk1994
03-25-2008, 10:40 PM
There, I'm not lazy anymore.

Sure you are, just slightly less lazy.

zokemon
03-25-2008, 10:43 PM
Sure you are, just slightly less lazy.

:frown:

Rapidwolve24
03-26-2008, 01:44 AM
:frown:

Lol.

Tolnaftate2004
04-03-2008, 04:24 AM
Just released a new version, one is for debug ("unstable"), and the other just has the functions to do the work. This release can catch all variables prefixes excluding temp.-. I fixed some problems (multidimensional arrays, 'error code 2' caused an infinite loop), and errors now tell you exactly what the problem is (and what line, but since only one line is supported so far, it says line 1, hurr). You should be able to do multiple operations, separating them with ;.

If you want to mess with the debug version, just change __debug__ (this is the mode) to somewhere between 0 (none) and 15 (all) and __debug_string__ to whatever you want to evaluate. The debug method does not make a call to eval().

Tolnaftate2004
04-30-2008, 06:05 AM
Hate to double post, but for the sake of the bump...
I've been slowly making progress with this script. Over the past few days, the to-do list has been slowly shrinking. The current version finally recognizes functions (it will say that the function does not exist, but the point is that it finds them correctly). I will release a supplementary script for the functions once I figure out a good way to handle them (must be secure, hoping to minimize the use of function f(p1,p2,...,pN), &c.).

cbk1994
04-30-2008, 06:23 AM
Hate to double post, but for the sake of the bump...
I've been slowly making progress with this script. Over the past few days, the to-do list has been slowly shrinking. The current version finally recognizes functions (it will say that the function does not exist, but the point is that it finds them correctly). I will release a supplementary script for the functions once I figure out a good way to handle them (must be secure, hoping to minimize the use of function f(p1,p2,...,pN), &c.).

Good job ;)

Way to show Zero who's boss! ^^

zokemon
04-30-2008, 07:41 AM
Good job ;)

Way to show Zero who's boss! ^^

Since when? Mine is made more for optimization and fast calculating of algorithms and such while PFA's is more focused around actually running code (assignment, function calling). I intentionally left assignment and function calling out of mine as I didn't want them in mine.

Neither of ours is better per say as we are doing them entirely different ways.

Anyways, good job PFA :).

cbk1994
05-01-2008, 04:29 AM
Since when? Mine is made more for optimization and fast calculating of algorithms and such while PFA's is more focused around actually running code (assignment, function calling). I intentionally left assignment and function calling out of mine as I didn't want them in mine.

Neither of ours is better per say as we are doing them entirely different ways.

Anyways, good job PFA :).

I know, it was a joke ^^

Yours is awesome as well. Didn't mean to hurt your ego, 'o great one.

zokemon
05-01-2008, 08:04 PM
I know, it was a joke ^^

Yours is awesome as well. Didn't mean to hurt your ego, 'o great one.

You don't have to say that, just don't put mine down :frown:.