Code Monkey home page Code Monkey logo

asdl-tools's Introduction

asdl-tools

This project is a compiler and code generator for a dialect of Abstract Syntax Description Language (ASDL). The compiler reads ASDL and writes Java class definitions that support processing of data using the Visitor pattern.

Motivation

The motivation for the work is to explore (in Java) the abstract syntax tree (AST) of Python. An AST is used as an intermediate representation of the input program inside a compiler. Python is unusual in that the mechanism is made available to Python programs through the ast module in the standard library. Any string of Python source code can be converted to its AST. The set of data types used in the Python AST is specified using ASDL.

Eli Bendersky has blogged about Using ASDL to describe ASTs in compilers, in relation to Python implementation, and the Python developer guide has a section on the compiler.

This ASDL is compiled by a Python program asdl-c.py, during the building of CPython, and used to generate the C data structures that become the implementation of the astmodules. In Jython (the Java implementation of Python), a modified version of the CPython asdl-c.pyis used to generate Java. The aim here is to use Java and modern compiler and code generation tools (ANTLR and StringTemplate) to accomplish something similar.

About ASDL

ASDL is described in "The Zephyr Abstract Syntax Description Language" TR-554-97 Wang, et al.. There are tools in ML at SourceForge ASDL, provided by Dan Wang, but at the time of this writing, the project has seen no changes since August 2002.

Dialect of ASDL

In applying ASDL to describing Python, the Python project made some additions to ASDL, and also omitted some features. Since the primary aim is to generate the Python AST, this project follows suit. These differences are:

  • Code generation is not controlled through the ASDL source files (view keyword). We'll be using StringTemplate.
  • The attributes keyword is allowed for "product" types, not just for "sum" types.
  • Importing of one module by another is not supported.

Because of these differences we don't claim that the supported dialect is "Zephyr ASDL".

asdl-tools's People

Contributors

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