Using the Toolkit Code and the Sample Code

Building Parsers with Java
By Steven  John  Metsker

Table of Contents


This book comes with a CD that contains all the code.

Contents of the CD

The CD includes all the code of the fundamental parser classes, the logic engine, and all the examples. The CD also contains the javadoc documentation from the code, which explains class by class how the code works.

Applying the Code on the CD

The code on the CD is free. It is copyrighted , so you may not claim that you wrote it. Otherwise, you may use the code as you wish.

Hello World

The following program is a sufficient test to verify that you can use the code from the CD. Load the code from the CD into your development environment. Type in the following program, or load it from on the CD.

 package sjm.examples.preface;  import sjm.parse.*; import sjm.parse.tokens.*; /**  * This is a "Hello world" program. Once you get this  * working on your computer, you can get any example in this  * book to work.  */ public class ShowHello { /**  * Create a little parser and use it to recognize  * "Hello world!".  */ public static void main(String[] args) {     Terminal t   = new Terminal();     Repetition r = new Repetition(t);     Assembly in  = new TokenAssembly("Hello world!");     Assembly out = r.completeMatch(in);     System.out.println(out.getStack()); } } 

Compiling and running this class prints the following:

 [Hello, world, !] 

Once you get this running in your environment, you will be able to use all the fundamental classes and all the examples in this book.

Coding Style

Some features of the coding style in this book may seem unusual. First, this book does not indent method signatures. This practice stems from the fact that the VisualAge development environment exports classes this way, resulting in a pair of curly braces at the end of a class. This convention has the happy effect of allowing a little more space before statements are wrapped within the narrow margins of this book.

Another feature of the coding style in this book that may give you pause is the use of extremely short variable names. Methods in this book nearly always perform a single service and thus are short. Temporary variables are never far from their declarations, and there is usually no need for names longer than one character. For example, it is not difficult in the preceding program to discern that the variable t refers to a Terminal object. In the rare event that two variables of a given type occur in one method, they receive meaningful names, such as in and out in the preceding example.

Comments in the code use javadoc tags such as @param and @exception , but the text usually omits these to save space. Comments for public methods begin with /** , which indicates that the comment is a "doc comment."


Building Parsers with Java
Building Parsers With Javaв„ў
ISBN: 0201719622
EAN: 2147483647
Year: 2000
Pages: 169

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: