9 * parser.l -- lex parser of algebraic chess moves for XBoard
12 * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
13 * Enhancements Copyright 1992-95 Free Software Foundation, Inc.
15 * The following terms apply to Digital Equipment Corporation's copyright
17 * ------------------------------------------------------------------------
20 * Permission to use, copy, modify, and distribute this software and its
21 * documentation for any purpose and without fee is hereby granted,
22 * provided that the above copyright notice appear in all copies and that
23 * both that copyright notice and this permission notice appear in
24 * supporting documentation, and that the name of Digital not be
25 * used in advertising or publicity pertaining to distribution of the
26 * software without specific, written prior permission.
28 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
29 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
30 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
31 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
32 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
33 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
35 * ------------------------------------------------------------------------
37 * The following terms apply to the enhanced version of XBoard distributed
38 * by the Free Software Foundation:
39 * ------------------------------------------------------------------------
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation; either version 2 of the License, or
43 * (at your option) any later version.
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
50 * You should have received a copy of the GNU General Public License
51 * along with this program; if not, write to the Free Software
52 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
53 * ------------------------------------------------------------------------
56 /* This parser handles all forms of promotion.
57 * The parser resolves ambiguous moves by searching and check-testing.
58 * It also parses comments of the form [anything] or (anything).
63 #define NO_CONSTRAINT -1
66 #define UNPUT_BUF_SIZE YYLMAX
69 /* yytext is probably a char*, but could be a char[]. yy_text is set
70 in YY_DECL below, because if yytext is a char*, its value is not
73 #else /*!FLEX_SCANNER*/
74 /* yytext is definitely a char[], so yy_text can be set here, statically. */
75 char *yy_text = (char *) yytext;
81 #define YY_INPUT(buf, result, max_size) my_yy_input(buf, &result, max_size)
84 int _yylex YY_PROTO((void)); \
85 int yylex YY_PROTO((void)) \
87 int result = _yylex(); \
88 yy_text = (char *) yytext; \
91 int _yylex YY_PROTO((void))
99 /* The includes must be here, below the #undef input */
106 #else /* not STDC_HEADERS */
109 # else /* not HAVE_STRING_H */
110 # include <strings.h>
111 # endif /* not HAVE_STRING_H */
112 #endif /* not STDC_HEADERS */
118 #if defined(_amigados)
121 # include <fcntl.h> /* isatty() prototype */
122 # endif /* HAVE_FCNTL_H */
123 #endif /* defined(_amigados) */
127 #include "frontend.h"
131 extern int PosFlags P((int));
133 extern Board boards[MAX_MOVES];
135 int yyskipmoves = FALSE;
136 char currentMoveString[YYLMAX];
138 char unputBuffer[UNPUT_BUF_SIZE];
143 void my_yy_input P((char *buf, int *result, int max_size));
144 #else /*!FLEX_SCANNER*/
145 static int input P((void));
146 static void output P((int ch));
147 static void unput P((int ch));
148 int yylook P((void));
149 int yyback P((int *, int));
152 int yywrap P((void));
153 extern void CopyBoard P((Board to, Board from));
158 [RrBbNnQqKkPp][/]?[a-h][1-8][xX:-]?[a-h][1-8](=?\(?[RrBbNnQqKk]\)?)? {
160 * Fully-qualified algebraic move, possibly with promotion
162 int skip1 = 0, skip2 = 0;
166 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
169 if (yytext[1] == '/') skip1 = 1;
171 /* remove the [xX:-] */
172 if ((yytext[3+skip1] == 'x') || (yytext[3+skip1] == 'X') ||
173 (yytext[3+skip1] == '-') || (yytext[3+skip1] == ':')) skip2 = 1;
175 currentMoveString[0] = yytext[1+skip1];
176 currentMoveString[1] = yytext[2+skip1];
177 currentMoveString[2] = yytext[3+skip1+skip2];
178 currentMoveString[3] = yytext[4+skip1+skip2];
179 currentMoveString[4] = NULLCHAR;
181 if (yyleng-skip1-skip2 > 5) {
182 if (yytext[yyleng-1] == ')') {
183 currentMoveString[4] = ToLower(yytext[yyleng-2]);
185 currentMoveString[4] = ToLower(yytext[yyleng-1]);
187 currentMoveString[5] = NULLCHAR;
190 piece = boards[yyboardindex]
191 [currentMoveString[1] - '1'][currentMoveString[0] - 'a'];
192 if (ToLower(yytext[0]) != ToLower(PieceToChar(piece)))
193 return (int) IllegalMove;
195 result = LegalityTest(boards[yyboardindex],
196 PosFlags(yyboardindex), EP_UNKNOWN,
197 currentMoveString[1] - '1',
198 currentMoveString[0] - 'a',
199 currentMoveString[3] - '1',
200 currentMoveString[2] - 'a',
201 currentMoveString[4]);
203 if (currentMoveString[4] == NULLCHAR &&
204 (result == WhitePromotionQueen || result == BlackPromotionQueen)) {
205 currentMoveString[4] = 'q';
206 currentMoveString[5] = NULLCHAR;
212 [a-h][1-8][xX:-]?[a-h][1-8](=?\(?[RrBbNnQqKk]\)?)? {
214 * Simple algebraic move, possibly with promotion
219 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
221 /* remove the [xX:-] */
222 if ((yytext[2] == 'x') || (yytext[2] == 'X') ||
223 (yytext[2] == '-') || (yytext[2] == ':')) skip = 1;
225 currentMoveString[0] = yytext[0];
226 currentMoveString[1] = yytext[1];
227 currentMoveString[2] = yytext[2+skip];
228 currentMoveString[3] = yytext[3+skip];
229 currentMoveString[4] = NULLCHAR;
231 if (yyleng-skip > 4) {
232 if (yytext[yyleng-1] == ')') {
233 currentMoveString[4] = ToLower(yytext[yyleng-2]);
235 currentMoveString[4] = ToLower(yytext[yyleng-1]);
237 currentMoveString[5] = NULLCHAR;
240 result = LegalityTest(boards[yyboardindex],
241 PosFlags(yyboardindex), EP_UNKNOWN,
242 currentMoveString[1] - '1',
243 currentMoveString[0] - 'a',
244 currentMoveString[3] - '1',
245 currentMoveString[2] - 'a',
246 currentMoveString[4]);
248 if (currentMoveString[4] == NULLCHAR &&
249 (result == WhitePromotionQueen || result == BlackPromotionQueen)) {
250 currentMoveString[4] = 'q';
251 currentMoveString[5] = NULLCHAR;
257 [a-h][1-8](=?\(?[RrBbNnQqKk]\)?)? {
259 * Pawn move, possibly with promotion
261 DisambiguateClosure cl;
264 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
267 if (yytext[2] == '=') skip++;
268 if (yytext[2+skip] == '(') skip++;
270 cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;
272 cl.ffIn = yytext[0] - 'a';
273 cl.rtIn = yytext[1] - '1';
274 cl.ftIn = yytext[0] - 'a';
275 cl.promoCharIn = yytext[2+skip];
276 Disambiguate(boards[yyboardindex],
277 PosFlags(yyboardindex), EP_UNKNOWN, &cl);
279 currentMoveString[0] = cl.ff + 'a';
280 currentMoveString[1] = cl.rf + '1';
281 currentMoveString[2] = cl.ft + 'a';
282 currentMoveString[3] = cl.rt + '1';
283 currentMoveString[4] = cl.promoChar;
284 currentMoveString[5] = NULLCHAR;
286 return (int) cl.kind;
290 (ab|bc|cd|de|ef|fg|gh|hg|gf|fe|ed|dc|cb|ba|([a-h][xX:-][a-h]))(=?\(?[RrBbNnQqKk]\)?)?(ep|"e.p.")? {
292 * Pawn capture, possibly with promotion, possibly ambiguous
294 DisambiguateClosure cl;
295 int skip1 = 0, skip2 = 0;
297 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
299 /* remove trailing ep or e.p. (nonstandard PGN) */
300 if (yytext[yyleng-1] == 'p') {
302 yytext[yyleng] = NULLCHAR;
303 } else if (yytext[yyleng-1] == '.') {
305 yytext[yyleng] = NULLCHAR;
308 /* remove the [xX:-] and =() */
309 if ((yytext[1] == 'x') || (yytext[1] == 'X')
310 || (yytext[1] == ':') || (yytext[1] == '-')) skip1 = 1;
311 if (yytext[2+skip1] == '=') skip2++;
312 if (yytext[2+skip1+skip2] == '(') skip2++;
314 cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;
316 cl.ffIn = yytext[0] - 'a';
318 cl.ftIn = yytext[1+skip1] - 'a';
319 cl.promoCharIn = yytext[2+skip1+skip2];
320 Disambiguate(boards[yyboardindex],
321 PosFlags(yyboardindex), EP_UNKNOWN, &cl);
323 currentMoveString[0] = cl.ff + 'a';
324 currentMoveString[1] = cl.rf + '1';
325 currentMoveString[2] = cl.ft + 'a';
326 currentMoveString[3] = cl.rt + '1';
327 currentMoveString[4] = cl.promoChar;
328 currentMoveString[5] = NULLCHAR;
330 return (int) cl.kind;
333 [a-h][xX:]?[a-h][1-8](=?\(?[RrBbNnQqKk]\)?)?(ep|"e.p.")? {
335 * unambiguously abbreviated Pawn capture, possibly with promotion
340 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
342 /* remove trailing ep or e.p. (nonstandard PGN) */
343 if (yytext[yyleng-1] == 'p') {
345 yytext[yyleng] = NULLCHAR;
346 } else if (yytext[yyleng-1] == '.') {
348 yytext[yyleng] = NULLCHAR;
351 /* remove the [xX:-] */
352 if ((yytext[1] == 'x') || (yytext[1] == 'X')
353 || (yytext[1] == ':') || (yytext[1] == '-')) skip = 1;
355 currentMoveString[0] = yytext[0];
356 currentMoveString[2] = yytext[1+skip];
357 currentMoveString[3] = yytext[2+skip];
358 if (WhiteOnMove(yyboardindex)) {
359 if (yytext[2+skip] == '1') return (int) ImpossibleMove;
360 currentMoveString[1] = yytext[2+skip] - 1;
362 if (yytext[2+skip] == '8') return (int) ImpossibleMove;
363 currentMoveString[1] = yytext[2+skip] + 1;
365 if (yyleng-skip > 3) {
366 if (yytext[yyleng-1] == ')')
367 currentMoveString[4] = ToLower(yytext[yyleng-2]);
369 currentMoveString[4] = ToLower(yytext[yyleng-1]);
370 currentMoveString[5] = NULLCHAR;
372 currentMoveString[4] = NULLCHAR;
375 result = LegalityTest(boards[yyboardindex],
376 PosFlags(yyboardindex), EP_UNKNOWN,
377 currentMoveString[1] - '1',
378 currentMoveString[0] - 'a',
379 currentMoveString[3] - '1',
380 currentMoveString[2] - 'a',
381 currentMoveString[4]);
383 if (currentMoveString[4] == NULLCHAR &&
384 (result == WhitePromotionQueen || result == BlackPromotionQueen)) {
385 currentMoveString[4] = 'q';
386 currentMoveString[5] = NULLCHAR;
389 if (result != IllegalMove) return (int) result;
391 /* Special case: improperly written en passant capture */
392 if (WhiteOnMove(yyboardindex)) {
393 if (currentMoveString[3] == '5') {
394 currentMoveString[1] = '5';
395 currentMoveString[3] = '6';
397 return (int) IllegalMove;
400 if (currentMoveString[3] == '4') {
401 currentMoveString[1] = '4';
402 currentMoveString[3] = '3';
404 return (int) IllegalMove;
408 result = LegalityTest(boards[yyboardindex],
409 PosFlags(yyboardindex), EP_UNKNOWN,
410 currentMoveString[1] - '1',
411 currentMoveString[0] - 'a',
412 currentMoveString[3] - '1',
413 currentMoveString[2] - 'a',
414 currentMoveString[4]);
416 if (result == WhiteCapturesEnPassant || result == BlackCapturesEnPassant)
419 return (int) IllegalMove;
422 [RrBbNnQqKk][xX:-]?[a-h][1-8] {
424 * piece move, possibly ambiguous
426 DisambiguateClosure cl;
429 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
431 /* remove the [xX:-] */
432 if ((yytext[1] == 'x') || (yytext[1] == 'X')
433 || (yytext[1] == ':') || (yytext[1] == '-')) skip = 1;
435 if (WhiteOnMove(yyboardindex)) {
436 cl.pieceIn = CharToPiece(ToUpper(yytext[0]));
438 cl.pieceIn = CharToPiece(ToLower(yytext[0]));
442 cl.rtIn = yytext[2+skip] - '1';
443 cl.ftIn = yytext[1+skip] - 'a';
444 cl.promoCharIn = NULLCHAR;
445 Disambiguate(boards[yyboardindex],
446 PosFlags(yyboardindex), EP_UNKNOWN, &cl);
448 currentMoveString[0] = cl.ff + 'a';
449 currentMoveString[1] = cl.rf + '1';
450 currentMoveString[2] = cl.ft + 'a';
451 currentMoveString[3] = cl.rt + '1';
452 currentMoveString[4] = cl.promoChar;
453 currentMoveString[5] = NULLCHAR;
455 return (int) cl.kind;
458 [RrBbNnQqKk][a-h1-8][xX:-]?[a-h][1-8] {
460 * piece move with rank or file disambiguator
462 DisambiguateClosure cl;
465 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
467 /* remove the [xX:-] */
468 if ((yytext[2] == 'x') || (yytext[2] == 'X')
469 || (yytext[2] == ':') || (yytext[2] == '-')) skip = 1;
471 if (WhiteOnMove(yyboardindex)) {
472 cl.pieceIn = CharToPiece(ToUpper(yytext[0]));
474 cl.pieceIn = CharToPiece(ToLower(yytext[0]));
476 if (isalpha(yytext[1])) {
478 cl.ffIn = yytext[1] - 'a';
480 cl.rfIn = yytext[1] - '1';
483 cl.rtIn = yytext[3+skip] - '1';
484 cl.ftIn = yytext[2+skip] - 'a';
485 cl.promoCharIn = NULLCHAR;
486 Disambiguate(boards[yyboardindex],
487 PosFlags(yyboardindex), EP_UNKNOWN, &cl);
489 currentMoveString[0] = cl.ff + 'a';
490 currentMoveString[1] = cl.rf + '1';
491 currentMoveString[2] = cl.ft + 'a';
492 currentMoveString[3] = cl.rt + '1';
493 currentMoveString[4] = cl.promoChar;
494 currentMoveString[5] = NULLCHAR;
496 return (int) cl.kind;
499 000|0-0-0|ooo|OOO|o-o-o|O-O-O {
502 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
504 if (WhiteOnMove(yyboardindex)) {
505 if (boards[yyboardindex][0][3] == WhiteKing) {
506 /* ICS wild castling */
507 strcpy(currentMoveString, "d1f1");
513 strcpy(currentMoveString, "e1c1");
520 if (boards[yyboardindex][7][3] == BlackKing) {
521 /* ICS wild castling */
522 strcpy(currentMoveString, "d8f8");
528 strcpy(currentMoveString, "e8c8");
535 return (int) LegalityTest(boards[yyboardindex],
536 PosFlags(yyboardindex), EP_UNKNOWN,
537 rf, ff, rt, ft, NULLCHAR);
540 00|0-0|oo|OO|o-o|O-O {
543 if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
545 if (WhiteOnMove(yyboardindex)) {
546 if (boards[yyboardindex][0][3] == WhiteKing) {
547 /* ICS wild castling */
548 strcpy(currentMoveString, "d1b1");
554 strcpy(currentMoveString, "e1g1");
561 if (boards[yyboardindex][7][3] == BlackKing) {
562 /* ICS wild castling */
563 strcpy(currentMoveString, "d8b8");
569 strcpy(currentMoveString, "e8g8");
576 return (int) LegalityTest(boards[yyboardindex],
577 PosFlags(yyboardindex), EP_UNKNOWN,
578 rf, ff, rt, ft, NULLCHAR);
581 [PpNnBbRrQq]@[a-h][1-8] {
582 /* Bughouse piece drop. No legality checking for now. */
583 currentMoveString[1] = '@';
584 currentMoveString[2] = yytext[2];
585 currentMoveString[3] = yytext[3];
586 currentMoveString[4] = NULLCHAR;
587 if (WhiteOnMove(yyboardindex)) {
588 currentMoveString[0] = ToUpper(yytext[0]);
589 return (int) WhiteDrop;
591 currentMoveString[0] = ToLower(yytext[0]);
592 return (int) BlackDrop;
597 if (WhiteOnMove(yyboardindex))
598 return (int) BlackWins;
600 return (int) WhiteWins;
603 (([Ww](hite)?)|([Bb](lack)?))" "(([Rr]esign)|([Ff]orfeit))(s|ed)? {
604 return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);
607 (([Ww](hite)?)|([Bb](lack)?))" "[Dd]isconnect(s|ed) {
608 return (int) GameUnfinished;
612 return (int) GameIsDrawn;
616 return (int) GameIsDrawn;
620 if (WhiteOnMove(yyboardindex))
621 return (int) BlackWins;
623 return (int) WhiteWins;
627 if (WhiteOnMove(yyboardindex))
628 return (int) BlackWins;
630 return (int) WhiteWins;
633 [Dd]raw(n)?(" "by)?(" "[Rr]epetition)|(" "[Aa]gree(d|ment)) {
634 return (int) GameIsDrawn;
637 [Dd]raw(n)?(" (".*")")? {
638 return (int) GameIsDrawn;
641 (([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ww][io]n(s)?.*) {
642 return (int) (ToUpper(yytext[0]) == 'W' ? WhiteWins : BlackWins);
645 (([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ll]os[tes]+.*) {
646 return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);
649 ("{"[^\}\n]*"} ")?(1-0|"1 - 0"|"1/0"|"1 / 0"|"1:0"|"1 : 0")(" (".*")"|" {".*"}")? {
650 return (int) WhiteWins;
653 ("{"[^\}\n]*"} ")?(0-1|"0 - 1"|"0/1"|"0 / 1"|"0:1"|"0 : 1")(" (".*")"|" {".*"}")? {
654 return (int) BlackWins;
657 ("{"[^\}\n]*"} ")?("1/2"|"1 / 2")(" "?[-:]" "?("1/2"|"1 / 2"))?(" (".*")"|" {".*"}")? {
658 return (int) GameIsDrawn;
661 ("{"[^\}\n]*"} ")?"*"(" (".*")"|" {".*"}")? {
662 return (int) GameUnfinished;
665 [1-9][0-9]*/"."?[ \t\n]*[a-hNnPpRrBQqKkOo] {
667 if ((yyleng == 1) && (yytext[0] == '1'))
668 return (int) MoveNumberOne;
671 \([0-9]+:[0-9][0-9](\.[0-9]+)?\)|\{[0-9]+:[0-9][0-9](\.[0-9]+)?\} {
672 /* elapsed time indication, e.g. (0:12) or {10:21.071} */
673 return (int) ElapsedTime;
677 /* position diagram enclosed in [-- --] */
678 return (int) PositionDiagram;
681 ^"{--------------"\n[^\}]*\n"--------------}"$ {
682 /* position diagram enclosed in {-- --} */
683 return (int) PositionDiagram;
686 \[[ \t\n]*[A-Za-z0-9][A-Za-z0-9_+#=-]*[ \t\n]*\"[^"]*\"[ \t\n]*\] {
690 [Gg](nu|NU)" "?[Cc](hess|HESS).*[Gg](ame|AME) {
691 return (int) GNUChessGame;
694 ^[#;%]" "[^ ]*(" game file"|" position file").*$ {
695 return (int) XBoardGame;
698 \$[0-9]+ { /* numeric annotation glyph */
702 \{[^\}]*\} { /* anything in {} */
703 return (int) Comment;
706 ;.*$ { /* ; to end of line */
707 return (int) Comment;
710 \[[^\]]*\] { /* anything in [] */
711 return (int) Comment;
714 \([^()]*(\([^()]*\)[^()]*)+[^()]*\) { /* nested () */
715 return (int) Comment;
718 \([^)][^)]+\) { /* >=2 chars in () */
719 return (int) Comment;
722 ^[-a-zA-Z0-9]+:" ".*(\n[ \t]+.*)* {
723 /* Skip mail headers */
727 /* Skip random words */
731 /* Skip everything else */
737 static char *StringToLex;
746 if (StringToLex != NULL) {
752 } else if (unputCount > 0) {
753 ret = unputBuffer[--unputCount];
765 * Return offset of next pattern within current file
769 int offset = ftell(lexFP) - unputCount;
777 static void output(ch)
780 fprintf(stderr, "PARSER BUG: unmatched character '%c' (0%o)\n",
784 static void unput(ch)
788 if (StringToLex != NULL) {
791 if (unputCount >= UNPUT_BUF_SIZE)
792 fprintf(stderr, "PARSER BUG: unput buffer overflow '%c' (0%o)\n",
794 unputBuffer[unputCount++] = ch;
798 /* Get ready to lex from a new file. Kludge below sticks
799 an artificial newline at the front of the file, which the
800 above grammar ignores, but which makes ^ at start of pattern
801 match at the real start of the file.
809 unput('\n'); /* kludge */
812 /* Get ready to lex from a string. ^ at start of pattern WON'T
813 match at the start of the string!
822 #endif /*!FLEX_SCANNER*/
825 void my_yy_input(buf, result, max_size)
832 if (StringToLex != NULL) {
834 while (*StringToLex != NULLCHAR) {
835 *buf++ = *StringToLex++;
841 count = fread(buf, 1, max_size, yyin);
851 static YY_BUFFER_STATE my_file_buffer = NULL;
854 Return offset of next pattern in the current file.
858 int pos = yy_c_buf_p - yy_current_buffer->yy_ch_buf;
860 return(ftell(yy_current_buffer->yy_input_file) -
868 if (my_file_buffer != NULL)
869 yy_delete_buffer(my_file_buffer);
871 my_file_buffer = yy_create_buffer(stdin, YY_BUF_SIZE);
872 yy_switch_to_buffer(my_file_buffer);
878 if (my_file_buffer != NULL)
879 yy_delete_buffer(my_file_buffer);
881 my_file_buffer = yy_create_buffer(f, YY_BUF_SIZE);
882 yy_switch_to_buffer(my_file_buffer);
884 #endif /*FLEX_SCANNER*/
891 /* Parse a move from the given string s */
892 /* ^ at start of pattern WON'T work here unless using flex */
893 ChessMove yylexstr(boardIndex, s)
898 char *oldStringToLex;
900 YY_BUFFER_STATE buffer, oldBuffer;
903 yyboardindex = boardIndex;
904 oldStringToLex = StringToLex;
907 buffer = yy_create_buffer(stdin, YY_BUF_SIZE);
908 oldBuffer = YY_CURRENT_BUFFER;
909 yy_switch_to_buffer(buffer);
910 #endif /*FLEX_SCANNER*/
912 ret = (ChessMove) yylex();
915 if (oldBuffer != NULL)
916 yy_switch_to_buffer(oldBuffer);
917 yy_delete_buffer(buffer);
918 #endif /*FLEX_SCANNER*/
919 StringToLex = oldStringToLex;