Giter Site home page Giter Site logo

gfour / antlr2datalog Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 2.0 376 KB

Datalog-based source code analysis framework.

License: MIT License

Java 92.14% COBOL 1.09% Shell 0.90% Go 5.55% Prolog 0.32%
antlr-parsers source-code-analysis static-analysis rust kotlin

antlr2datalog's Introduction

Build Status

antlr2datalog

This is a framework for statically analyzing source code using Datalog queries.

For the set of supported source languages, see the list of parsers in the grammars-v4 repository. The following languages are included out of the box: C, C++, COBOL85, Go, JavaScript, Kotlin, Lua, PHP, Prolog, Python3, Rust, and Solidity. Support for more languages can be easily added, read on below for how to enable support for other languages.

This framework works by transforming ANTLR parsers to Datalog front-ends. An ANTLR parser API is translated into a Datalog schema and the parser is then invoked on the source code to populate a "facts" directory according to the schema. Finally, the analysis logic runs on the facts and computes the analysis results. For more information, see ARCHITECTURE.md.

Installation

  • Install the parsers used:
./install-parsers.sh
  • Install Souffle.

  • Build and install the distribution:

./gradlew installDist

Use

Python3 example:

build/install/antlr2datalog/bin/antlr2datalog -l python3 -i grammars-v4/python/python3/examples/coroutines.py

Kotlin example:

build/install/antlr2datalog/bin/antlr2datalog -l kotlin -i grammars-v4/kotlin/kotlin-formal/examples/Test.kt

Adding a language/parser

  1. Put your ANTLR parser in the local Maven repository. For example, to pick from the "grammars-v4" parsers, install them as follows:
git clone https://github.com/antlr/grammars-v4.git
cd grammars-v4
mvn install
  1. Edit class ParserConfiguration to add a case for the parser.

  2. Add logic/LANGUAGE-logic.dl with the Datalog rules for the new language.

License

For the license of this project, see LICENSE. Note that ANTLR parsers may be covered by different licenses.

antlr2datalog's People

Contributors

gfour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.