[antlr-interest] Parsing PGN (chess algebraic notation) files

Kevin Jackson foamdino at gmail.com
Mon Jan 24 19:21:58 PST 2011


Hi,

I have to convert PGN files using algebraic notation and I'm doing ok so far.

I have one major stumbling block and I was wondering if anyone has
done something similar.

Algebraic notation is a short form of chess move that only contains an
optional piece identifier, followed by destination square followed by
optional markers:
e5 => pawn moves to e5
Bf3 => Bishop moves to f3
Nh2+ => Knight moves to h2 (and check)

Parsing these is ok, but my task is to generate output containing both
start and end positions for a move.  My research seems to indicate
that this isn't easy without maintaining the current state of the
board and applying each move as I parse it to update the board and
therefore be able to determine where the move came from.  Another
option is to maintain an index of piece-destination
(possible_start_position_1, possible_start_position_2...) - and then
for each piece lookup where it could possibly have come from - I'm not
sure this helps though :)

What was a simple text transformation problem has become a game engine!

I'd be interested to hear any thoughts from people who have attempted
PGN parsing in antlr

Thanks,
Kev


More information about the antlr-interest mailing list