-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AST visualisation #25
Comments
How about if this is done external to the compiler coursework repo and instead a contribution is made to something like https://github.com/fkling/astexplorer (see example here: https://astexplorer.net/)? |
That's a good point - after creating this Issue I actually thought about creating a standalone repo to avoid polutting this one. Your point of contributing to AST explorer is interesting as I've been always suprised that they don't offer C/C++. However, that also might be a problem, as there certainly is a very good reason why they don't offer support for one of the most popular languages. Aside from contributing C to AST explorer being technically challenging, it also would be quite specific as we only care about the limited subset of C90, which I guess wouldn't be very popular outside students working on this coursework. Hence, I'd say it might be more feasible (and "thematically" correct) to develop the visualiser in this repo/standalone repo under LangProc, depending on the code size - i.e., finding the correct balance of main repo poluttion vs ease of use if it was provided as one package. |
Even if it wasn't accepted upstream, we could still consider our own fork for C90 specifically Maybe have a look at these to see if they could be useful: https://github.com/zaach/jison / https://github.com/ericprud/ts-jison (looks like they can be used to generate a parser in javascript / typescript, then it should be possible to walk the AST and output whatever structure astexplorer requires, as documented here: https://github.com/fkling/astexplorer?tab=readme-ov-file#how-to-add-a-new-parser) |
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:
parser_visualizer.y
which has the same grammar asparser_full.y
and each rule builds a generic tree composed ofTreeNode
(declared inast_node.hpp
, it would have no other information, but name and children).parser_visualizer.y
and then walks the tree and outputs a very simple.dot
file.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:
ParseAST
incompiler.cpp
): no easy way to walk since we removed the genericbranches_
, hence each node would require overriding a base virtual function likeWalk
in order to handle all named children.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.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)..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).The text was updated successfully, but these errors were encountered: