Skip to content

Commit 498d6e3

Browse files
committed
Verilog: rules for part select expressions
This introduces the rules for constant_range, indexed_range, and part_select_range, to match IEEE 1800-2017.
1 parent 6806280 commit 498d6e3

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/verilog/parser.y

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,6 @@ part_select:
911911
{ init($$, ID_part_select); mto($$, $2); mto($$, $4); }
912912
;
913913

914-
indexed_part_select:
915-
'[' const_expression TOK_PLUSCOLON const_expression ']'
916-
{ init($$, ID_indexed_part_select_plus); mto($$, $2); mto($$, $4); }
917-
| '[' const_expression TOK_MINUSCOLON const_expression ']'
918-
{ init($$, ID_indexed_part_select_minus); mto($$, $2); mto($$, $4); }
919-
;
920-
921914
// System Verilog standard 1800-2017
922915
// A.2.1.3 Type declarations
923916

@@ -2615,15 +2608,30 @@ inc_or_dec_expression:
26152608
{ init($$, ID_postdecrement); mto($$, $1); }
26162609
;
26172610

2611+
constant_range:
2612+
const_expression TOK_COLON const_expression
2613+
{ init($$, ID_part_select); mto($$, $1); mto($$, $3); }
2614+
;
2615+
2616+
indexed_range:
2617+
expression TOK_PLUSCOLON constant_expression
2618+
{ init($$, ID_indexed_part_select_plus); mto($$, $1); mto($$, $3); }
2619+
| expression TOK_MINUSCOLON constant_expression
2620+
{ init($$, ID_indexed_part_select_minus); mto($$, $1); mto($$, $3); }
2621+
;
2622+
2623+
part_select_range:
2624+
constant_range
2625+
| indexed_range
2626+
;
2627+
26182628
// System Verilog standard 1800-2017
26192629
// A.8.4 Primaries
26202630

26212631
primary: primary_literal
26222632
| indexed_variable_lvalue
2623-
| indexed_variable_lvalue part_select
2624-
{ extractbits($$, $1, $2); }
2625-
| indexed_variable_lvalue indexed_part_select
2626-
{ extractbits($$, $1, $2); }
2633+
| indexed_variable_lvalue '[' part_select_range ']'
2634+
{ extractbits($$, $1, $3); }
26272635
| concatenation
26282636
| replication
26292637
| function_subroutine_call
@@ -2650,10 +2658,8 @@ net_lvalue: variable_lvalue;
26502658

26512659
variable_lvalue:
26522660
indexed_variable_lvalue
2653-
| indexed_variable_lvalue part_select
2654-
{ extractbits($$, $1, $2); }
2655-
| indexed_variable_lvalue indexed_part_select
2656-
{ extractbits($$, $1, $2); }
2661+
| indexed_variable_lvalue '[' part_select_range ']'
2662+
{ extractbits($$, $1, $3); }
26572663
| concatenation
26582664
/* more generous than the rule below to avoid conflict */
26592665
/*

0 commit comments

Comments
 (0)