Subj : Walking through script syntactic tree To : netscape.public.mozilla.jseng From : BegemoT Date : Thu May 26 2005 10:46 pm Hello, All! I use Rhino embedded engine in my application. In host enviroment I have some set of objects, each of them identified by uniq string ID. User can write some kind of script to evaluate an expression depends on some of this object's properties. Thing that I want to do is to, given a script code, find what objects are using in it. Where are two reasons for what -- one, as users supposed to have only basic programming experience, I want to allow them refer my object by simply use their ID as variable name, e.g then user write script like distance(Object1, Object2), I want to find, that "Object1" and "Object2" is IDs of some objects in host enviroment and create appropriate variables (Object1,Object2) in current score, given them values of appropriate objects, before executing script. Second reason is perfomance issue -- knowing on which objects expression value is depends allow to recalculate it only then required. So, as far as I can understand, I should use Rhino Parser directly, to parse user's script and make some processing of resulting syntactic tree. I see, from Rhino sources, what parsed arbitrary script I got ScriptOrFunctionNode as root. So, my question is: how I can walk through each node in this tree? I feel myself rather confusing with first-next-last notation used in this tree structure.... Another question is how I can find undeclared variables nodes in this tree? Now, I can find only one way to do somthing like this -- searching for nodes with type == Token.NAME, but it is not exactly the thing -- in expression distance(Object1, Object2) I see NAME nodes [distance, Object1, Object2] -- how I can determine, what "distance" is a function name, not variable? Is it possible in JS syntax at all? -- functions in JS is variables, only with special content, as far as I know, but it seems obvious, what with given full sintactic tree it is possible to distinct function call operation on an object from property access/rvalue using, it is not obvious only HOW to do so :) Any ideas? Thanks in advance! Ruslan. .