@@ -1440,16 +1440,18 @@ net_declaration:
14401440// Note that the identifier that is defined using the typedef may be
14411441// an existing type or non-type identifier.
14421442type_declaration:
1443- TOK_TYPEDEF data_type new_identifier ' ;'
1444- { // add to the scope as a type name
1445- auto &name = PARSER.scopes .add_name (stack_expr ($3 ).get (ID_identifier), " " );
1446- name.is_type = true ;
1447-
1448- init ($$, ID_decl);
1443+ TOK_TYPEDEF
1444+ { init ($$, ID_decl);
14491445 stack_expr ($$).set (ID_class, ID_typedef);
1450- addswap ($$, ID_type, $2 );
1451- stack_expr ($3 ).id (ID_declarator);
1452- mto ($$, $3 );
1446+ }
1447+ data_type any_identifier ' ;'
1448+ { $$ = $2 ;
1449+ // add to the scope as a type name
1450+ auto &name = PARSER.scopes .add_name (stack_expr ($4 ).get (ID_identifier), " " );
1451+ name.is_type = true ;
1452+ addswap ($$, ID_type, $3 );
1453+ stack_expr ($4 ).id (ID_declarator);
1454+ mto ($$, $4 );
14531455 }
14541456 ;
14551457
@@ -2679,7 +2681,7 @@ expression_or_dist:
26792681// A.2.11 Covergroup declarations
26802682
26812683covergroup_declaration:
2682- TOK_COVERGROUP new_identifier tf_port_list_paren_opt coverage_event_opt ' ;'
2684+ TOK_COVERGROUP any_identifier tf_port_list_paren_opt coverage_event_opt ' ;'
26832685 coverage_spec_or_option_brace TOK_ENDGROUP
26842686 { init ($$, ID_verilog_covergroup); }
26852687 ;
@@ -3194,13 +3196,13 @@ udp_initial_statement:
31943196 TOK_INITIAL output_port_identifier ' =' init_val ' ;'
31953197 ;
31963198
3197- output_port_identifier: new_identifier
3199+ output_port_identifier: any_identifier
31983200 ;
31993201
32003202init_val:
32013203 // Really 1'b0 | 1'b1 | 1'bx | 1'bX | 1'B0 | 1'B1 | 1'Bx | 1'BX | 1 | 0
32023204 TOK_NUMBER
3203- | new_identifier
3205+ | any_identifier
32043206 ;
32053207
32063208sequential_entry_brace:
@@ -3233,7 +3235,7 @@ edge_input_list: level_symbol_brace edge_indicator level_symbol_brace ;
32333235output_symbol:
32343236 // Really 0 | 1 | x | X
32353237 TOK_NUMBER
3236- | new_identifier
3238+ | any_identifier
32373239 ;
32383240
32393241level_symbol_brace:
@@ -3244,13 +3246,13 @@ level_symbol_brace:
32443246level_symbol:
32453247 // Really 0 | 1 | x | X | ? | b | B
32463248 TOK_NUMBER
3247- | new_identifier
3249+ | any_identifier
32483250 ;
32493251
32503252edge_symbol:
32513253 // Really r | R | f | F | p | P | n | N | *
32523254 TOK_NUMBER
3253- | new_identifier
3255+ | any_identifier
32543256 ;
32553257
32563258// System Verilog standard 1800-2017
@@ -4362,9 +4364,10 @@ attr_name: identifier
43624364// System Verilog standard 1800-2017
43634365// A.9.3 Identifiers
43644366
4365- // An extension of the System Verilog grammar to allow defining new types
4366- // using an existing type or non-type identifier.
4367- new_identifier:
4367+ // An extension of the System Verilog grammar to allow defining new identifiers
4368+ // even if they are already used for a different kind of identifier
4369+ // in a higher scope.
4370+ any_identifier:
43684371 type_identifier
43694372 | non_type_identifier
43704373 ;
0 commit comments