added support for inside expressions (closes #28)

This commit is contained in:
Zachary Snow 2019-09-04 21:36:50 -04:00
parent 33bea9e694
commit 1a6e0ce9df
3 changed files with 22 additions and 1 deletions

View File

@ -388,7 +388,7 @@ string { Token Lit_string _ _ }
%left "^" "^~" "~^"
%left "&" "~&"
%left "==" "!=" "===" "!==" "==?" "!=?"
%left "<" "<=" ">" ">="
%left "<" "<=" ">" ">=" "inside" "dist"
%left "<<" ">>" "<<<" ">>>"
%left "+" "-"
%left "*" "/" "%"
@ -999,6 +999,7 @@ Expr :: { Expr }
| "'" "{" PatternItems "}" { Pattern $3 }
| "{" StreamOp StreamSize Concat "}" { Stream $2 $3 $4 }
| "{" StreamOp Concat "}" { Stream $2 (Number "1") $3 }
| Expr "inside" Concat { foldl1 (BinOp LogOr) $ map (BinOp Eq $1) $3 }
-- binary expressions
| Expr "||" Expr { BinOp LogOr $1 $3 }
| Expr "&&" Expr { BinOp LogAnd $1 $3 }

View File

@ -0,0 +1,9 @@
module top;
initial
for (logic [1:0] a = 0; a < 3; a++) begin
if (a inside {2'b01, 2'b00})
$display("fizz");
if (a inside {2'b10})
$display("buzz");
end
endmodule

11
test/basic/inside_expr.v Normal file
View File

@ -0,0 +1,11 @@
module top;
initial begin : foo
reg [1:0] a;
for (a = 0; a < 3; a++) begin
if (a == 2'b01 || a == 2'b00)
$display("fizz");
if (a == 2'b10)
$display("buzz");
end
end
endmodule