Subj : The root of the syntax tree To : netscape.public.mozilla.jseng From : joao Date : Tue Jul 06 2004 11:56 pm Hi all, I'm trying to get at the syntax tree, after a JS script has been compiled. Hopefully I'd like to have a tool to display and manipulate this tree. I've been poking around the SpiderMonkey source code (I downloaded the latest js-1.5-rc6a), I found the description of JSParseNode's in jsparse.h, so I've written a little recursive function that outputs a node, showing token type, jsop, arity, and the children if any. Then to have this code called, I looked into js_CompileTokenStream in jsparse.c, and added my call after the line that says pn = Statements(cx, ts, &cg->treeContext); It turns out that this node only has a TOK_EOF... I was hoping to find a list of top-level statements. So I went one step further, inside the Statements call, and inserted my call inside the 'while' loop, after the line pn2 = Statement(cx, ts, tc); and sure enough, I can output each of the toplevel statements. But they are not connected, I do not have a root for this syntax tree. Does this root exist ? are all the top-level statements collected somewhere, before the EOF is reached ? or does JS emit the bytecode for each statement and then forget about it ? Related question : for a string literal, I get a TOK_STRING token with a JSOP_STRING operator, but I can't see how to get at the value of the string ; it has arity PN_NULLARY so there's nothing more in the JSParseNode. How can I reach this value ? Thanks, Joao -- joao at teaser dot fr .