PDN Implementation¶
This section contains concrete examples of PDN grammars.
DParser¶
[DParser] is a C parser generator.
pdn_reading_dparser.gA fairly liberal reading grammar.pdn_writing_dparser.gA PDN 3.0 writing grammar.fen_dparser.gA grammar for FEN strings.timecontrol_dparser.gA grammar for time controls.
Grammatica¶
[Grammatica] is a java parser generator.
pdn_reading_grammatica.grammarA fairly liberal reading grammar.pdn_writing_grammatica.grammarA PDN 3.0 writing grammar.fen_grammatica.grammarA grammar for FEN strings.timecontrol_grammatica.grammarA grammar for time controls.
The Grammatica grammars are LL(1) grammars. They define a move as a token to make this possible.
The Grammatica grammars contain a workaround for move strengths, since the regular expressions in Grammatica do not behave correctly.
Toy Parser Generator¶
[TPG] is a python parser generator.
pdn_reading_tpg.gA fairly liberal reading grammar.pdn_writing_tpg.gA PDN 3.0 writing grammar.
ANTLR4¶
[ANTLR4] is a parser generator supporting many target languages, including Python.
pdn_reading_antlr.g4A fairly liberal reading grammar.pdn_writing_antlr.g4A PDN 3.0 writing grammar.
The ANTLR4 grammars use a semantic predicate on the
DRAW2token to prevent the result1-1from being mis-tokenised when it appears as part of a numeric move such as1-10.
JavaScript¶
[Peggy] is a parser generator for JavaScript, the successor of PEG.js.
pdn_reading_javascript.pegjsA fairly liberal reading grammar.pdn_writing_javascript.pegjsA PDN 3.0 writing grammar.
The reading grammar is tested using
python/pdn_reading_javascript.js, a hand-written recursive-descent parser that implements the same grammar directly in plain JavaScript. It has no runtime dependency beyond Node.js itself, so — unlike the other three parser generators — no install step is needed to run its tests.Peggy is scannerless: there is no separate tokenizing pass that commits to a token via maximal munch before the parser rules run. This flips the
DRAW2subtlety around: instead of a lexer eating the leading digits of a move such as1-10, an unguarded move rule would happily read the literal text1-1as a move from square 1 to square 1, which is otherwise unreachable syntax. The grammar excludes that exact literal from the move rule so1-1is always read as theDRAW2result.
Test files¶
The games/ directory contains a collection of PDN games used for testing
the grammars, organised into two subdirectories:
games/succeed/— files that every parser must accept without errors.games/fail/— files that every parser must reject.
DParser, a GLR parser generator written in C https://github.com/jplevyak/dparser
Grammatica, an LL parser generator written in Java https://github.com/cederberg/grammatica
Toy Parser Generator, a parser written in Python https://codeberg.org/cdsoft/tpg
ANTLR4, a parser generator supporting multiple target languages https://www.antlr.org/
Peggy, a parser generator for JavaScript https://peggyjs.org/