Browse Prior Art Database

Software Framework for Generating AST Node Class Hierarchy, Visitor Pattern Implementation and Language Parser from a Simple Language Specification

IP.com Disclosure Number: IPCOM000109205D
Original Publication Date: 2005-Mar-23
Included in the Prior Art Database: 2005-Mar-23
Document File: 3 page(s) / 47K

Publishing Venue

IBM

Abstract

This article describes a software framework for generating an AST node class hierarchy, visitor pattern implementation and language parser from a simple grammatical language specification. The software framework described was implemented as a set of plugins to the Eclipse IDE (www.eclipse.org).

This text was extracted from a PDF file.
At least one non-text object (such as an image or picture) has been suppressed.
This is the abbreviated version, containing approximately 52% of the total text.

Page 1 of 3

Software Framework for Generating AST Node Class Hierarchy, Visitor Pattern Implementation and Language Parser from a Simple Language Specification

The framework described here was conceived after a study of the Eclipse IDE (www.eclipse.org) and specifically the Java Development Tooling (JDT) subsystem and even more specifically the ASTNode class (in package org.eclipse.jdt.core.dom) and its subclasses and the related ASTVisitor class. It was observed that while these classes appear to be handwritten, they have a very regular structure and could perhaps have been generated by some tool. A second observation was that these classes were written to interact with other classes (the Java parser) that were generated by a parser generator tool.

The motivating idea behind the framework described here was the desire to have a tool that, given a syntactic specification of a programming language, will generate an ASTNode class hierarchy, an ASTVisitor class (similar to those in the JDT) and input to a parser generator (Antlr was chosen for this, see www.antlr.org) with tree-building actions. Additionally, the generated classes should inherit from common AST oriented classes allowing generic UI components (such as a parse tree view) to work for all languages generated by the framework.

The name given to the generation tool (by its creator) is Gymnast, which is semi-acronymal for "Generate You a Mighty Nice AST".

The name given to the set of common AST oriented classes and generic UI components used by the generated language code is LDT, which stands for "Language Development Tooling".

Input files to Gymnast are given the extension .ast. The picture below shows the language description for Jel, a "Java-like Example Language":

The yellow-highlighted keywords tell the code generator what sort of pattern the generated classes should fall into (if the tool were a little smarter, some of this could be inferred by looking at the grammatical expressions in the rules.) So jel.ast is an example i...