diff options
author | schweikh <schweikh@FreeBSD.org> | 2003-08-30 12:31:44 +0000 |
---|---|---|
committer | schweikh <schweikh@FreeBSD.org> | 2003-08-30 12:31:44 +0000 |
commit | 70a2b506d0394f7e4718d8cf08ad3ccfa2112637 (patch) | |
tree | 6e23a9b62c546da89fbc5cc397c8c2045f56efc3 /bin/sh/arith_lex.l | |
parent | e8c434f7c55809a53a64211ba5234f1f59e72df8 (diff) | |
download | FreeBSD-src-70a2b506d0394f7e4718d8cf08ad3ccfa2112637.zip FreeBSD-src-70a2b506d0394f7e4718d8cf08ad3ccfa2112637.tar.gz |
Implement missing shell arithmetic operators in $(()) expansion
and variable recognition.
PR: standards/52972
Submitted by: Wartan Hachaturow <wart@tepkom.ru>
Reviewed by: tjr (improved on original patch)
Tested by: buildworld on CURRENT.
MFC after: 6 weeks
Diffstat (limited to 'bin/sh/arith_lex.l')
-rw-r--r-- | bin/sh/arith_lex.l | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/bin/sh/arith_lex.l b/bin/sh/arith_lex.l index 6bbbfaf..cad1846 100644 --- a/bin/sh/arith_lex.l +++ b/bin/sh/arith_lex.l @@ -43,10 +43,12 @@ static char sccsid[] = "@(#)arith_lex.l 8.3 (Berkeley) 5/4/95"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "shell.h" #include "y.tab.h" #include "error.h" +#include "var.h" +#include "memalloc.h" -extern int yylval; extern char *arith_buf, *arith_startbuf; #undef YY_INPUT #define YY_INPUT(buf,result,max) \ @@ -56,7 +58,36 @@ extern char *arith_buf, *arith_startbuf; %% [ \t\n] { ; } -[0-9]+ { yylval = atol(yytext); return(ARITH_NUM); } + +0x[a-fA-F0-9]+ { + yylval.l_value = strtoarith_t(yytext, NULL, 16); + return(ARITH_NUM); + } + +0[0-7]+ { + yylval.l_value = strtoarith_t(yytext, NULL, 8); + return(ARITH_NUM); + } + +[0-9]+ { + yylval.l_value = strtoarith_t(yytext, NULL, 10); + return(ARITH_NUM); + } + + +[A-Za-z][A-Za-z0-9_]* { + /* + * If variable doesn't exist, we should initialize + * it to zero. + */ + char *temp; + if (lookupvar(yytext) == NULL) + setvarsafe(yytext, "0", 0); + temp = (char *)ckmalloc(strlen(yytext) + 1); + yylval.s_value = strcpy(temp, yytext); + + return(ARITH_VAR); + } "(" { return(ARITH_LPAREN); } ")" { return(ARITH_RPAREN); } "||" { return(ARITH_OR); } @@ -79,6 +110,17 @@ extern char *arith_buf, *arith_startbuf; "-" { return(ARITH_SUB); } "~" { return(ARITH_BNOT); } "!" { return(ARITH_NOT); } +"=" { return(ARITH_ASSIGN); } +"+=" { return(ARITH_ADDASSIGN); } +"-=" { return(ARITH_SUBASSIGN); } +"*=" { return(ARITH_MULASSIGN); } +"/=" { return(ARITH_DIVASSIGN); } +"%=" { return(ARITH_REMASSIGN); } +">>=" { return(ARITH_RSHASSIGN); } +"<<=" { return(ARITH_LSHASSIGN); } +"&=" { return(ARITH_BANDASSIGN); } +"^=" { return(ARITH_BXORASSIGN); } +"|=" { return(ARITH_BORASSIGN); } . { error("arith: syntax error: \"%s\"\n", arith_startbuf); } %% |