Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-24-2008, 04:33 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004 Send a message via Skype™ to Tolnaftate2004
function: eval

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!)
Attached Files
File Type: txt math.parser.txt (15.5 KB, 259 views)
File Type: txt math.parser.unstable.txt (17.9 KB, 199 views)
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 05-02-2008 at 12:58 AM..
Reply With Quote
  #2  
Old 03-24-2008, 04:41 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
That's truly amazing, far beyond what I could do.
__________________
Reply With Quote
  #3  
Old 03-24-2008, 04:58 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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().
__________________
Reply With Quote
  #4  
Old 03-24-2008, 08:12 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004 Send a message via Skype™ to Tolnaftate2004
Quote:
Originally Posted by Inverness View Post
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #5  
Old 03-24-2008, 08:41 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Tolnaftate2004 View Post
I know, this is my preference, though.
Mine too, and you always amaze me with your scripts
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 03-24-2008, 09:44 AM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Nice
__________________
Reply With Quote
  #7  
Old 03-24-2008, 10:37 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004 Send a message via Skype™ to Tolnaftate2004
Question: should eval be able to access temp. variables declared within the scope that eval is called? e.g.,

Graal Script Code:
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.
Graal Script Code:
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 03-24-2008 at 11:13 AM..
Reply With Quote
  #8  
Old 03-24-2008, 11:43 AM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Read line 242.
__________________
Reply With Quote
  #9  
Old 03-24-2008, 11:52 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004 Send a message via Skype™ to Tolnaftate2004
Quote:
Originally Posted by Dan View Post
Read line 242.
... Are you getting an error?
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #10  
Old 03-24-2008, 12:38 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Inverness View Post
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.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #11  
Old 03-24-2008, 04:53 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Looks good PFA. I'm still going to post mine though when I'm not so busy .
__________________
Do it with a DON!

Last edited by zokemon; 03-24-2008 at 05:10 PM..
Reply With Quote
  #12  
Old 03-24-2008, 06:33 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xXziroXx View Post
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.
__________________
Reply With Quote
  #13  
Old 03-24-2008, 09:37 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tolnaftate2004 View Post
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.
__________________
Reply With Quote
  #14  
Old 03-24-2008, 10:52 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004 Send a message via Skype™ to Tolnaftate2004
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 03-24-2008 at 11:16 PM..
Reply With Quote
  #15  
Old 03-24-2008, 11:48 PM
Rapidwolve24 Rapidwolve24 is offline
North*
Join Date: Oct 2007
Location: Massachusetts
Posts: 178
Rapidwolve24 is on a distinguished road
Send a message via AIM to Rapidwolve24 Send a message via MSN to Rapidwolve24
Really nice work.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:33 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.