ff3cb1fa1a818232bd58283a74c3ade3c768a747
[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 static int lines = 1, cols = 1;
66 %}
67
68 PIECE   [PLNSGBRK]               
69 SQUARE  [1-9][a-i]     
70 NUMBER  [1-9]([0-9])*
71 COMMENT ["#"]([^\n])*
72
73 %%
74
75 "White wins" { return WHITE_WINS; }
76 "Black wins" { return BLACK_WINS; }
77 "Draw"       { return DRAW;       }
78
79 "\n"      { lines++; cols = 1;       }
80 "+"       { cols++;  return PROMOTE; }
81 "*"       { cols++;  return DROPS;   }
82 "'"       { cols++;  return DROPS;   }
83 "."       { cols++;  return COLON;   }
84 {PIECE}   { yylval.string = yytext; cols += strlen(yytext); return PIECE;   }
85 {SQUARE}  { yylval.string = yytext; cols += strlen(yytext); return SQUARE;  }
86 {NUMBER}  { yylval.string = yytext; cols += strlen(yytext); return NUMBER;  }
87 {COMMENT} { yylval.string = yytext; lines++; cols = 1;      return COMMENT; }
88 .         { cols++; }
89
90 %%
91
92 /*
93  * This is to avoid having to link in a lex library;
94  * flex also allows the "%option noyywrap" option but
95  * I don't think that's generally true of other lex
96  * implementations.
97  */
98
99 int
100 yywrap()
101 {
102     return 1;
103 }
104
105
106