7

The Portable Game Notation (PGN) specification appears to contradict itself regarding the valid characters that may appear in a symbol token.

From [1], section 7, quote:

A symbol token starts with a letter or digit character and is immediately followed by a sequence of zero or more symbol continuation characters. These continuation characters are letter characters ("A-Za-z"), digit characters ("0-9"), the underscore ("_"), the plus sign ("+"), the octothorpe sign ("#"), the equal sign ("="), the colon (":"), and the hyphen ("-") ...

Or, to put it more concisely, a symbol token conforms to the regular expression /^[A-Za-z0-9][A-Za-z0-9_+#=:-]*/.

However, this definition explicitly precludes the game draw termination marker 1/2-1/2. Quoting again from [1], section 8.2.6:

Each movetext section has exactly one game termination marker; the marker always occurs as the last element in the movetext. The game termination marker is a symbol that is one of the following four values: "1-0" (White wins), "0-1" (Black wins), "1/2-1/2" (drawn game), and "*" (game in progress, result unknown, or game abandoned).

The string "1/2-1/2" very obviously does not meet the definition of a symbol token, so either:

a) the solidus character ('/', 0x2f) should have been included in the definition of symbol continuation characters, but the author failed to do so, or;

b) game termination markers should not be considered symbol tokens, but rather a distinct type of token which is separate from symbol tokens, and the author failed to indicate this, or;

c) I have completely misunderstood the wording of the specification, and am an idiot.

Somebody has screwed up here, and either it's me, or it's Steven J. Edwards. Hopefully it's me. Personally I think (a) is the most likely of the three but perhaps I've missed something.

[1] http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm

2 Answers 2

5

You are right, the text as written there isn't exactly correct.

It also says that the marker is a symbol and lists * as one of the options, even though * is a token on its own and also cannot occur in a symbol.

That said, the meaning is clear enough, 1/2-1/2 is a valid termination marker. How you solve this in your code is up to you. As it's hard to add 1/2-1/2 as a token on its own (would need lookahead to disambiguate it from symbol 1 et cetera), it's probably easiest to add '/' to the possible symbol characters, yes.

1
  • Thanks for raising the point about *. I had gone ahead and coded * up as a token in its own right, but I think that you are correct to say that this is another error in the description of game termination markers.
    – direvus
    Commented Jan 23, 2020 at 14:09
4

I agree the spec is ambiguous. This antlr grammar uses your option b

game termination markers should not be considered symbol tokens, but rather a distinct type of token which is separate from symbol tokens, and the author failed to indicate this

In the grammar I find

SYMBOL
: [a-zA-Z0-9] [a-zA-Z0-9_+#=:-]*
;

separate from termination

game_termination
 : WHITE_WINS
 | BLACK_WINS
 | DRAWN_GAME
 | ASTERISK
 ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.