GithubHelp home page GithubHelp logo

preesee / graph-ast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bdqnghi/graph-ast

0.0 0.0 1.0 60 KB

A tool to provide the graph representation of the source code based on the paper: "Learning to Represent Program with Graph"

C 25.37% Python 74.63%

graph-ast's Introduction

Graph-AST: Graph Representation of the Abstract Syntax Tree

A tool to generate the graph representation of the source code based on the paper: Learning to Represent Program with Graph, ICLR 2018.

Note that this is only for the graph generation from the AST. For the Gated Graph Neural Network implementation that process the graph, please refer to GGNN for graph classification

Installation

The backbone of this tool is the Abstract Syntax Tree (AST). The AST will be generated using the f-ast tool: fAST: Flattening Abstract Syntax Trees for Efficiency, ICSE 2019. The tool supports any ANTLR4 grammar of over 170 different types of programming languages.

Some benefits of using the f-ast:

  • f-ast leverages protobuf to store the AST and make the parsing much faster than the other tools.
  • f-ast is built based on srcml and srcSlice. That is, it can incorporate the slicing information of the program, such as the use-def chain (taken from srcSlice) into the AST. The use-def chain is a critical information to generate the graph-ast.

A runnable docker image of the tool can be pulled by using this command:

  $ docker pull yijun/fast:latest

Example usages:

To generate an AST representation of a file.

  $ cd sample_files
  $ docker run -v $(pwd):/e -it yijun/fast -p Test.c Test.pb

The Test.pb file is the AST representation under the protobuf format. For example on how to read and traverse the tree, see this link.

Since the goal of this tool is to generate the graph representation of the source code, the next step is to run:

  $  python3 generate_graph Test.pb Test.txt

The Test.txt is a graph representation with the format: source_id, source_node_type edge_type sink_id, sink_node_type. For example, the edge:

22,3 1 21,4

means that the node with id 22 connects to the node with id 21 via the edge with id 1. Also, the node with id 22 has the type of 3, the node with id 21 has the type of 4.

For the list of node types, see this. For the list of edge types, see this.

graph-ast's People

Contributors

bdqnghi avatar

Forkers

brojackvn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.