CFGs with Closures

36 views
Skip to first unread message

kyle.t...@gmail.com

unread,
May 7, 2012, 5:37:53 PM5/7/12
to closure-comp...@googlegroups.com
Is it possible to generate a CFG for code within a closure using only command line options?  For example, with the following snippet:
var f = function(){ ... }

...I get a CFG for the assignment to f, but not for whatever the code in { ... } is.  I understand that these two CFGs would be unconnected, but that's fine for my purposes.  It doesn't seem too complicated to me to make this modification, but I wanted to make sure I'm not missing something before I start hacking away.

Thanks,
-Kyle

Mike Samuel

unread,
May 8, 2012, 4:03:03 PM5/8/12
to closure-comp...@googlegroups.com
2012/5/7 <kyle.t...@gmail.com>:
If by CFG, you mean context-free grammar, the grammatical production
for { ... } in your example is the FunctionBody production as defined
at http://es5.github.com/#x13
I believe Rhino just uses
http://www.jarvana.com/jarvana/view/org/mozilla/rhino/1.7R3/rhino-1.7R3-javadoc.jar!/org/mozilla/javascript/ast/Block.html
as the node type since it allows FunctionDeclarations in any block
which is not strictly allowed in ES5.
There are additional syntactic constraints around break/continue
labels and whether or not an enclosing function/program is in strict
mode that are not expressed in that grammar.

Alan Leung

unread,
May 10, 2012, 1:20:26 PM5/10/12
to closure-comp...@googlegroups.com
If you are talking about the Control Flow Graph. You can run control flow analysis on any Node object to get one.

-Alan
Reply all
Reply to author
Forward
0 new messages