script examples.
can anybody be so kind to reveal some simple script code, written preferably in c++ or perl?
scripts have always interested me. im just wondering how it is processed between reading/parsing it and actually executing it.
in other words, a detailed explanation would suffice.
edward
c++ isn't a scripting language
There are many perl examples on the web. If you don't know perl you wouldn't understand something posted here. Have a look here.
[edited by - petewood on February 17, 2003 3:05:53 AM]
There are many perl examples on the web. If you don't know perl you wouldn't understand something posted here. Have a look here.
quote: a detailed explanation would suffice!
[edited by - petewood on February 17, 2003 3:05:53 AM]
I wrote a pure-C wrapper to help me with functions and variables for scripting a while back, but I haven''t gotten around to writing any parsers... if you want a look at the (open) source for what I''ve got, send me an email, to tiogshi@hotmail.com
Essentially, though, you can do almost anything.
"Scripting" is generally considered to be read at run-time, sometimes parsed from human-readable text, and executed. Some scripting systems use an editor to write the scripts, and half-compile to a bytecode which is read and executed by a program. Compiling to a CPU-native instruction set leads us into the realm of run-time libraries, commonly called DLLs under all versions of the Windows OSes.
Shell Scripting, called "batch" scripting in DOS/Win, is done by simply having the shell interpret each line of text exactly as it would input from the normal command prompt. It passes it on to the same parser/lexer/executer as it would any input from the user. So, the problem of re-writing all the parsing is fixed there.
For a common non-shell use, we use scripting to make easily-configurable or changable actions or media, like changing the behaviour of an app''s skin or a button in a game.
Now, to your specific question...
Once you''ve read in, for example, a line of text, you should check it for basic syntax. Bracket and quote counting? Proper line terminator? Next, check any symbols/tokens/atoms in there. Is this function defined? These variables? Does some symbol/token/atom contain an illegal character? Lastly, confirm highest-level syntax. A function name is followed by a parameter list, a variable name is not, math symbols are not used incorrectly (ie "a + b + * d").
Now that you know the statement/line is valid, now you can parse it. Read function names and their parameters, and execute them. Look at math, sort out order-of-operations, and perform the arithmetic.
And now, you''re done with this line. Either move on to the next, or return to tell your managing class/function that you''re finished with that one.
I hope this helps...
Essentially, though, you can do almost anything.
"Scripting" is generally considered to be read at run-time, sometimes parsed from human-readable text, and executed. Some scripting systems use an editor to write the scripts, and half-compile to a bytecode which is read and executed by a program. Compiling to a CPU-native instruction set leads us into the realm of run-time libraries, commonly called DLLs under all versions of the Windows OSes.
Shell Scripting, called "batch" scripting in DOS/Win, is done by simply having the shell interpret each line of text exactly as it would input from the normal command prompt. It passes it on to the same parser/lexer/executer as it would any input from the user. So, the problem of re-writing all the parsing is fixed there.
For a common non-shell use, we use scripting to make easily-configurable or changable actions or media, like changing the behaviour of an app''s skin or a button in a game.
Now, to your specific question...
Once you''ve read in, for example, a line of text, you should check it for basic syntax. Bracket and quote counting? Proper line terminator? Next, check any symbols/tokens/atoms in there. Is this function defined? These variables? Does some symbol/token/atom contain an illegal character? Lastly, confirm highest-level syntax. A function name is followed by a parameter list, a variable name is not, math symbols are not used incorrectly (ie "a + b + * d").
Now that you know the statement/line is valid, now you can parse it. Read function names and their parameters, and execute them. Look at math, sort out order-of-operations, and perform the arithmetic.
And now, you''re done with this line. Either move on to the next, or return to tell your managing class/function that you''re finished with that one.
I hope this helps...
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
The current series of articles on Gamedev.net about creating a scripting engine might be good reading? I really liked it.
Part 5, the latest installment,
http://www.gamedev.net/reference/programming/features/cppscript5/
Part 1, where it all began,
http://www.gamedev.net/reference/programming/features/cppscript1/
hth
(My projects and ramblings...)
Part 5, the latest installment,
http://www.gamedev.net/reference/programming/features/cppscript5/
Part 1, where it all began,
http://www.gamedev.net/reference/programming/features/cppscript1/
hth
(My projects and ramblings...)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement