views:

93

answers:

2

Hi

I have an app in C++ which actually processes a binary file. The binary file is a collection of events say A/B/C, and on detecting event A in the file, the app handles the event in "handler A".

Now i need to write another script in a custom language, which gets executed orthogonally to the binary file processing. The script can have something like,

define proc onA
{
 c= QueryVariable(cat)
print ( c )
}

So when the app handles the event "A" from the binary file, the app has to parse this script file, check for OnA and convert the statements in OnA proc to routines supported by the app. For eg, QueryVariable should copy the value of variable "cat" defined in the app to the variable "C". The app should also check for syntax/semantics of the language in script. Where can i get the best info for deciding on the design? My knowledge on parse trees/grammar has really weakened.

Thanks

+1  A: 

There must be some interpreter or compiler for the scripting language. Check if it supports embedding in C or C++. Most script languages do.

Next choice, or perhaps first, would be to just run the script externally, using the existing compiler/interpreter.

I can't think of any reason why one of the first two options won't do, but if not, consider building an interpreter using ANTLR or for a small language Boost Spirit. Disclaimer: I haven't used the first, and I've only tried out Boost Spirit for a small toy example.

Cheers & hth.,

PS: If you can choose the script language, consider JavaScript and just use Google's reportedly excellent embedding API.

Alf P. Steinbach
From the sound of it, the first two options won't do because he's inventing his own scripting language. I certainly agree with your post script.
JoshD
That's right. It's my own language