Subject: Re: Makefile.mbr problem - fix?
To: David Laight <david@l8s.co.uk>
From: Darrin B. Jewell <dbj@netbsd.org>
List: tech-toolchain
Date: 05/05/2003 18:06:55
Cool. I wouldn't bother with the double quotes and just include the
literal string in the regexp. Also, does the use of strtoul
introduce any errors trying to parse a number that is too large
to fit in an int yylval?
I haven't looked at lex input in a while, but I assume it doesn't
matter that 0 matches both your decimal and octal regexps. (The
octal regexp could be easily adjusted to be 0[0-7]+ if it mattered)
Darrin
David Laight <david@l8s.co.uk> writes:
> > However, I did consult the SUSv3 before making this change. It would
> > appear that our shell is out of spec.
> >
> > >>From the SUSv3 on arithmetic expansion in the shell:
> > "Only the decimal-constant, octal-constant, and hexadecimal-constant
> > constants specified in the ISO C standard, Section 6.4.4.1 are
> > required to be recognized as constants."
> >
> > I will file a PR about the shell bug.
>
> The following patch will fix NetBSD's /bin/sh
> (I assume it is proper lex - it seems to work!)
>
> Index: arith_lex.l
> ===================================================================
> RCS file: /cvsroot/src/bin/sh/arith_lex.l,v
> retrieving revision 1.10
> diff -u -p -r1.10 arith_lex.l
> --- arith_lex.l 1999/02/05 07:52:52 1.10
> +++ arith_lex.l 2003/05/05 21:07:35
> @@ -61,7 +61,9 @@ extern char *arith_buf, *arith_startbuf;
>
> %%
> [ \t\n] { ; }
> -[0-9]+ { yylval = atol(yytext); return(ARITH_NUM); }
> +"0x"[0-9a-fA-F]+ { yylval = strtoul(yytext, 0, 16); return(ARITH_NUM); }
> +"0"[0-7]* { yylval = strtoul(yytext, 0, 8); return(ARITH_NUM); }
> +[1-9][0-9]* { yylval = strtoul(yytext, 0, 10); return(ARITH_NUM); }
> "(" { return(ARITH_LPAREN); }
> ")" { return(ARITH_RPAREN); }
> "||" { return(ARITH_OR); }
>
> David
>
> --
> David Laight: david@l8s.co.uk