Individual Practical (07-08): JavaCC Parser Generator

Introduction

Parser generators are highly useful tools for automatically generating parsers from annotated grammar specifications. A classic example is yacc and the associated lexer lex from the C world. JavaCC is one of the most popular parser generators used for Java.

Accessing JavaCC

JavaCC V4.0 is already installed on DICE machines. If you need to install it on your own machine, visit the JavaCC home page, click on Documents and Files on the Project tools menu on the left hand side. Download release 4.0, either javacc-4.0.tar.gz or javacc-4.0.zip, unpack, and visit the doc/index.html file for further installation instructions and documentation.

Documentation

The root page for JavaCC online documentation is here. The FAQ and Documentation links from this page are probably the most useful to you.

Start with having a read through the draft tutorial by Theo Norvell, also the maintainer of the JavaCC FAQ linked to from the documentation page.

You might also find it useful to look through and try running the examples from the examples/SimpleExamples/ directory of the release. See the README file in this directory for instructions.

There is no need to read about the JJTree class for building syntax trees.

Example Relevant to Part 2

I have put together an example parser generator for simple arithmetic expressions. The generated parser parses expression strings into syntax trees built using a provided tree class. You should easily be able to adapt this example to create a parser for the Part 2 Boolean query expressions.

Download the tar and gzipped file javacc-arith.tgz to your pt2 directory and unpack with the command

tar xzvf javacc-arith.tgz
The file unpacks to 3 files in the src/example/arith/ sub-directory:
Paul Jackson, Paul.Jackson (@) ed.ac.uk

Last modified: Sat Nov 17 23:00:27 GMT 2007


Home : Teaching : Courses : Ip 

Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh