home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #include "chesstype.h"
- #include "notation.h"
- #include "lexer.h"
-
- /*token */
- static char curtok[MAXTOKLEN];
-
- extern FILE * infile ;
-
- /* commentary level
- act as a boolean too */
- static int comment = FALSE;
-
-
- static char nextchar()
- {
- if (!feof(infile))
- return(getc(infile));
- else
- return('\0');
- }
-
-
-
- /* this function returns the next token:
- Definition of a token:
- a number [0-9]*. ie 1. , 35.
- a string terminated by a blank or rc or "." or tab
- commentary enclosed in 90 or [] are skipped
- Each move must not have a blank inside ie exc6 legal,
- but not e x c6
- */
- int nexttoken()
- {
- int i =0;
- char c;
-
- /*(void) fprintf(stdout, "nexttoken\n");*/
- curtok[0]= '\0' ;
- c = nextchar();
- while ((c == ' ') || (c == '\n') || (c == '\t') || (c== '.') ||
- ( c== '[') || (c =='(' ) || comment ) {
- /*(void) fprintf(stdout, "=%c",c);*/
- switch (c) {
- case '[':
- case '(':
- comment++;
- break;
- case ']':
- case ')':
- comment--;
- break;
- default:
- break;
- }
- c = nextchar();
- }
-
- if (c == '\0') return (FALSE);
-
- while ( c != ' ' && c != '\n' && c != '\t' &&
- c != '.' && c != '\0' && c != '[' && c!= '(' &&
- i < MAXTOKLEN ) {
- curtok[i++] = c ;
- c = nextchar();
- }
- if ( c== '.' )
- curtok[i++] = c ;
-
- curtok[i] = '\0' ;
- if ( c == '[' || c == '(' )
- comment++;
-
- if (c == '\0') return (FALSE);
-
- /*(void) fprintf(stdout,"---%s---\n",curtok);*/
- return(TRUE);
- }
-
-
- /* this function parse the current token */
- int parsetoken()
- {
- int i;
- register int c;
-
-
- /* look for keyword */
- if (curtok[0] == '@') /* keyword case */
- return(parse_keyword(curtok));
-
- /* look for roque */
- if (parse_roque(curtok))
- return(TRUE);
-
- /* is it a move numbering ? */
- if ((curtok[0] >= '0') && (curtok[0] <= '9' )) {
- return(parse_number(curtok) );
- }
-
- /* last option: it is a move
- Syntax of a move:
- [] denote a range]
- () denote a 0/1 (absence/presence)
-
- ((Piece Name)[a-h]([1-8])[x-])(PieceName)[a-h][1-8]
-
- We use an automata here.
- */
- parse_move(curtok);
-
-
- return(TRUE);
- }
-
-