diff options
author | Larry Doolittle <ldoolitt@recycle.lbl.gov> | 2017-11-28 19:50:44 -0800 |
---|---|---|
committer | Larry Doolittle <ldoolitt@recycle.lbl.gov> | 2017-11-28 19:50:44 -0800 |
commit | f4cab3af39cb36c246ca933abc1574abb704a5f7 (patch) | |
tree | d4ce89812d60f605618648c4d42a735a5118fe26 /src/vhd2vl.l | |
parent | 37e85b47814e2275e80cd2b949338292cb20551b (diff) | |
download | vhdl2vl-f4cab3af39cb36c246ca933abc1574abb704a5f7.tar.gz vhdl2vl-f4cab3af39cb36c246ca933abc1574abb704a5f7.zip |
Accept and ignore underscores in NATURAL
It would be even better to retain them in the output, but that's harder
Diffstat (limited to 'src/vhd2vl.l')
-rw-r--r-- | src/vhd2vl.l | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/vhd2vl.l b/src/vhd2vl.l index 71f87a9..ab3c0d0 100644 --- a/src/vhd2vl.l +++ b/src/vhd2vl.l @@ -36,6 +36,7 @@ extern int skipRem; void getstring(unsigned skip); void getbasedstring(unsigned skip); +int scan_int(char *s); %} %% @@ -157,8 +158,8 @@ void getbasedstring(unsigned skip); return NAME; } -[0-9]+ { - sscanf(yytext, "%d", &yylval.n); +[0-9][0-9_]* { + yylval.n = scan_int(yytext); return NATURAL; } @@ -196,6 +197,17 @@ void getbasedstring(unsigned skip){ strcpy(yylval.txt, yytext+skip); } +int scan_int(char *s){ + char c; + int nn = 0; + while ((c=*s++)) { + if (c>='0' && c<='9') nn = nn*10 + (c-'0'); + /* ignore underscores and any other non-digit; depend on + * the lex pattern to only feed us digits and underscores */ + } + return nn; +} + void yyerror(char *s){ fprintf(stderr,"%s at \"%s\" in line %d.\n\n",s,yytext,lineno); } |