Skip to content

AST visualisation #25

Description

@Fiwo735

I've started working on an AST visualisation in the form of a tree graph. Before I commit to the development, I wanted to get your feedback about the approach below, especially if you have some experience with similar tasks:

  1. Create parser_visualizer.y which has the same grammar as parser_full.y and each rule builds a generic tree composed of TreeNode (declared in ast_node.hpp, it would have no other information, but name and children).
  2. Write a C++ driver that parses input program using parser_visualizer.y and then walks the tree and outputs a very simple .dot file.
  3. Call Graphviz CLI (or similar) to create a graph, using in-built arguments to make it look nice.

I've also considered and found issues with other approaches/aspects:

  • Walk the already existing AST (parsed with ParseAST in compiler.cpp): no easy way to walk since we removed the generic branches_, hence each node would require overriding a base virtual function like Walk in order to handle all named children.
  • Put the C++ visualiser logic in compiler.cpp: the logic might be non-trivial, adding to the existing complexity of understanding that file and making it look scarier + separation is usually nice.
  • Use C++ Graphviz module to manipulate the graphs directly in C++: looks less portable if we ever wanted to change the graphing + more cumbersome to implement it (Graphviz CLI seems easier to use).
  • Use GCC/Clang to generate .dot files: their AST is different to ours + it'd be hard to match the C version + that option is not very well documented/developped (to my surprise, but maybe that's due to insufficient googling).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions