summaryrefslogtreecommitdiff
path: root/bc/scan.l
diff options
context:
space:
mode:
Diffstat (limited to 'bc/scan.l')
-rw-r--r--bc/scan.l72
1 files changed, 33 insertions, 39 deletions
diff --git a/bc/scan.l b/bc/scan.l
index b4addaa..eb2e2dd 100644
--- a/bc/scan.l
+++ b/bc/scan.l
@@ -1,12 +1,10 @@
-%{
-/* scan.l: the (f)lex description file for the scanner. */
-
/* This file is part of GNU bc.
- Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
+
+ Copyright (C) 1991-1994, 1997, 2006, 2008, 2012-2017 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
+ the Free Software Foundation; either version 3 of the License , or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -15,10 +13,8 @@
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, Inc.
- 59 Temple Place, Suite 330
- Boston, MA 02111 USA
+ along with this program; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses>.
You may contact the author by:
e-mail: philnelson@acm.org
@@ -29,6 +25,10 @@
*************************************************************************/
+/* scan.l: the (f)lex description file for the scanner. */
+
+%{
+
#include "bcdefs.h"
#include "bc.h"
#include "global.h"
@@ -48,7 +48,7 @@
/* We want to define our own yywrap. */
#undef yywrap
-_PROTOTYPE(int yywrap, (void));
+int yywrap (void);
#if defined(LIBEDIT)
/* Support for the BSD libedit with history for
@@ -59,40 +59,30 @@ _PROTOTYPE(int yywrap, (void));
/* Have input call the following function. */
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
- bcel_input((char *)buf, &result, max_size)
+ bcel_input((char *)buf, (yy_size_t *)&result, max_size)
/* Variables to help interface editline with bc. */
static const char *bcel_line = (char *)NULL;
static int bcel_len = 0;
-
-/* Required to get rid of that ugly ? default prompt! */
-char *
-null_prompt (EditLine *el)
-{
- return "";
-}
-
-
/* bcel_input puts upto MAX characters into BUF with the number put in
BUF placed in *RESULT. If the yy input file is the same as
stdin, use editline. Otherwise, just read it.
*/
static void
-bcel_input (buf, result, max)
- char *buf;
- int *result;
- int max;
+bcel_input (char *buf, yy_size_t *result, int max)
{
+ ssize_t rdsize;
if (!edit || yyin != stdin)
{
- while ( (*result = read( fileno(yyin), buf, max )) < 0 )
+ while ( (rdsize = read( fileno(yyin), buf, max )) < 0 )
if (errno != EINTR)
{
yyerror( "read() in flex scanner failed" );
- exit (1);
+ bc_exit (1);
}
+ *result = (yy_size_t) rdsize;
return;
}
@@ -143,7 +133,6 @@ static int rl_len = 0;
/* Definitions for readline access. */
extern FILE *rl_instream;
-_PROTOTYPE(char *readline, (char *));
/* rl_input puts upto MAX characters into BUF with the number put in
BUF placed in *RESULT. If the yy input file is the same as
@@ -151,10 +140,7 @@ _PROTOTYPE(char *readline, (char *));
*/
static void
-rl_input (buf, result, max)
- char *buf;
- int *result;
- int max;
+rl_input (char *buf, int *result, int max)
{
if (yyin != rl_instream)
{
@@ -162,7 +148,7 @@ rl_input (buf, result, max)
if (errno != EINTR)
{
yyerror( "read() in flex scanner failed" );
- exit (1);
+ bc_exit (1);
}
return;
}
@@ -216,7 +202,7 @@ rl_input (buf, result, max)
#endif
%}
-DIGIT [0-9A-F]
+DIGIT [0-9A-Z]
LETTER [a-z]
%s slcomment
%%
@@ -243,8 +229,10 @@ obase return(Obase);
auto return(Auto);
else return(Else);
read return(Read);
+random return(Random);
halt return(Halt);
last return(Last);
+void return(Void);
history {
#if defined(READLINE) || defined(LIBEDIT)
return(HistoryVar);
@@ -269,14 +257,14 @@ limits return(Limits);
&& { return(AND); }
\|\| { return(OR); }
"!" { return(NOT); }
-"*"|"/"|"%" { yylval.c_value = yytext[0]; return((int)yytext[0]); }
+"*"|"/"|"%"|"&" { yylval.c_value = yytext[0]; return((int)yytext[0]); }
"="|\+=|-=|\*=|\/=|%=|\^= { yylval.c_value = yytext[0]; return(ASSIGN_OP); }
=\+|=-|=\*|=\/|=%|=\^ {
#ifdef OLD_EQ_OP
char warn_save;
warn_save = warn_not_std;
warn_not_std = TRUE;
- warn ("Old fashioned =<op>");
+ ct_warn ("Old fashioned =<op>");
warn_not_std = warn_save;
yylval.c_value = yytext[1];
#else
@@ -313,7 +301,7 @@ limits return(Limits);
}
[a-z][a-z0-9_]* { yylval.s_value = strcopyof(yytext); return(NAME); }
\"[^\"]*\" {
- unsigned char *look;
+ const char *look;
int count = 0;
yylval.s_value = strcopyof(yytext);
for (look = yytext; *look != 0; look++)
@@ -325,7 +313,7 @@ limits return(Limits);
return(STRING);
}
{DIGIT}({DIGIT}|\\\n)*("."({DIGIT}|\\\n)*)?|"."(\\\n)*{DIGIT}({DIGIT}|\\\n)* {
- unsigned char *src, *dst;
+ char *src, *dst;
int len;
/* remove a trailing decimal point. */
len = strlen(yytext);
@@ -344,6 +332,11 @@ limits return(Limits);
src++; src++;
line_no++;
}
+ if (*src == ',')
+ {
+ src++;
+ ct_warn("Commas in numbers");
+ }
else
*dst++ = *src++;
}
@@ -367,8 +360,9 @@ limits return(Limits);
/* This is the way to get multiple files input into lex. */
int
-yywrap()
+yywrap(void)
{
if (!open_new_file ()) return (1); /* EOF on standard in. */
- return (0); /* We have more input. */
+ return (0); /* We have more input. */
+ yyunput(0,NULL); /* Make sure the compiler think yyunput is used. */
}