Skip to content

Visualization

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

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.

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 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

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