source: trunk/minix/commands/bc/scan.l@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 5.2 KB
Line 
1%{
2/* scan.l: the (f)lex description file for the scanner. */
3
4/* This file is part of bc written for MINIX.
5 Copyright (C) 1991, 1992 Free Software Foundation, Inc.
6
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.
11
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.
16
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.
20
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
27
28*************************************************************************/
29
30#include "bcdefs.h"
31#include "y.tab.h"
32#include "global.h"
33#include "proto.h"
34
35/* Using flex, we can ask for a smaller input buffer. With lex, this
36 does nothing! */
37
38#ifdef SMALL_BUF
39#undef YY_READ_BUF_SIZE
40#define YY_READ_BUF_SIZE 512
41#endif
42
43/* We want to define our own yywrap. */
44#undef yywrap
45_PROTOTYPE(int yywrap, (void));
46
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
49 does nothing! */
50#include <errno.h>
51#undef YY_INPUT
52#define YY_INPUT(buf,result,max_size) \
53 while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
54 if (errno != EINTR) \
55 YY_FATAL_ERROR( "read() in flex scanner failed" );
56
57%}
58DIGIT [0-9A-F]
59LETTER [a-z]
60%%
61define return(Define);
62break return(Break);
63quit return(Quit);
64length return(Length);
65return return(Return);
66for return(For);
67if return(If);
68while return(While);
69sqrt return(Sqrt);
70scale return(Scale);
71ibase return(Ibase);
72obase return(Obase);
73auto return(Auto);
74else return(Else);
75read return(Read);
76halt return(Halt);
77last return(Last);
78warranty return(Warranty);
79continue return(Continue);
80print return(Print);
81limits return(Limits);
82"+"|"-"|";"|"("|")"|"{"|"}"|"["|"]"|","|"^" { yylval.c_value = yytext[0];
83 return((int)yytext[0]); }
84&& { return(AND); }
85\|\| { return(OR); }
86"!" { return(NOT); }
87"*"|"/"|"%" { yylval.c_value = yytext[0]; return(MUL_OP); }
88"="|\+=|-=|\*=|\/=|%=|\^= { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
89=\+|=-|=\*|=\/|=%|=\^ {
90#ifdef OLD_EQ_OP
91 char warn_save;
92 warn_save = warn_not_std;
93 warn_not_std = TRUE;
94 warn ("Old fashioned =<op>");
95 warn_not_std = warn_save;
96 yylval.c_value = yytext[1];
97#else
98 yylval.c_value = '=';
99 yyless (1);
100#endif
101 return(ASSIGN_OP);
102 }
103==|\<=|\>=|\!=|"<"|">" { yylval.s_value = strcopyof((char *) yytext);
104 return(REL_OP); }
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 */ }
109"/*" {
110 int c;
111
112 for (;;)
113 {
114 while ( ((c=input()) != '*') && (c != EOF))
115 /* eat it */
116 if (c == '\n') line_no++;
117 if (c == '*')
118 {
119 while ( (c=input()) == '*') /* eat it*/;
120 if (c == '/') break; /* at end of comment */
121 if (c == '\n') line_no++;
122 }
123 if (c == EOF)
124 {
125 fprintf (stderr,"EOF encountered in a comment.\n");
126 break;
127 }
128 }
129 }
130[a-z][a-z0-9_]* { yylval.s_value = strcopyof((char *) yytext); return(NAME); }
131\"[^\"]*\" {
132 unsigned char *look;
133 int count = 0;
134 yylval.s_value = strcopyof((char *) yytext);
135 for (look = yytext; *look != 0; look++)
136 {
137 if (*look == '\n') line_no++;
138 if (*look == '"') count++;
139 }
140 if (count != 2) yyerror ("NUL character in string.");
141 return(STRING);
142 }
143{DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
144 unsigned char *src, *dst;
145 int len;
146 /* remove a trailing decimal point. */
147 len = strlen((char *) yytext);
148 if (yytext[len-1] == '.')
149 yytext[len-1] = 0;
150 /* remove leading zeros. */
151 src = yytext;
152 dst = yytext;
153 while (*src == '0') src++;
154 if (*src == 0) src--;
155 /* Copy strings removing the newlines. */
156 while (*src != 0)
157 {
158 if (*src == '\\')
159 {
160 src++; src++;
161 line_no++;
162 }
163 else
164 *dst++ = *src++;
165 }
166 *dst = 0;
167 yylval.s_value = strcopyof((char *) yytext);
168 return(NUMBER);
169 }
170. {
171 if (yytext[0] < ' ')
172 yyerror ("illegal character: ^%c",yytext[0] + '@');
173 else
174 if (yytext[0] > '~')
175 yyerror ("illegal character: \\%3d", (int) yytext[0]);
176 else
177 yyerror ("illegal character: %s",yytext);
178 }
179%%
180
181
182
183/* This is the way to get multiple files input into lex. */
184
185int
186yywrap()
187{
188 if (!open_new_file ()) return (1); /* EOF on standard in. */
189 return (0); /* We have more input. */
190}
Note: See TracBrowser for help on using the repository browser.