Skip to content

jeff5/asdl-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Compiler and code generator for a dialect of Abstract Syntax Description Language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published