PGNParser using JavaCC
The Java Parser Generator / Java Compiler Compiler (JavaCC) is the most popular parser generator for use with Java applications. A parser generator is a tool that reads a grammar specification and converts it to a Java program that can recognize matches to the grammar.
The latest release of JavaCC and the version I am using is Version 3.0. This version was released by Sun Microsystems.
Playing around with this tool is quite amazing and very helpful to get a better understanding about how a parser works. My main intention is to use it for my Java/Swing chess project. Therefore I created a JavaCC grammar file that parses PGN files. PGN is "Portable Game Notation", a standard designed for the representation of chess game data using ASCII text files.
Parsing these files is a little bit tricky, because there are many 'flavours' and different styles regarding chess notation. The standard distinguishes between import (a more relaxed definition) and export (more restrictive rules) files. My parser tries to support both so it's kind of a balancing act.
Any way, if you are interested, feel free to download the latest verion and give it a try.
There is a new version available that also includes some basic Java classes representing the particular tokens like moves, comments, etc. Furthermore, it has support to build everything using Ant. I also made several improvements to the parser itself (see included CHANGELOG for details).
There is also a version donated by Jean-Paul QUANTIN with several changes based on version 0.6.5. This version is also availabe as PGNParser0.7.6.zip.