|
| 1 | +PDN Grammars |
| 2 | +This section defines some PDN grammars. First a PDN 3.0 grammar is given, with some additional restrictions. The goal of these restrictions is to make PDN easier to parse, and thus to make it easier for programmers to support PDN 3.0. Also some explanations are given. Finally, a much more liberal reading grammar is given that can be used when reading existing PDN files. The grammars that are given in this section can not be parsed using a simple LL(1) parser. See the PDN Implementation section for some examples of LL(1) grammars. |
| 3 | + |
| 4 | +PDN 3.0 Grammar |
| 5 | +// Game independent productions |
| 6 | +PdnFile : Game (GameSeparator Game)* GameSeparator? |
| 7 | +GameSeparator : ASTERISK |
| 8 | +Game : (GameHeader GameBody?) | GameBody |
| 9 | +GameHeader : PdnTag+ |
| 10 | +GameBody : (GameMove | Variation | COMMENT | SETUP | NAG)+ |
| 11 | +PdnTag : LBRACKET IDENTIFIER STRING RBRACKET |
| 12 | +GameMove : MOVENUMBER? Move MOVESTRENGTH? |
| 13 | +Variation : LPAREN GameBody RPAREN |
| 14 | + |
| 15 | +// Game dependent productions |
| 16 | +Move : NormalMove | CaptureMove |
| 17 | +NormalMove : Square MOVESEPARATOR Square |
| 18 | +CaptureMove : Square (CAPTURESEPARATOR Square)+ |
| 19 | +Square : ALPHASQUARE | NUMSQUARE |
| 20 | + |
| 21 | +// Tokens |
| 22 | +MOVENUMBER : "[0-9]+\.(\.\.)?" |
| 23 | +MOVESEPARATOR : "-" |
| 24 | +CAPTURESEPARATOR : "x" |
| 25 | +ALPHASQUARE : "[a-h][1-8]" |
| 26 | +NUMSQUARE : "[1-9][0-9]?" |
| 27 | +MOVESTRENGTH : "([\!\?]+)|(\([\!\?]+\))" |
| 28 | +NAG : "\$[0-9]+" |
| 29 | +LPAREN : "\(" |
| 30 | +RPAREN : "\)" |
| 31 | +LBRACKET : "\[" |
| 32 | +RBRACKET : "\]" |
| 33 | +ASTERISK : "\*" |
| 34 | +SETUP : "\/[^\/]*\/" |
| 35 | +STRING : "\"([^\"]|\\\")*\"" |
| 36 | +COMMENT : "\{[^}]*\}" |
| 37 | +IDENTIFIER : "[A-Z][a-zA-Z0-9_]*" |
| 38 | +Besides the usual white space characters (spaces, tabs and line endings), also line comments starting with a % are allowed. For example |
| 39 | + |
| 40 | +% Board game: International Draughts 10x10 |
| 41 | +[Date "2012.02.01"] |
| 42 | +1. 32-28 19-23 |
| 43 | +PDN 3.0 Restrictions |
| 44 | +When writing PDN, the following restrictions should be applied: |
| 45 | + |
| 46 | +Spaces are not allowed in the notation of a move. For example, 1 - 7 is not allowed. |
| 47 | + |
| 48 | +Spaces are not allowed between a move notation and it’s move strength indicator. For example, 32-28 ! is not allowed. |
| 49 | + |
| 50 | +The symbol * is not allowed as a move strength indicator. Use the $7 numeric annotation glyph instead. See the PDN parsing issues section for an explanation. |
| 51 | + |
| 52 | +Only the symbol * is allowed as a game separator. |
| 53 | + |
| 54 | +Squares of moves may not have leading zeroes. For example 01-07 is not allowed. |
| 55 | + |
| 56 | +Moves must be written in the format (Alpha numeric, Numeric or SAN) as it is specified in the Notation attribute of the GameType tag. See also section GameType tag. |
| 57 | + |
| 58 | +Capture moves must be written using the capture separator corresponding to the GameType, as it is specified in the table in section GameType tag. |
| 59 | + |
| 60 | +Ambiguous moves must be written in long notation, i.e. they must contain the full capture sequence. All other moves should use regular notation, i.e. only a begin and an end square. |
| 61 | + |
| 62 | +Explanation: sometimes the regular notation of a move is ambiguous. For example in the position below the notation 47x36 does not specify exactly which black pieces were captured. |
| 63 | + |
| 64 | +_images/diagram1.png |
| 65 | +To resolve this, 47x38x24x13x36 or 47x38x20x9x36 must be chosen. |
| 66 | + |
| 67 | +Disambiguated capture sequences have to specify a complete sequence of intermediate squares along the path of the capture. If there is a change in direction, an intermediate square is the square where a turn in direction was made. If there was not a change in direction, the intermediate square is the square immediately behind a captured piece. There is no intermediate square behind the last captured piece, but otherwise leaving out an intermediate square that is not necessary for the disambiguation is forbidden. |
| 68 | + |
| 69 | +For example, in the above diagram 47x24x36 is not allowed, even though it uniquely determines the move. Also 47x33x24x13x36 is not allowed, since 33 is not immediately behind a captured piece. |
| 70 | + |
| 71 | +N.B. The first five restrictions are enforced by the grammar. Other restrictions have to be checked after parsing. |
| 72 | + |
| 73 | +Explanation |
| 74 | +The grammar is given in EBNF format. In the productions the symbol ? stands for 0 or 1 repetitions, * stands for 0 or more repetitions, and + stands for 1 or more repetitions. Tokens are given between double quotes and should be interpreted as regular expressions. |
| 75 | + |
| 76 | +Strings can have embedded double quotes ", by using the escape sequence \". For example "An embedded \" quote!". |
| 77 | + |
| 78 | +Comments are placed between braces. For example { Start of the game } 33-28 18-22 39-33? { This is a classical mistake }. |
| 79 | + |
| 80 | +In existing PDN files games are usually terminated with a result. It can be one of the chess results 1-0, 1/2-1/2, 0-1, one of the results of international draughts 2-0, 1-1, 0-2, or a double forfeit 0-0. Finally the * can be used as a terminator. |
| 81 | + |
| 82 | +A game can not be empty. |
| 83 | + |
| 84 | +Both numeric moves 32-28 and alpha-numeric moves a3-b4 are allowed. |
| 85 | + |
| 86 | +In alpha-numeric moves the separator may be omitted, so a3b4 is allowed. |
| 87 | + |
| 88 | +A move number is a number followed by either one dot or three dots, for example 1. 32-28 or 23... 20-25. The three dots denotes that it is a black move. |
| 89 | + |
| 90 | +Moves can be annotated using a move strength indicator right after their notation, for example 10-15! or 29-23(?). |
| 91 | + |
| 92 | +Moves can also be annotated using numeric annotation glyphs (NAGs). For example $1 has the same meaning as the move strength indicator !. |
| 93 | + |
| 94 | +Comments, variations and NAGs may appear anywhere in the game, in any order. This is less restrictive than in [Nemesis], |
| 95 | + |
| 96 | +Variations are placed between parentheses. They can be nested arbitrarily, for example: 32-28 19-23 (18-23 38-32 (37-32? 23-29! { Black wins }) 12-18) 28x19 14x23. |
| 97 | + |
| 98 | +PDN Reading Grammar |
| 99 | +// Game independent productions |
| 100 | +PdnFile : Game (GameSeparator Game)* GameSeparator? |
| 101 | +GameSeparator : ASTERISK | Result |
| 102 | +Game : (GameHeader GameBody?) | GameBody |
| 103 | +GameHeader : PdnTag+ |
| 104 | +GameBody : (GameMove | Variation | COMMENT | SETUP | NAG)+ |
| 105 | +PdnTag : LBRACKET IDENTIFIER STRING RBRACKET |
| 106 | +GameMove : MOVENUMBER? Move MOVESTRENGTH? |
| 107 | +Variation : LPAREN GameBody RPAREN |
| 108 | + |
| 109 | +// Game dependent productions |
| 110 | +Move : NormalMove | CaptureMove | ELLIPSES |
| 111 | +NormalMove : Square MOVESEPARATOR Square |
| 112 | +CaptureMove : Square (CAPTURESEPARATOR Square)+ |
| 113 | +Square : ALPHASQUARE | NUMSQUARE |
| 114 | +Result : Result1 | Result2 | DOUBLEFORFEIT |
| 115 | +Result1 : WIN1 | DRAW1 | LOSS1 |
| 116 | +Result2 : WIN2 | DRAW2 | LOSS2 |
| 117 | + |
| 118 | +// Tokens |
| 119 | +WIN1 : "1-0" |
| 120 | +DRAW1 : "1\/2-1\/2" |
| 121 | +LOSS1 : "0-1" |
| 122 | +WIN2 : "2-0" |
| 123 | +DRAW2 : "1-1" |
| 124 | +LOSS2 : "0-2" |
| 125 | +DOUBLEFORFEIT : "0-0" |
| 126 | +ELLIPSES : "\.\.\." |
| 127 | +MOVENUMBER : "[0-9]+\.(\.\.)?" |
| 128 | +MOVESEPARATOR : "-" |
| 129 | +CAPTURESEPARATOR : "[x:]" |
| 130 | +ALPHASQUARE : "[a-h][1-8]" |
| 131 | +NUMSQUARE : "([1-9][0-9]?)|(0[1-9])" |
| 132 | +MOVESTRENGTH : "([\!\?]+)|(\([\!\?]+\))" |
| 133 | +NAG : "\$[0-9]+" |
| 134 | +LPAREN : "\(" |
| 135 | +RPAREN : "\)" |
| 136 | +LBRACKET : "\[" |
| 137 | +RBRACKET : "\]" |
| 138 | +ASTERISK : "\*" |
| 139 | +SETUP : "\/[^\/]*\/" |
| 140 | +STRING : "\"([^\"]|\\\")*\"" |
| 141 | +COMMENT : "\{[^}]*\}" |
| 142 | +IDENTIFIER : "[A-Z][a-zA-Z0-9_]*" |
| 143 | +When reading PDN, one must take into account that captures can can contain the full capture sequence, also in the case of non-ambiguous moves. This is for backward compatibility. |
0 commit comments