/* scan.l: the (f)lex description file for the scanner. */
/* This file is part of bc written for MINIX.
Copyright (C) 1991 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License , or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
You may contact the author by:
us-mail: Philip A. Nelson
Computer Science Department, 9062
Western Washington University
Bellingham, WA 98226-9062
*************************************************************************/
/* Using flex, we can ask for a smaller input buffer. With lex, this
#define YY_READ_BUF_SIZE 512
/* We want to define our own yywrap. */
_PROTOTYPE(int yywrap, (void));
/* MINIX returns from read with < 0 if SIGINT is encountered.
In flex, we can redefine YY_INPUT to the following. In lex, this
#define YY_INPUT(buf,result,max_size) \
while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
YY_FATAL_ERROR( "read() in flex scanner failed" );
warranty return(Warranty);
continue return(Continue);
"+"|"-"|";"|"("|")"|"{"|"}"|"["|"]"|","|"^" { yylval.c_value = yytext[0];
return((int)yytext[0]); }
"*"|"/"|"%" { yylval.c_value = yytext[0]; return(MUL_OP); }
"="|\+=|-=|\*=|\/=|%=|\^= { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
warn_save = warn_not_std;
warn ("Old fashioned =<op>");
warn_not_std = warn_save;
yylval.c_value = yytext[1];
==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof(yytext); return(REL_OP); }
\+\+|-- { yylval.c_value = yytext[0]; return(INCR_DECR); }
"\n" { line_no++; return(NEWLINE); }
\\\n { line_no++; /* ignore a "quoted" newline */ }
[ \t]+ { /* ignore spaces and tabs */ }
while ( ((c=input()) != '*') && (c != EOF))
if (c == '\n') line_no++;
while ( (c=input()) == '*') /* eat it*/;
if (c == '/') break; /* at end of comment */
if (c == '\n') line_no++;
fprintf (stderr,"EOF encountered in a comment.\n");
[a-z][a-z0-9_]* { yylval.s_value = strcopyof(yytext); return(NAME); }
yylval.s_value = strcopyof(yytext);
for (look = yytext; *look != 0; look++)
if (*look == '\n') line_no++;
{DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
/* remove a trailing decimal point. */
if (yytext[len-1] == '.')
/* remove leading zeros. */
while (*src == '0') src++;
/* Copy strings removing the newlines. */
yylval.s_value = strcopyof(yytext);
. yyerror ("illegal character: %s",yytext);
/* This is the way to get multiple files input into lex. */
if (!open_new_file ()) return (1); /* EOF on standard in. */
return (0); /* We have more input. */