2 /* scan.l: the (f)lex description file for the scanner. */
4 /* This file is part of bc written for MINIX.
5 Copyright (C) 1991, 1992 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License , or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 You may contact the author by:
22 e-mail: phil@cs.wwu.edu
23 us-mail: Philip A. Nelson
24 Computer Science Department, 9062
25 Western Washington University
26 Bellingham, WA 98226-9062
28 *************************************************************************/
35 /* Using flex, we can ask for a smaller input buffer. With lex, this
39 #undef YY_READ_BUF_SIZE
40 #define YY_READ_BUF_SIZE 512
43 /* We want to define our own yywrap. */
45 _PROTOTYPE(int yywrap, (void));
47 /* MINIX returns from read with < 0 if SIGINT is encountered.
48 In flex, we can redefine YY_INPUT to the following. In lex, this
52 #define YY_INPUT(buf,result,max_size) \
53 while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
55 YY_FATAL_ERROR( "read() in flex scanner failed" );
61 define return(Define);
64 length return(Length);
65 return return(Return);
78 warranty return(Warranty);
79 continue return(Continue);
81 limits return(Limits);
82 "+"|"-"|";"|"("|")"|"{"|"}"|"["|"]"|","|"^" { yylval.c_value = yytext[0];
83 return((int)yytext[0]); }
87 "*"|"/"|"%" { yylval.c_value = yytext[0]; return(MUL_OP); }
88 "="|\+=|-=|\*=|\/=|%=|\^= { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
89 =\+|=-|=\*|=\/|=%|=\^ {
92 warn_save = warn_not_std;
94 warn ("Old fashioned =<op>");
95 warn_not_std = warn_save;
96 yylval.c_value = yytext[1];
103 ==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof((char *) yytext);
105 \+\+|-- { yylval.c_value = yytext[0]; return(INCR_DECR); }
106 "\n" { line_no++; return(NEWLINE); }
107 \\\n { line_no++; /* ignore a "quoted" newline */ }
108 [ \t]+ { /* ignore spaces and tabs */ }
114 while ( ((c=input()) != '*') && (c != EOF))
116 if (c == '\n') line_no++;
119 while ( (c=input()) == '*') /* eat it*/;
120 if (c == '/') break; /* at end of comment */
121 if (c == '\n') line_no++;
125 fprintf (stderr,"EOF encountered in a comment.\n");
130 [a-z][a-z0-9_]* { yylval.s_value = strcopyof((char *) yytext); return(NAME); }
134 yylval.s_value = strcopyof((char *) yytext);
135 for (look = yytext; *look != 0; look++)
137 if (*look == '\n') line_no++;
138 if (*look == '"') count++;
140 if (count != 2) yyerror ("NUL character in string.");
143 {DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
144 unsigned char *src, *dst;
146 /* remove a trailing decimal point. */
147 len = strlen((char *) yytext);
148 if (yytext[len-1] == '.')
150 /* remove leading zeros. */
153 while (*src == '0') src++;
154 if (*src == 0) src--;
155 /* Copy strings removing the newlines. */
167 yylval.s_value = strcopyof((char *) yytext);
172 yyerror ("illegal character: ^%c",yytext[0] + '@');
175 yyerror ("illegal character: \\%3d", (int) yytext[0]);
177 yyerror ("illegal character: %s",yytext);
183 /* This is the way to get multiple files input into lex. */
188 if (!open_new_file ()) return (1); /* EOF on standard in. */
189 return (0); /* We have more input. */