-
Notifications
You must be signed in to change notification settings - Fork 2
Visualization
This section outlines what visualization options are available in AFP Library. More specifically, we discuss how to visualize parse trees and grammar productions using the ParserPrinter class.
The ParserPrinter class provides the user an interface to visualize parse trees for some input and grammar productions.
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
To print parse trees or grammar productions to stdout, pass an instance of a ParseTree or AFParser 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
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.