Xshogi: build scanner separately from parser.
[gnushogi.git] / xshogi / scanner.l
1 %{
2 /*
3  * FILE: scanner.l
4  *
5  *     Lexer for xshogi.
6  *
7  * ------------------------------------------------------------------------
8  * xshogi is based on XBoard -- an Xt/Athena user interface for GNU Chess.
9  *
10  * Original authors:                                Dan Sears, Chris Sears
11  * Enhancements (Version 2.0 and following):        Tim Mann
12  * Modifications to XShogi (Version 1.0):           Matthias Mutz
13  * Enhancements to XShogi (Version 1.1):            Matthias Mutz
14  * Modified implementation of ISS mode for XShogi:  Matthias Mutz
15  * Current maintainer:                              Michael C. Vanier
16  *
17  * XShogi borrows some of its piece bitmaps from CRANES Shogi.
18  *
19  * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
20  * Enhancements Copyright 1992 Free Software Foundation, Inc.
21  * Enhancements for XShogi Copyright 1993, 1994, 1995 Matthias Mutz
22  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
23  *
24  * The following terms apply to Digital Equipment Corporation's copyright
25  * interest in XBoard:
26  * ------------------------------------------------------------------------
27  * All Rights Reserved
28  *
29  * Permission to use, copy, modify, and distribute this software and its
30  * documentation for any purpose and without fee is hereby granted,
31  * provided that the above copyright notice appear in all copies and that
32  * both that copyright notice and this permission notice appear in
33  * supporting documentation, and that the name of Digital not be
34  * used in advertising or publicity pertaining to distribution of the
35  * software without specific, written prior permission.
36  *
37  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43  * SOFTWARE.
44  * ------------------------------------------------------------------------
45  *
46  * This file is part of GNU shogi.
47  *
48  * GNU shogi is free software; you can redistribute it and/or modify
49  * it under the terms of the GNU General Public License as published by
50  * the Free Software Foundation.
51  *
52  * GNU shogi is distributed in the hope that it will be useful,
53  * but WITHOUT ANY WARRANTY; without even the implied warranty of
54  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55  * GNU General Public License for more details.
56  *
57  * You should have received a copy of the GNU General Public License
58  * along with GNU shogi; see the file COPYING.  If not, write to
59  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
60  *
61  * ------------------------------------------------------------------------
62  *
63  */
64
65 #include "parser.h"
66
67 extern int lines, cols;
68
69 %}
70
71 PIECE   [PLNSGBRK]               
72 SQUARE  [1-9][a-i]     
73 NUMBER  [1-9]([0-9])*
74 COMMENT ["#"]([^\n])*
75
76 %%
77
78 "White wins" { return WHITE_WINS; }
79 "Black wins" { return BLACK_WINS; }
80 "Draw"       { return DRAW;       }
81
82 "\n"      { lines++; cols = 1;       }
83 "+"       { cols++;  return PROMOTE; }
84 "*"       { cols++;  return DROPS;   }
85 "'"       { cols++;  return DROPS;   }
86 "."       { cols++;  return COLON;   }
87 {PIECE}   { yylval.string = yytext; cols += strlen(yytext); return PIECE;   }
88 {SQUARE}  { yylval.string = yytext; cols += strlen(yytext); return SQUARE;  }
89 {NUMBER}  { yylval.string = yytext; cols += strlen(yytext); return NUMBER;  }
90 {COMMENT} { yylval.string = yytext; lines++; cols = 1;      return COMMENT; }
91 .         { cols++; }
92
93 %%
94
95 /*
96  * This is to avoid having to link in a lex library;
97  * flex also allows the "%option noyywrap" option but
98  * I don't think that's generally true of other lex
99  * implementations.
100  */
101
102 int
103 yywrap()
104 {
105     return 1;
106 }
107
108
109