public static void SetGrammarPtr(Grammar g, GrammarAST tree)
{
if (tree == null)
return;
// ensure each node has pointer to surrounding grammar
Antlr.Runtime.Misc.Func<object, object> preAction =
t =>
{
((GrammarAST)t).g = g;
return t;
};
Antlr.Runtime.Misc.Func<object, object> postAction = t => t;
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
v.Visit(tree, new TreeVisitorAction(preAction, postAction));
}