At the office, we ve applied simple Domain Specific Languages (DSLs) to several problem domains we encountered.
Basically, we parse (lex/yacc) the custom script into an expression tree. Every node in the expression tree has an .evaluate() method that gets called recursively, until the program is done. Nice, and simple as pie. Which is a good thing, because I know next to nothing about parsing techniques, compiler construction and whatnot (good thing my coworkers know a thing or two).
Now here is the challenge: the implementation we are currently working on needs the ability to
- stop at any position in the tree
- persist all state
- and restore state/positon at any given time in the future.
Persiting the actual state should not be too hard, but the position in the tree (or the "callstack") befuddles me. How would one go about implementing such a system? Storing the position in the tree using some sort of ID s for every node? Or is evaluating the tree itself the wrong approach, and should we somehow transform it into something linear?
I m guessing this is a rather common problem, but I don t know what to look for. Any help on the correct terminology, nudges in the right direction, keywords to search on, design patterns to look at etc... are most welcome!
(Doing this in Win32/Dephi, but hopefully we can keep this language agnostic)