1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
\documentclass[a4paper]{article}
\usepackage{skak}
\def\package#1{``\textsf{#1}''}
\def\command#1{``\texttt{\symbol{92}#1}''}
\def\commandwarg#1#2{\texttt{\symbol{92}#1}\{\textit{#2}\}}
\def\base#1{$_{\scriptscriptstyle #1}$}
\def\abbrev#1{\textsf{#1}}
\def\bnf#1{\textit{#1}}
\def\bnfterm#1{\textbf{#1}}
\def\bnfprod{$\rightarrow$}
\def\bnfempty{$\epsilon$}
\def\bnfor{$|$}
\def\bnfjoin{$\bowtie$}
\setlength{\parindent}{0pt}
\title{The Syntax of Chess Moves in the \LaTeX{} Package \package{skak} (Draft)}
\author{Dirk B\"achle}
\begin{document}
\maketitle
\begin{abstract}
This short document contains some thoughts and ideas about the ``to be supported''
syntax of chess moves, including SAN (Short Algebraic Notation) as well as LAN
(Long Algebraic Notation).
The main purpose of this draft is to specify a concrete set of allowed chess moves.
In the next step, extensive test routines for this syntax should be generated
that can be used to verify the final implementation\ldots
\end{abstract}
\section*{Stage 1: Parsing \command{mainline}/\command{variation}}
The commands \command{mainline} and \command{variation} should accept
a nonemtpy list of space separated ``move tokens'' (\abbrev{MT}):
\medskip
\hfil\commandwarg{mainline}{MT\_list}\hfil or \hfil\commandwarg{variation}{MT\_list}\hfil
where
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MT\_list} \bnfprod\={} \bnf{MT} \bnfterm{space} \bnf{MT\_list}\\
\>\bnfor{} \bnf{MT}
\end{tabbing}
\end{minipage}
\end{center}
using BNF (Backus-Naur Form) notation with `\bnfterm{space}' as the
terminal symbol for the character '\ ' (ASCII code
32\base{10}).
\section*{Stage 2: Splitting off move numbers}
Each \abbrev{MT} may be either a chess move (\abbrev{CM}), a move number (\abbrev{MN})
or a token like ``\texttt{2.Kg1}'' that combines both:
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MT} \bnfprod\={} \bnf{MN} \bnf{CM}\\
\>\bnfor{} \bnf{CM}\\
\>\bnfor{} \bnf{MN}
\end{tabbing}
\end{minipage}
\end{center}
The only task of this stage is to separate ``combined tokens'' (first rule in the
production above) and, therefore, supply the next stage 3 with a steady stream
of single move tokens (\abbrev{M}).
\begin{quote}
Remark: This ``separation'' probably has to be done by inspecting the whole
token character for character. Thus, it appears to be efficient to already
collect information about the move number \abbrev{MN} (White/Black to move,
getting the number itself, suppressing leading zeros) in this early stage\ldots
\end{quote}
No semantic checking is done here, i.e.~this stage doesn't
detect errors like \mbox{``\texttt{2.~Kg1 3.~Bf4}''}.
\section*{Stage 3: Parsing single move tokens}
At this point, we can be sure to get either a chess move \abbrev{CM}
or a move number \abbrev{MN}:
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{M} \bnfprod\={} \bnf{CM}\\
\>\bnfor{} \bnf{MN}
\end{tabbing}
\end{minipage}
\end{center}
Both can be distinguished well by inspecting the first character of the token, since
only move numbers \abbrev{MN} may start with a digit (\abbrev{D}).
This stage would be the right place to check for the correct order
of chess moves and move numbers, i.e.~if a \abbrev{MN} is encountered
the right side (White or Black) should be to move.
\section*{Parsing move numbers}
Move numbers \abbrev{MN} consist of an integer value (\abbrev{N}), immediately
followed by one or three dots as terminal symbols, signalling whether it's
Whites or Blacks move.
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MN} \bnfprod\={} \bnf{N} \bnfterm{...}\\
\>\bnfor{} \bnf{N} \bnfterm{.}
\end{tabbing}
\end{minipage}
\end{center}
An integer value \abbrev{N} is a nonempty list of single digits
(\abbrev{D})\ldots
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{N} \bnfprod\={} \bnf{D} \bnf{N}\\
\>\bnfor{} \bnf{D}
\end{tabbing}
\end{minipage}
\end{center}
\ldots where each digit \abbrev{D} should be contained in the set of terminal
symbols 0--9.
\begin{center}
\begin{minipage}{5cm}
\begin{tabbing}
\bnf{D} \bnfprod\={} \bnfterm{0}\bnfor\bnfterm{1}\bnfor\bnfterm{2}%
\bnfor\bnfterm{3}\bnfor\bnfterm{4}\bnfor\bnfterm{5}\bnfor\bnfterm{6}%
\bnfor\bnfterm{7}\bnfor\bnfterm{8}\bnfor\bnfterm{9}
\end{tabbing}
\end{minipage}
\end{center}
Here, the move number can be checked against the internal move counter
if necessary.
\section*{Parsing chess moves}
A chess move \abbrev{CM} starts with the ``move specification'' (\abbrev{MS}),
giving information about the piece that is to move and the source and
destination squares. Additionally, an arbitrary number of character tokens may follow
as a move comment (\abbrev{MC}). So, after enough ``hints'' for executing the move
are collected, i.e.~\abbrev{MS} was ``matched'', the rest of the token is regarded
as comment \abbrev{MC} and is output unchanged.
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{CM} \bnfprod\={} \bnf{MS} \bnf{MC}\\
\>\bnfor{} \bnf{MS}
\end{tabbing}
\end{minipage}
\end{center}
Before defining the move specification \abbrev{MS} itself a few helping nonterminal
symbols are introduced. Please, remember that bold characters within
the ``rules'' denote terminal symbols\ldots
\begin{enumerate}
\item A ``piece'' character (\abbrev{P})
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{P} \bnfprod\={} \bnfterm{K}\bnfor\bnfterm{Q}\bnfor\bnfterm{B}%
\bnfor\bnfterm{N}\bnfor\bnfterm{R}
\end{tabbing}
\end{minipage}
\end{center}
Remark: This definition uses the english letters for the single pieces. The
real implementation should be independent of the used language.
\item A ``file'' character (\abbrev{f})
\begin{center}
\begin{minipage}{5cm}
\begin{tabbing}
\bnf{f} \bnfprod\={} \bnfterm{a}\bnfor\bnfterm{b}\bnfor\bnfterm{c}%
\bnfor\bnfterm{d}\bnfor\bnfterm{e}\bnfor\bnfterm{f}\bnfor\bnfterm{g}%
\bnfor\bnfterm{h}
\end{tabbing}
\end{minipage}
\end{center}
\item A ``rank'' character (\abbrev{r})
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{r} \bnfprod\={} \bnfterm{1}\bnfor\bnfterm{2}\bnfor\bnfterm{3}%
\bnfor\bnfterm{4}\bnfor\bnfterm{5}\bnfor\bnfterm{6}\bnfor\bnfterm{7}%
\bnfor\bnfterm{8}
\end{tabbing}
\end{minipage}
\end{center}
\item A ``capture'' character (\bnfjoin)
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnfjoin{} \bnfprod\={} \bnfterm{-}\\
\>\bnfor{} \bnfterm{x}\\
\>\bnfor{} \bnfempty
\end{tabbing}
\end{minipage}
\end{center}
where '\bnfempty' denotes the ``empty symbol''.
\end{enumerate}
Move specifications (\abbrev{MS}) can be subdivided into the following groups:
\begin{itemize}
\item Starting with a ``piece'' character
\begin{itemize}
\item With source square
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MS} \bnfprod\={} \bnf{P} \bnf{f} \bnf{r} \bnfjoin{} \bnf{f} \bnf{r}\\
\>\bnfor{} \bnf{P} \bnf{f} \bnfjoin{} \bnf{f} \bnf{r}\\
\>\bnfor{} \bnf{P} \bnf{r} \bnfjoin{} \bnf{f} \bnf{r}
\end{tabbing}
\end{minipage}
\end{center}
Examples: ``\texttt{Qf3-f4}'', ``\texttt{Ree6}'', ``\texttt{N1xc3}''
\item Only a destination square present
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MS} \bnfprod\={} \bnf{P} \bnfjoin{} \bnf{f} \bnf{r}
\end{tabbing}
\end{minipage}
\end{center}
Example: ``\texttt{Nxc4}''
\end{itemize}
\item Without leading ``piece'' character
\begin{itemize}
\item With source square
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MS} \bnfprod\={} \bnf{f} \bnf{r} \bnfjoin{} \bnf{f} \bnf{r} \bnf{P}\\
\>\bnfor{} \bnf{f} \bnfjoin{} \bnf{f} \bnf{r} \bnf{P}\\
\>\bnfor{} \bnf{f} \bnf{r} \bnfjoin{} \bnf{f} \bnf{r}\\
\>\bnfor{} \bnf{f} \bnfjoin{} \bnf{f} \bnf{r}
\end{tabbing}
\end{minipage}
\end{center}
Examples: ``\texttt{f7-f8R}'', ``\texttt{dxe8B}'', ``\texttt{g2-g4}'',
``\texttt{fxe6}''
\item Only a destination square present
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MS} \bnfprod\={} \bnf{f} \bnf{r} \bnf{P}\\
\>\bnfor{} \bnf{f} \bnf{r}
\end{tabbing}
\end{minipage}
\end{center}
Examples: ``\texttt{e8R}'', ``\texttt{a6}''
\end{itemize}
\item Castlings
\begin{center}
\begin{minipage}{3cm}
\begin{tabbing}
\bnf{MS} \bnfprod\={} \bnfterm{O-O-O}\\
\>\bnfor{} \bnfterm{O-O}
\end{tabbing}
\end{minipage}
\end{center}
Both of these terminals use the letter 'O' (ASCII code
79\base{10}) and not the digit '0'
(ASCII code 48\base{10})!
\end{itemize}
\section*{Final remark}
This text tries to provide only the syntax for the frontend of the new ``move
machine''. All the things that happen after the input was ``matched'' and
information was drawn out of the given ``chess moves'' to the largest extent,
i.e.~the semantic actions, are beyond the scope of this document.
So, at the moment it is perfectly legal and syntactically correct to say
``\texttt{4. gxf8K}''\ldots
\end{document}
|