Skip to main content
gamedev.net
🔒 Locked

Flex/Bison and code snippets

Started by BradDaBug Jun 27, 2007 at 10:15 AM 0 replies 650+ views
Original Post
BradDaBug
BradDaBug
I've written a compiler using Flex and Bison that converts Sheep script (a scripting language built for Gabriel Knight 3) into bytecode, and then the bytecode runs on a VM I've made. Whenever the game needs to runs a script it first compiles the script to bytecode, then runs the bytecode on the VM. The problem is I've made the compiler expect script that looks something like this:

symbols
{
   int blah$ = 4;
}
code
{
   MyFunction$()
   {
      DoSomething(blah$);
   }
}
Now I have a need to be able to run "snippets" of script, that may only be a line or two of script, but aren't encapsulated inside a code{} section. The snippets might be just a list of statements. The simplest way to get around this is to dynamically generate a script that puts "code { func$() { ... } }" around the snippet. But I also need to be able to evaluate snippets that are a conditional that needs to be evaluated, and local functions inside sheep scripts can't return values. So now what? Modify the compiler so that it can run in "snippet mode?" Any advice?
I like the DARK layout!
ToohrVyk
ToohrVyk
The simplest way would be to add an exit(x) primitive, which would stop script execution and return the value of x to the virtual macine. Then, you can implement one-liners in terms of a function with one or more exit statements.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.