-
Notifications
You must be signed in to change notification settings - Fork 35
ViewSyntaxTree
Olivier Duhart edited this page May 17, 2019
·
2 revisions
CSLY allow to get and visualize the concrete syntax tree after a parse.
The ParseResult<IN,OUT>
class expose the root of the syntax tree as a ISyntaxNode<IN>
.
ISyntaxNode<IN>
can be compiled to a graphviz dot file using GraphVizEBNFSyntaxTreeVisitor<IN>
(courtesy to DotNetGraph for .dot file generation)
var result = parser.Result.Parse("2 + 2 * 3");
var tree = result.SyntaxTree;
var graphviz = new GraphVizEBNFSyntaxTreeVisitor<ExpressionToken>();
var root = graphviz.VisitTree(tree);
string graph = graphviz.Graph.Compile();
File.Delete("c:\\temp\\tree.dot");
File.AppendAllText("c:\\temp\\tree.dot", graph);
the graph for this example is :