Original Post
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?