From f4cab3af39cb36c246ca933abc1574abb704a5f7 Mon Sep 17 00:00:00 2001 From: Larry Doolittle Date: Tue, 28 Nov 2017 19:50:44 -0800 Subject: Accept and ignore underscores in NATURAL It would be even better to retain them in the output, but that's harder --- src/vhd2vl.l | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/vhd2vl.l') 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); } -- cgit v1.2.1