Skip to content

Commit ce49dcb

Browse files
committed
Verilog: consolidate the two kinds of identifiers in the tokenizer
The code that handles the two kinds of identifiers (quoted or not) is consolidated in the IDENTIFIER macro.
1 parent 8d99c0d commit ce49dcb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/verilog/scanner.l

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ static void preprocessor()
6161

6262
}
6363

64-
#define IDENTIFIER { newstack(yyveriloglval); stack_expr(yyveriloglval).id(yytext); return TOK_NON_TYPE_IDENTIFIER; }
64+
#define IDENTIFIER(text) \
65+
{ newstack(yyveriloglval); \
66+
stack_expr(yyveriloglval).id(text); \
67+
return TOK_NON_TYPE_IDENTIFIER; \
68+
}
6569
#define SYSTEM_VERILOG_KEYWORD(x) \
6670
{ if(PARSER.mode==verilog_parsert::SYSTEM_VERILOG) \
6771
return x; \
6872
else \
69-
IDENTIFIER; \
73+
IDENTIFIER(yytext); \
7074
}
7175
#define SYSTEM_VERILOG_OPERATOR(token, text) \
7276
{ if(PARSER.mode==verilog_parsert::SYSTEM_VERILOG) \
@@ -79,7 +83,7 @@ static void preprocessor()
7983
PARSER.mode==verilog_parsert::VIS_VERILOG) \
8084
return x; \
8185
else \
82-
IDENTIFIER; \
86+
IDENTIFIER(yytext); \
8387
}
8488
%}
8589

@@ -496,8 +500,8 @@ within { SYSTEM_VERILOG_KEYWORD(TOK_WITHIN); }
496500
{Time} { newstack(yyveriloglval); stack_expr(yyveriloglval).id(yytext); return TOK_TIME_LITERAL; }
497501
{Real} { newstack(yyveriloglval); stack_expr(yyveriloglval).id(yytext); return TOK_NUMBER; }
498502
{RealExp} { newstack(yyveriloglval); stack_expr(yyveriloglval).id(yytext); return TOK_NUMBER; }
499-
{Word} { IDENTIFIER; }
500-
{EscapedWord} { newstack(yyveriloglval); stack_expr(yyveriloglval).id(yytext+1); return TOK_NON_TYPE_IDENTIFIER; }
503+
{Word} { IDENTIFIER(yytext); }
504+
{EscapedWord} { IDENTIFIER(yytext+1); /* The backslash is not part of the name */ }
501505
. { return yytext[0]; }
502506
} // GRAMMAR
503507

0 commit comments

Comments
 (0)