2
$\begingroup$

Does it make sense to represent an AST as a graph? How can one achieve a mapping between ASTs and graphs that preserves both semantic and syntactic properties of source code?

The goal and application of such a transformation would be to use graph neural networks and other deep "graph" learning techniques to extracts features, clustering source code, find code similarities and suggest code completion tasks.

Any suggestion of current algorithms and research in this area?

$\endgroup$
2
$\begingroup$

Every tree is itself a graph, so of course an AST is a graph -- no mapping is needed, it is already a graph. I don't see any way that this is useful in practice, though.

Rather than trying to convert to a graph and then use graph neural networks, I suggest using a more direct approach: e.g., using a neural network on the AST or on the code itself. Since you haven't told us what you want to do with the neural network, it's impossible to suggest something more concrete, but I encourage you to do a literature search; there are many recent papers on using neural networks on code.


Alternatively, if you insist on having a graph somewhere, perhaps you will be interested in learning about control-flow graphs, which are one use of graphs in program analysis where the graph structure is useful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.