bfs/dfs traversal over ast in pyslang #1624
Unanswered
Snow-Crash
asked this question in
Q&A
Replies: 1 comment
|
Are you talking about traversing the CST or the AST? SyntaxNodes are iterable so you can traverse them however you want. They also have parent pointers. AST elements are more bespoke, but you can still do what you want by returning VisitAction::Skip from the visitor to avoid the default behavior and then provide manual traversal behavior per node. Symbols have parent pointers but other types of AST nodes (such as expressions and statements) do not, so you'd have to build that yourself by traversing the graph and storing the parents as you go. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
Is it possible to explicitly perform bfs/dfs traversal using pyslang? visitor seems automatically travels in dfs, however i'd like to do it manually. I cannot find a unified api to access chindren of a node, some nodes allow me to do for each iteration, while for other nodes, i have to access specific member.
Or can I do the other way by traveling bottom up if for every node i can get their parent? however it seems in ast, there is no such api to access parent.
The purpose of dfs/bfs, or bottom up traversal is that i can build a graph in some other lib such as networkx for the ast, so i can easily inspect it and use some graph algorithm to do some analysis.
Thanks for this super useful library, this is really the best I've tried so far for verilog parsing.
All reactions