Skip to content

Visualization

Ronald Franco edited this page Dec 21, 2018 · 3 revisions

Visualization

This section outlines what visualization options are available in [Project Title]. More specifically, we discuss how to visualize parse trees and grammar productions using the ParserPrinter class.

Background

ParserPrinter

The ParserPrinter class provides the user an interface to visualize parse trees for some input and grammar productions.

ParseTree

The ParseTree class provides the basis to store information of a parse tree for some input. A parse tree is generated and stored in a ParseTree object, passed in by reference into the parse function, when parsing some input. This is seen in the following code snippet:

ParseTree pt;
S.parse(&input,&pt); # Generated parse tree is stored in pt

Visualize using STDOUT

To print parse trees or grammar productions to STDOUT, pass a reference to the ParseTree or Parser (stores grammar productions) object into the print member function of the ParserPrinter class. This is seen below:

ParserPrinter p;
p.print(&pt); // pt is a ParseTree
p.print(&S);  // S is a nonterminal

Visualize using Graphviz Dot

Parse trees can also be visualized as a graphviz dot specification file that is generated using the graphviz member function of the ParserPrinter class. This is seen below:

ParserPrinter p;
p.graphviz(&pt); // returns a std::string of Graphviz Dot specification file

Currently visualizing grammar productions using Graphviz Dot is not available.

Clone this wiki locally