On 19/10/2010, at 12:57 AM, Vyacheslav Egorov wrote:
I do not understand why you want to plug into AST directly.
Because it's a proof of concept, and it's required to prove the concept. The idea is based on the fact that PEG grammars are composable. That is, you can take a PEG grammar, and add one new rule, and the new grammar works immediately without any analysis steps. The new rule(s) can override existing rules, and even call the rules they overrode (like inheritance), and because there's no separate lexer, the composite grammar "just works". There's no generation of the many extra layers of function calls that you normally get when interpreting one language in another, no efficiency gap between the two. Supposing that the JS grammar was like this, and the semantic part of each rule yielded the appropriate AST node. Now, when I add a new rule (including overriding an existing one, and calling other existing ones), the semantic part is some JS that will parse using the original compiler. If the new rule has called an existing rule, the AST yielded from that rule is directly used within that semantic JS. In this way, an AST is built for the new rule but without any new types of AST nodes, and without any explicit AST building. It's not a two-step compilation process, but source-level direct-to-AST with no performance penalty at run-time. This demonstrates that a PEG-based parser can have a completely fluid grammar, and so the language can be used to construct any DSL or in fact any language, while being fully integrating into the core JS language. It becomes a meta-language workbench with production performance.
It will require allow digging into V8 internals. Exposing Zone-mananged AST objects to GC-mananged JS-land is possible but extremely painful. I would not recommend doing that.
I expected that. It may be that some intermediary tree is necessary, but I don't think just generating complete JS will work. So, as a compromise, if I create a JS lib of pseudo-AST nodes, of exactly the same structure as V8's ASTs but made in GC land, then I'd only need to add one method built in native code to allow this pseudo-AST to be directly translated to a V8 AST, and from there to a function. That would sort-of demonstrate the same thing, but perhaps less painfully. Clifford Heath. -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
