SeriesPt4 - A Java Cross-Reference Tool A Java...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
A Java Cross-Reference Tool A Java Cross-Reference Tool 1 sur 13 Parsers, Part IV: A Java Cross-Reference Tool Scott Stanchfield and Terence Parr, MageLang Institute Have you ever wanted to build a tool that examines or processes Java source files? For example, you might be interested in a tool that enforces a coding style or a tool that automatically augments programs with debugging code snippets. Building a real parser for the Java language with a complete symbol table is nontrivial and most programmers have shied away from such a task and relied on partial solutions using PERL instead. This is the last article in the parsing series. We built a Java language cross-referencing tool that accumulates complete symbol table information using a Java parser generated by the ANTLR parser generator. The previous article in this series discussed the generation of tag files needed to build a code browser and made use of an older version of ANTLR that generated parsers implemented in C++. The tag file generator was almost exclusively a Java parser, with no symbol table manager, and hence, our discussion concentrated on the Java grammar. This article discusses some of the key concepts involved in building a cross-reference tool, focusing on the design of a Java symbol table manager and its interaction with a Java parser. This article also includes a small detour that describes the latest version of ANTLR, generating parsers implemented in the Java language. A cross-referencing tool assists navigation of code by reporting interactions of modules, variables and classes within that code. It's also useful for determining portions of your code that are no longer used, thereby enabling you to produce the smallest possible program footprint. If you are unfamiliar with the parsing terms in this article, read Introduction to Parsers, Part III: Does a Yak Have Antlers? by Greg Voss. What is a Cross-Reference Tool? A Java program consists of definitions and references . When you write a program, you define constructs like classes, methods and variables. These definitions include references to other Java language constructs. Classes refer to another class as their superclass; variables refer to a class or primitive as their type; some statements refer to methods to delegate processing. A cross-reference tool describes these relationships by parsing one or more Java source files and determining which constructs are being referred to. These relationships are presented in a report to describe which constructs refer to other constructs and where a given construct is used. An example input and output is provided below . There are two main components in a cross-reference tool: a parser and a symbol table. The cross-reference parser is similar to the parser described in the previous article in this series. The symbol table is a new feature and is discussed in great detail in this article.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2010 for the course CS 5503 taught by Professor Kaylor during the Spring '10 term at University of West Alabama-Livingston.

Page1 / 13

SeriesPt4 - A Java Cross-Reference Tool A Java...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online