PDN Implementation

This section contains concrete examples of PDN grammars.

DParser

[DParser] is a C parser generator.

Grammatica

[Grammatica] is a java parser generator.

  • 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.

ANTLR4

[ANTLR4] is a parser generator supporting many target languages, including Python.

  • The ANTLR4 grammars use a semantic predicate on the DRAW2 token to prevent the result 1-1 from being mis-tokenised when it appears as part of a numeric move such as 1-10.

JavaScript

[Peggy] is a parser generator for JavaScript, the successor of PEG.js.

  • 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 DRAW2 subtlety around: instead of a lexer eating the leading digits of a move such as 1-10, an unguarded move rule would happily read the literal text 1-1 as a move from square 1 to square 1, which is otherwise unreachable syntax. The grammar excludes that exact literal from the move rule so 1-1 is always read as the DRAW2 result.

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]

DParser, a GLR parser generator written in C https://github.com/jplevyak/dparser

[Grammatica]

Grammatica, an LL parser generator written in Java https://github.com/cederberg/grammatica

[TPG]

Toy Parser Generator, a parser written in Python https://codeberg.org/cdsoft/tpg

[ANTLR4]

ANTLR4, a parser generator supporting multiple target languages https://www.antlr.org/

[Peggy]

Peggy, a parser generator for JavaScript https://peggyjs.org/