Git Product home page Git Product logo

ast's Introduction

AST

This Java project contains a library for shrinking abstract syntax trees. For initial construction of ASTs it uses javaparser.

How To Compile Sources

The Project uses Maven build system. If you checked out the project from GitHub you can build the project with maven using:

mvn clean install

Then compile source files:

mvn javacc:javacc

How to use

Open Class Main. A main function of it looks as follows:

public static void main( String[] args ) throws IOException, ClassNotFoundException {
        SaveToFile saver = new SaveToFile(2);
        saver.save();
}

2 here stands for number of shrinks that you can vary. This code does the following:

  • finds all the java files in folder src/main/resources. So, put all your java files you want to process here.
  • constructs abstract syntax trees and shrinks them number of times you specified in SaveToFile constructor.
  • saves all the data in folder src/main/Data using structure of folders in src/main/resources.

It saves three type of files:

  • JavaFileName.txt where JavaFileName.java was in src/main/resources. It is just a dump of shrinked ast tree. I have class MyNode that I use for constructing abstract syntax trees and it is serializable, so it I dump. Such files can be used later for reconstructing ast tree and writing some its visual representation.
  • JavaFileName_YamlPrinter.txt - file with visual representation of shrinked ast of file JavaFileName.java. It is constructed with src/main/java/com.ast.shrink/printer/MyYamlPrinter.
  • JavaFileName.dot - it is intermediate representation of shrinked ast. It is used for building png files. Just use terminal command:
dot -Tpng JavaFileName.dot > ast.png

Though, it is worth doing only with really small code.

All classes are supplemented with abundant documentation. All code is situated in following folders:

  • ast
  • printer
  • utils

in directory src/main/java/com.ast.shrink.

How to use MyYamlPrinter on dumped AST:

Example:

MyYamlPrinter printer = new MyYamlPrinter(Paths.get("./src/main/Data"));
printer.print(Paths.get(relativePathToDumpedASTFile));

Write this code in main method of class Main and it'll write _YamlPrinter representation to console. Dumped AST file is one of those JavaFileName.txt.

ast's People

Contributors

dingearteom avatar

Watchers

 avatar

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.