JavaCFG - Installation and Usage

  1. After unzipping or gunzipping and untar'ing, a directory called "JavaCFG" will be created, and you should cd into it.
  2. Create the Java bytecode with the command
    javac CFGParse.java
  3. Write a grammar file such as the racecar grammar or sample from some examples provided in the grammars directory.
  4. attempt to parse an input-string with the command
    java CFGParse grammar-file-path input-string
  5. if input-string is generated by the grammar, two trees are created:
  6. if input-string is not generated by the grammar this fact is reported in a window created by the program. No LaTeX file is created in this case.
  7. If you want convert the LaTeX tree into PDF you'll need LaTeX installed. The command
    pdflatex filename.tex
    creates a file called "filename.pdf" which contains a picture of the derivation tree.

Grammar Files

Grammars are stored as text files which should end with the .cfg extension. They are specified as follows:

For example the language
{anbn   |   n > 0} ∪ {bnan   |   n > 0}
has the context free grammar:
S → X | Y
X → aXb | ab
Y → bYa | ba
which is represented in the grammar file by:
S X Y
X aXb ab
Y bYa ba

Directory Structure and Source Code

After untaring or unzipping you will find the following files
CFG.java
A class the defines the context free grammar object used by JavaCFG. Embedded in this class is some additional functionality, added by Yoav Hirsch for de-epsilonizing, and converting grammars into Chomsky Normal Form. Instructions for how to call on the conversion algorithms is embedded in the file.
CFGParse.java
A class created for simplifying the parsing command.
EarleyAgent.java
A class used in the parsing algorithm.
EarleyRule.java
A class used in the parsing algorithm
MalformedGrammarException.java
An exception class used to let the user know that their grammar has not been defined properly, has a typo, or is not the right type for the given operation.
Rule.java
A class which defines the productions of a CFG.
TreeModel2LaTeX.java
A class for converting JTree objects into LaTeX trees.
grammars
A directory containing some examples of grammars NOTE: some of these grammars contain epsilons and that the success of the parsing algorithm on such grammars is not guaranteed.
instructions.html
This file

Last modified: Sun Oct 10 04:06:45 2004